diff --git a/desktop/main.go b/desktop/main.go index 3f56748..a17bcf6 100644 --- a/desktop/main.go +++ b/desktop/main.go @@ -27,10 +27,33 @@ func main() { app := NewApp() tray := newTray(app) + // One process per PC, enforced by the OS rather than by hoping. + // + // The window hides to the tray on close, so the ordinary next thing a shop + // assistant does is double-click the desktop shortcut again to get it + // back. Without this lock that started a SECOND complete copy: a second + // tray icon, a second engine supervisor on the same SQLite WAL and the + // same port - the "start twice" failure the agent package exists to + // prevent, on the one binary that never had the guard. Seen on a Windows + // install as a row of Behavision icons in the tray. A second launch now + // only brings the existing window to the front, which is what the person + // wanted in the first place. + var ctxRef context.Context + single := &options.SingleInstanceLock{ + UniqueId: "ai.loyaly.behavision.desktop", + OnSecondInstanceLaunch: func(options.SecondInstanceData) { + if ctxRef != nil { + runtime.Show(ctxRef) + runtime.WindowUnminimise(ctxRef) + } + }, + } + err := wails.Run(&options.App{ - Title: "Behavision", - Width: 1280, - Height: 820, + SingleInstanceLock: single, + Title: "Behavision", + Width: 1280, + Height: 820, // Small enough to still be usable on a cramped shop-counter monitor. MinWidth: 1024, MinHeight: 640, @@ -40,6 +63,7 @@ func main() { // is where they get the window back. HideWindowOnClose: true, OnStartup: func(ctx context.Context) { + ctxRef = ctx app.startup(ctx) tray.start(ctx) },