diff --git a/cmd/tray/main.go b/cmd/tray/main.go
index a4ab008..9cba69c 100644
--- a/cmd/tray/main.go
+++ b/cmd/tray/main.go
@@ -69,6 +69,11 @@ func onReady() {
}()
go func() {
for range quitItem.ClickedCh {
+ if err := quitTray(); err != nil {
+ statusItem.SetTitle("托盘状态:退出失败")
+ systray.SetTooltip(fmt.Sprintf("闲鱼管家:托盘退出失败:%v", err))
+ continue
+ }
systray.Quit()
}
}()
diff --git a/cmd/tray/service_control_darwin.go b/cmd/tray/service_control_darwin.go
index e633f72..6abb89c 100644
--- a/cmd/tray/service_control_darwin.go
+++ b/cmd/tray/service_control_darwin.go
@@ -44,6 +44,15 @@ func serviceAction(action string) error {
}
}
+func quitTray() error {
+ label := envOr("XIANYU_TRAY_SERVICE_NAME", "com.ydisks.xianyu-helper.tray")
+ target := "gui/" + fmt.Sprint(os.Getuid()) + "/" + label
+ if err := launchctl("print", target); err != nil {
+ return nil
+ }
+ return launchctl("bootout", target)
+}
+
func launchctl(args ...string) error {
cmd := exec.Command("launchctl", args...)
output, err := cmd.CombinedOutput()
diff --git a/cmd/tray/service_control_other.go b/cmd/tray/service_control_other.go
index f45419f..9ae6c5f 100644
--- a/cmd/tray/service_control_other.go
+++ b/cmd/tray/service_control_other.go
@@ -7,3 +7,5 @@ import "fmt"
func serviceAction(action string) error {
return fmt.Errorf("当前平台不支持托盘服务操作: %s", action)
}
+
+func quitTray() error { return nil }
diff --git a/cmd/tray/service_control_windows.go b/cmd/tray/service_control_windows.go
index 3625251..db6f272 100644
--- a/cmd/tray/service_control_windows.go
+++ b/cmd/tray/service_control_windows.go
@@ -44,3 +44,5 @@ exit $exitCode`, quotedName, action)
}
return nil
}
+
+func quitTray() error { return nil }
diff --git a/packaging/macos/com.ydisks.xianyu-helper.tray.plist.template b/packaging/macos/com.ydisks.xianyu-helper.tray.plist.template
index e7000f7..69c0e38 100644
--- a/packaging/macos/com.ydisks.xianyu-helper.tray.plist.template
+++ b/packaging/macos/com.ydisks.xianyu-helper.tray.plist.template
@@ -5,6 +5,7 @@
Labelcom.ydisks.xianyu-helper.tray
ProgramArguments__TRAY__
RunAtLoad
- KeepAlive
+
+ KeepAlive