fix: 修复托盘进程无法退出

将 macOS 托盘 LaunchAgent 的 KeepAlive 设置为 false,避免用户退出后被 launchd 立即拉起。

托盘退出菜单主动卸载当前 LaunchAgent,再结束托盘进程。

保留旧版本通过 launchctl bootout 清理服务的升级恢复路径。
This commit is contained in:
Christ committed 2026-08-11 22:40:46 +08:00
1 parent 07e91afc22
commit 3d715e916b
5 files changed
+20 -1

No files matched your search

+5
View File
@@ -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()
}
}()
+9
View File
@@ -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()
+2
View File
@@ -7,3 +7,5 @@ import "fmt"
func serviceAction(action string) error {
return fmt.Errorf("当前平台不支持托盘服务操作: %s", action)
}
func quitTray() error { return nil }
+2
View File
@@ -44,3 +44,5 @@ exit $exitCode`, quotedName, action)
}
return nil
}
func quitTray() error { return nil }
@@ -5,6 +5,7 @@
<key>Label</key><string>com.ydisks.xianyu-helper.tray</string>
<key>ProgramArguments</key><array><string>__TRAY__</string></array>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
<!-- 托盘允许用户退出;服务端 LaunchAgent 单独负责 KeepAlive。 -->
<key>KeepAlive</key><false/>
</dict>
</plist>