Skip to content

Commit

Permalink
fix: prevent user starting wails app twice
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Sep 25, 2024
1 parent ff417c4 commit 22d721d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions main_wails.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"context"
"embed"
"net"

"github.com/getAlby/hub/logger"
"github.com/getAlby/hub/service"
Expand All @@ -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)
Expand Down

0 comments on commit 22d721d

Please sign in to comment.