Repository navigation
fix(macos): keep pinned Dock icon after update restart - #9910
Merged
allenxu09 merged 1 commit intoNov 24, 2026
Merged
Conversation
allenxu09
force-pushed
the
fix/macos-update-dock-duplicate
branch
from
November 23, 2026 13:26
66474be to
136734a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human Note / 本人说明
在 macOS 上每次在线升级 CC Switch 之后,Dock 栏都会新弹出来一个图标,而不是直接复用原来固定在 Dock 里的图标,每次都得手动删掉旧的再把新的拖回 Dock。改一下 macOS 重启逻辑,等旧进程退出后再拉起新实例。
Summary / 概述
此前
relaunch_macos_bundle在当前进程仍存活时同步执行/usr/bin/open -n <bundle>,成功后再调用std::process::exit(0)。在应用内更新原地替换.appbundle(或配置目录变更重启)时,新实例启动瞬间旧进程仍占着 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 路径。.appbundle 路径解析,以及确认 helper 会等旧 PID 退出后才调用open -n并保留带空格的参数(空PATH环境)。Related Issue / 关联 Issue
Fixes #8329
Checklist / 检查清单
cargo fmt --check --manifest-path src-tauri/Cargo.tomlpassescargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warningspassescargo test --manifest-path src-tauri/Cargo.toml --lib macos_passes (8/8, including 2 new macOS relaunch tests)tests/lib/registeredCommands.test.ts,tests/config/ompProviderPresets.test.ts,tests/components/usageProviderLabel.test.ts) pass (9/9)