From 22d721d1e4e1208a0cd40979f24e2ffab70a9abf Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Wed, 25 Sep 2024 13:20:35 +0700 Subject: [PATCH] fix: prevent user starting wails app twice --- main_wails.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main_wails.go b/main_wails.go index 27764a5d..806ad7cf 100644 --- a/main_wails.go +++ b/main_wails.go @@ -6,6 +6,7 @@ package main import ( "context" "embed" + "net" "github.com/getAlby/hub/logger" "github.com/getAlby/hub/service" @@ -20,6 +21,14 @@ var assets embed.FS var appIcon []byte func main() { + // Get a port lock on a rare port to prevent the app running twice + listener, err := net.Listen("tcp", "0.0.0.0:21420") + if err != nil { + log.Println("Another instance of Alby Hub is already running.") + return + } + defer listener.Close() + log.Info("Alby Hub starting in WAILS mode") ctx, cancel := context.WithCancel(context.Background()) svc, _ := service.NewService(ctx)