Skip to content

Commit

Permalink
Fix exit from systray (#4337)
Browse files Browse the repository at this point in the history
  • Loading branch information
DingDongSoLong4 authored Dec 2, 2023
1 parent d4ef182 commit ccb1b7c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion internal/desktop/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion internal/desktop/systray_nixes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 13 additions & 8 deletions internal/desktop/systray_nonlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -85,8 +90,8 @@ func systrayInitialize(exit chan<- int, faviconProvider FaviconProvider) {
case <-openStashButton.ClickedCh:
openURLInBrowser("")
case <-quitStashButton.ClickedCh:
systray.Quit()
exit <- 0
return
}
}
}()
Expand Down

0 comments on commit ccb1b7c

Please sign in to comment.