Skip to content

Commit

Permalink
fix: prevent user starting wails app twice (#709)
Browse files Browse the repository at this point in the history
Fixes #467

The simplest change to prevent Alby Hub running twice in Wails mode
which could potentially cause corruption of the LDK directory. This is
equivalent to how the http mode prevents it, but even better because the
port is allocated even before the service starts.
  • Loading branch information
im-adithya authored Oct 9, 2024
2 parents b05c187 + 22d721d commit 0ec74af
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 0ec74af

Please sign in to comment.