Skip to content

fix(macos): keep pinned Dock icon after update restart - #9910

Merged
allenxu09 merged 1 commit into
farion1231:mainfrom
allenxu09:fix/macos-update-dock-duplicate
Nov 24, 2026
Merged

allenxu09 merged 1 commit into
farion1231:mainfrom
allenxu09:fix/macos-update-dock-duplicate

Conversation

@allenxu09

@allenxu09 allenxu09 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Human Note / 本人说明

在 macOS 上每次在线升级 CC Switch 之后,Dock 栏都会新弹出来一个图标,而不是直接复用原来固定在 Dock 里的图标,每次都得手动删掉旧的再把新的拖回 Dock。改一下 macOS 重启逻辑,等旧进程退出后再拉起新实例。

Summary / 概述

此前 relaunch_macos_bundle 在当前进程仍存活时同步执行 /usr/bin/open -n <bundle>,成功后再调用 std::process::exit(0)。在应用内更新原地替换 .app bundle(或配置目录变更重启)时,新实例启动瞬间旧进程仍占着 Dock 固定图标,macOS Dock 会给新实例分配第二个临时图标;随后旧进程退出,固定图标熄灭而运行中的新实例留在右侧。

本次修改 src-tauri/src/lib.rs 中的 macOS 重启路径(覆盖应用内更新 install_update_and_restart 与配置目录重启 restart_app):

  • 新增 MACOS_WAIT_THEN_RELAUNCH_SCRIPT 与 build_macos_relaunch_command:拉起脱离当前进程组(process_group(0))且 stdin/stdout/stderr 重定向到 /dev/null 的 /bin/sh 辅助进程,轮询 kill -0 等待旧 PID 退出(最多 10 秒)并额外留出 100ms 给 Dock / LaunchServices 完成注销,再执行 /usr/bin/open -n <bundle>(仅在有参数时追加 --args "$@";若 open 返回失败则回落 exec 直接启动 bundle 二进制)。
  • relaunch_macos_bundle 在 helper 成功拉起后立即 std::process::exit(0),仅在 helper 本身拉起失败时回落到 tauri::process::restart,同时保留经 LaunchServices 启动以获得 macOS 14+ 前台激活的能力。
  • 新增 macos_app_bundle_from_binary:同时校验 <Name>.app/Contents/MacOS/<binary> 目录层级与 .app 扩展名,避免误匹配非 bundle 路径。
  • 补充 2 个精简的 macOS 单元测试:校验 .app bundle 路径解析,以及确认 helper 会等旧 PID 退出后才调用 open -n 并保留带空格的参数(空 PATH 环境)。

注:该修复从包含此改动的版本开始生效——从旧版本升到包含本修复的版本那一次仍会走旧进程的重启代码,之后每次升级和重启都会复用固定的 Dock 图标。

Related Issue / 关联 Issue

Fixes #8329

Checklist / 检查清单

  • cargo fmt --check --manifest-path src-tauri/Cargo.toml passes
  • cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings passes
  • cargo test --manifest-path src-tauri/Cargo.toml --lib macos_ passes (8/8, including 2 new macOS relaunch tests)
  • Frontend contract tests (tests/lib/registeredCommands.test.ts, tests/config/ompProviderPresets.test.ts, tests/components/usageProviderLabel.test.ts) pass (9/9)
  • Updated i18n files if user-facing text changed / 如修改了用户可见文本,已更新国际化文件(不涉及用户可见文案)

@github-actions github-actions Bot added the backend Backend (Rust/Tauri) label Nov 23, 2026
@allenxu09
allenxu09 force-pushed the fix/macos-update-dock-duplicate branch from 66474be to 136734a Compare November 23, 2026 13:26

@YUZHEthefool YUZHEthefool left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it 🚢

@SaladDay SaladDay left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@allenxu09
allenxu09 merged commit 0c3b5fd into farion1231:main Nov 24, 2026
10 checks passed
@allenxu09 allenxu09 mentioned this pull request Nov 24, 2026
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend (Rust/Tauri)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

在线升级后dok栏显示双份图标

3 participants