feat(updater): macOS 原地升级 —— 去掉 Finder 替换确认弹窗 - #17
Merged
Conversation
Previously macOS updates ended by opening the downloaded dmg, leaving the user to drag the .app into /Applications and confirm Finder's replace prompt. Now, when running from a real .app bundle, the updater mounts the dmg read-only and spawns a trampoline shell script before exiting. The trampoline waits for the process to die, stages the new bundle next to the target with ditto, swaps with atomic mv (rolling back if the second move fails), detaches, and relaunches — zero prompts. Any failure (dev binary outside a bundle, hdiutil errors, unwritable install dir) falls back to the old open-the-dmg flow. Pure helpers (bundle-path detection, hdiutil mount-point parsing, shell quoting, script rendering) are unit-tested cross-platform; the hdiutil/ditto execution is cfg(macos)-gated. Swap mechanics validated end-to-end against the signed V1.4.1 dmg in a sandboxed target, and the full GUI flow verified on hardware: check -> download -> install -> automatic relaunch into the official signed build.
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_82e7e030-a8ae-4480-87b4-036e33892115) |
Merged
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.
背景
V1.4.1 实测反馈:应用内更新在 macOS 上最后一步是打开 dmg 让用户手动拖拽,Finder 会弹「保留两者 / 停止 / 替换」确认框。 Finder 不认版本号,任何拖拽覆盖都会问——正版升级的「无弹窗」体验来自原地替换机制。
方案
下载完成后不再
open dmg,而是:hdiutil attach -nobrowse -readonly),解析挂载点,定位其中的 .appditto暂存新包到目标同级目录(同卷)→mv旧包到旁边 →mv新包到位(同卷原子替换,第二步失败会回滚)→ 卸载 dmg、删除临时文件 → 重新打开应用任意环节失败都回退到旧行为(打开 dmg 走手动流程):开发态裸二进制(不在 .app 里)、挂载失败、目录不可写等。
实现说明
hdiutil/ditto执行路径用cfg(macos)门控,不影响 Linux CI。验证
Note
Medium Risk
Changes how macOS replaces the installed
.app(filesystem moves, generated shell,hdiutil/ditto); rollback and DMG fallback limit breakage but a failed swap could still disrupt the install location until the user intervenes.Overview
macOS in-app updates no longer end by opening the DMG for manual drag-and-drop. When the app runs from a real
.appbundle,launch_installer_and_exitmounts the downloaded DMG read-only, writes a short-lived trampoline shell script, spawns it detached, and exits. The script waits for the updater process (up to ~30s), stages the new bundle withditto, performs an atomic same-volume swap (mvold aside →mvnew in, with rollback on failure), detaches the volume, deletes the DMG, and relaunches the updated app.Linux/Windows behavior is unchanged via a non-macOS
launch_inner(stillxdg-open/ direct spawn). Failure paths (dev binary outside a bundle, mount/parse errors, spawn failure) log a warning and fall back toopenon the DMG.The swap logic is split into testable pure helpers (
bundle_path_from_exe,hdiutilmount parsing, POSIXshell_quote,render_trampoline_script) plus six new unit tests;hdiutil/dittointegration stays behind#[cfg(target_os = "macos")].Reviewed by Cursor Bugbot for commit 966ca48. Bugbot is set up for automated code reviews on this repo. Configure here.