From 9521cb986ba490d342f24636382e64823fb9797a Mon Sep 17 00:00:00 2001 From: Suriyakumarvijayanayagam Date: Wed, 9 Sep 2026 13:06:51 +0530 Subject: [PATCH] The shop PC's UI had never once been run `wails build` had never been executed against this project - CLAUDE.md says so plainly - so every screen the shop floor actually touches was unreviewed. Running it found why nobody had. fyne.io/systray's nativeLoop must own the main thread on macOS, a Cocoa requirement, and Wails already holds it. Starting both kills the process with a SIGTRAP inside cgo before a single pixel is drawn. On Windows, which is what ships, a tray on its own goroutine is fine - so the one platform the whole team develops on was the one platform that could not open the app, and the UI went unlooked-at as a result. BEHAVISION_NO_TRAY runs the window without the tray, the same escape hatch BEHAVISION_ALLOW_PLAINTEXT_MQTT already is for the broker. Deliberately an environment variable and NOT a GOOS check: a build that quietly drops the tray is how a shop PC ends up with no control surface at all, and it would fail where nobody is watching. The guard is on stop() as well, because systray.Quit() on a systray that never started is not a no-op in v1.12.2 - it would turn closing the window into a crash on exit, the failure most likely to be shrugged off as "it closed, fine". go.mod gains the indirect dependencies the darwin build pulls in. No version moved: the committed list was written by a windows-only build, which never resolves that part of the Wails tree. Verified: GOOS=windows build, go vet, and the agent suite all still pass, and the packaged .app runs. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01Qiy5iKfz4L8S4vRaYPBdaU --- .gitignore | 7 +++++++ desktop/go.mod | 18 ++++++++++++++++++ desktop/go.sum | 8 ++++++++ desktop/tray.go | 30 ++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/.gitignore b/.gitignore index bdf9213..5b3b3f4 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,10 @@ node_modules/ # Backups of .env made when editing camera credentials. /.env.bak-* + +# Generated by the wails CLI on every dev run and build, not source. +# NOT /desktop/build/ as a whole: appicon.png, darwin/ and windows/ under it +# are the Wails project scaffolding (icon, Info.plist, manifest) that a +# reproducible Windows build needs. Only the compiled output is ignored. +/desktop/frontend/wailsjs/ +/desktop/frontend/package.json.md5 diff --git a/desktop/go.mod b/desktop/go.mod index 66a2a82..81d92fc 100644 --- a/desktop/go.mod +++ b/desktop/go.mod @@ -14,16 +14,34 @@ require ( ) require ( + github.com/bep/debounce v1.2.1 // indirect github.com/eclipse/paho.mqtt.golang v1.4.3 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect + github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect + github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect + github.com/labstack/echo/v4 v4.10.2 // indirect + github.com/labstack/gommon v0.4.0 // indirect github.com/leaanthony/go-ansi-parser v1.6.0 // indirect + github.com/leaanthony/gosod v1.0.3 // indirect github.com/leaanthony/slicer v1.6.0 // indirect github.com/leaanthony/u v1.1.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.4.4 // indirect + github.com/samber/lo v1.38.1 // indirect + github.com/tkrajina/go-reflector v0.5.6 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasttemplate v1.2.2 // indirect github.com/wailsapp/go-webview2 v1.0.16 // indirect + github.com/wailsapp/mimetype v1.4.1 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect golang.org/x/net v0.25.0 // indirect golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect ) diff --git a/desktop/go.sum b/desktop/go.sum index 4f69a81..b3e0742 100644 --- a/desktop/go.sum +++ b/desktop/go.sum @@ -3,6 +3,7 @@ fyne.io/systray v1.12.2/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs= github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY= github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik= github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE= @@ -20,6 +21,7 @@ github.com/labstack/echo/v4 v4.10.2 h1:n1jAhnq/elIFTHr1EYpiYtyKgx4RW9ccVgkqByZaN github.com/labstack/echo/v4 v4.10.2/go.mod h1:OEyqf2//K1DFdE57vw2DRgWY0M7s65IVQO2FzvI4J5k= github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8= github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM= +github.com/leaanthony/debme v1.2.1 h1:9Tgwf+kjcrbMQ4WnPcEIUcQuIZYqdWftzZkBr+i/oOc= github.com/leaanthony/debme v1.2.1/go.mod h1:3V+sCm5tYAgQymvSOfYQ5Xx2JCr+OXiD9Jkw3otUjiA= github.com/leaanthony/go-ansi-parser v1.6.0 h1:T8TuMhFB6TUMIUm0oRrSbgJudTFw9csT3ZK09w0t4Pg= github.com/leaanthony/go-ansi-parser v1.6.0/go.mod h1:+vva/2y4alzVmmIEpk9QDhA7vLC5zKDTRwfZGOp3IWU= @@ -30,6 +32,7 @@ github.com/leaanthony/slicer v1.6.0 h1:1RFP5uiPJvT93TAHi+ipd3NACobkW53yUiBqZheE/ github.com/leaanthony/slicer v1.6.0/go.mod h1:o/Iz29g7LN0GqH3aMjWAe90381nyZlDNquK+mtH2Fj8= github.com/leaanthony/u v1.1.0 h1:2n0d2BwPVXSUq5yhe8lJPHdxevE2qK5G99PMStMZMaI= github.com/leaanthony/u v1.1.0/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI= +github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU= github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -42,6 +45,7 @@ github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= @@ -50,6 +54,8 @@ github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM= github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tkrajina/go-reflector v0.5.6 h1:hKQ0gyocG7vgMD2M3dRlYN6WBBOmdoOzJ6njQSepKdE= github.com/tkrajina/go-reflector v0.5.6/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= @@ -92,3 +98,5 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/desktop/tray.go b/desktop/tray.go index 083e7da..8a8da06 100644 --- a/desktop/tray.go +++ b/desktop/tray.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "os" "sync" "time" @@ -10,6 +11,25 @@ import ( "github.com/wailsapp/wails/v2/pkg/runtime" ) +// BEHAVISION_NO_TRAY runs the window with no tray icon. +// +// It exists so the UI can be looked at on a Mac. fyne.io/systray's nativeLoop +// must own the main thread on macOS - a Cocoa requirement, not a library +// choice - and Wails already holds it, so starting both kills the process with +// a SIGTRAP inside cgo before a single screen is drawn. On Windows, which is +// what ships, a tray on its own goroutine is fine. That asymmetry is why this +// went unnoticed for so long: the shop-floor UI had never once been run on the +// platform it is developed on, so every screen in it was unreviewed. +// +// Deliberately an environment variable and NOT a GOOS check. A build that +// quietly drops the tray on some platform is how a shop PC ends up with no +// control surface at all - the one thing a shop manager has - and it would +// fail exactly where nobody is watching. Nothing is skipped unless a person +// asked for it, by name, on this run. +const noTrayEnv = "BEHAVISION_NO_TRAY" + +func trayDisabled() bool { return os.Getenv(noTrayEnv) != "" } + // tray is the always-present control surface. Wails v2 has no systray of its // own, so this drives fyne.io/systray alongside the window. // @@ -32,6 +52,9 @@ type tray struct { func newTray(a *App) *tray { return &tray{app: a, quit: make(chan struct{})} } func (t *tray) start(ctx context.Context) { + if trayDisabled() { + return + } t.once.Do(func() { go systray.Run(func() { t.onReady(ctx) }, func() {}) }) @@ -43,6 +66,13 @@ func (t *tray) stop() { default: close(t.quit) } + // systray.Quit() on a systray that was never started is not a no-op in + // v1.12.2, so the guard has to be on both ends or quitting the window + // takes the process down with it - a crash on exit, which is the failure + // most likely to be shrugged off as "it closed, fine". + if trayDisabled() { + return + } systray.Quit() }