The shop app starts once, and a second launch just shows the window
The window hides to the tray on close, so the natural next step for a shop assistant is to double-click the shortcut again. That started a second full copy of the app: a second tray icon, a second engine supervisor on the same SQLite WAL and the same port - the start-twice failure the agent package was built to prevent, on the one binary that never had the guard. Seen on a Windows install as a row of tray icons. Wails' SingleInstanceLock now hands the second launch to the first process, which brings its window to the front. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KGcjxF1cNLcuwc3DAPcnfj
This commit is contained in:
@@ -27,10 +27,33 @@ func main() {
|
|||||||
app := NewApp()
|
app := NewApp()
|
||||||
tray := newTray(app)
|
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{
|
err := wails.Run(&options.App{
|
||||||
Title: "Behavision",
|
SingleInstanceLock: single,
|
||||||
Width: 1280,
|
Title: "Behavision",
|
||||||
Height: 820,
|
Width: 1280,
|
||||||
|
Height: 820,
|
||||||
// Small enough to still be usable on a cramped shop-counter monitor.
|
// Small enough to still be usable on a cramped shop-counter monitor.
|
||||||
MinWidth: 1024,
|
MinWidth: 1024,
|
||||||
MinHeight: 640,
|
MinHeight: 640,
|
||||||
@@ -40,6 +63,7 @@ func main() {
|
|||||||
// is where they get the window back.
|
// is where they get the window back.
|
||||||
HideWindowOnClose: true,
|
HideWindowOnClose: true,
|
||||||
OnStartup: func(ctx context.Context) {
|
OnStartup: func(ctx context.Context) {
|
||||||
|
ctxRef = ctx
|
||||||
app.startup(ctx)
|
app.startup(ctx)
|
||||||
tray.start(ctx)
|
tray.start(ctx)
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user