diff --git a/internal/desktop/desktop.go b/internal/desktop/desktop.go index 52823b4030c..b5a261bf7a9 100644 --- a/internal/desktop/desktop.go +++ b/internal/desktop/desktop.go @@ -23,7 +23,7 @@ type FaviconProvider interface { // Start starts the desktop icon process. It blocks until the process exits. // MUST be run on the main goroutine or will have no effect on macOS -func Start(exit chan<- int, faviconProvider FaviconProvider) { +func Start(exit chan int, faviconProvider FaviconProvider) { if IsDesktop() { hideConsole() diff --git a/internal/desktop/systray_nixes.go b/internal/desktop/systray_nixes.go index c6fbec89022..8ef65270233 100644 --- a/internal/desktop/systray_nixes.go +++ b/internal/desktop/systray_nixes.go @@ -2,7 +2,7 @@ package desktop -func startSystray(exit chan<- int, favicon FaviconProvider) { +func startSystray(exit chan int, favicon FaviconProvider) { // The systray is not available on Linux because the required libraries (libappindicator3 and gtk+3.0) // are not able to be statically compiled. Technically, the systray works perfectly fine when dynamically // linked, but we cannot distribute it for compatibility reasons. diff --git a/internal/desktop/systray_nonlinux.go b/internal/desktop/systray_nonlinux.go index 4ce6aea51ec..b1eb011a352 100644 --- a/internal/desktop/systray_nonlinux.go +++ b/internal/desktop/systray_nonlinux.go @@ -14,7 +14,7 @@ import ( ) // MUST be run on the main goroutine or will have no effect on macOS -func startSystray(exit chan<- int, faviconProvider FaviconProvider) { +func startSystray(exit chan int, faviconProvider FaviconProvider) { // Shows a small notification to inform that Stash will no longer show a terminal window, // and instead will be available in the tray. Will only show the first time a pre-desktop integration // system is started from a non-terminal method, e.g. double-clicking an icon. @@ -23,7 +23,7 @@ func startSystray(exit chan<- int, faviconProvider FaviconProvider) { SendNotification("Stash has moved!", "Stash now runs in your tray, instead of a terminal window.") c.Set(config.ShowOneTimeMovedNotification, false) if err := c.Write(); err != nil { - logger.Errorf("Error while writing configuration file: %s", err.Error()) + logger.Errorf("Error while writing configuration file: %v", err) } } @@ -37,11 +37,16 @@ func startSystray(exit chan<- int, faviconProvider FaviconProvider) { // } // }() - for { - systray.Run(func() { - systrayInitialize(exit, faviconProvider) - }, nil) - } + // "intercept" an exit code to quit the systray, allowing the call to systray.Run() below to return. + go func() { + exitCode := <-exit + systray.Quit() + exit <- exitCode + }() + + systray.Run(func() { + systrayInitialize(exit, faviconProvider) + }, nil) } func systrayInitialize(exit chan<- int, faviconProvider FaviconProvider) { @@ -85,8 +90,8 @@ func systrayInitialize(exit chan<- int, faviconProvider FaviconProvider) { case <-openStashButton.ClickedCh: openURLInBrowser("") case <-quitStashButton.ClickedCh: - systray.Quit() exit <- 0 + return } } }()