fix(tray): 托盘恢复主窗口按系统版本选择激活选择器,修复 macOS 13 及更早系统崩溃 - #238
Merged
Merged
Conversation
`NSApplication::activate()` 是 macOS 14 才引入的选择器(Apple《AppKit Release Notes for macOS 14》:`activate(ignoringOtherApps:)` 在 14 废弃,同时新增 `activate`),而 `Info.plist` 声明的最低支持版本是 macOS 12.0。旧系统上该选择器不存在,消息转发失败 (`doesNotRecognizeSelector:`)→ `std::terminate` → SIGABRT。 - 崩溃报告:x86_64 / macOS 12.7.6(MacBookPro11,4)/ navop 0.18.3;未捕获 ObjC 异常 `EXC_CRASH (SIGABRT)`,帧序 `__exceptionPreprocess` → `objc_exception_throw` → `___forwarding___` → `_CF_forwarding_prep_0` - 必现路径:SSH 终端窗口最小化到托盘后恢复主窗口 - 修复:`activate_app` 用 `respondsToSelector(sel!(activate))` 运行时按系统版本分派, 命中走 `activate()`,否则回退 `activateIgnoringOtherApps:`;回退收进 `activate_legacy` 并 `#[allow(deprecated)]`,两条路径各自都在原生支持的系统上 - 新增源码级守卫测试:禁止调用方绕过 helper 直接调新选择器,也禁止删掉旧系统回退 - 影响面仅 `main/src/window_visibility.rs`;gpui 的 `activate_window()` 只做 `makeKeyAndOrderFront:`,无同类越线
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.
Description
Fixes a reproducible crash when restoring the main window from the system tray on macOS 13 and earlier.
Root cause.
main/src/window_visibility.rscalledNSApplication.activate()unconditionally. Per Apple's AppKit Release Notes for macOS 14,activate(ignoringOtherApps:)is deprecated in macOS 14 and a newactivatemethod was added in that release.Info.plistdeclaresLSMinimumSystemVersion = 12.0, so on macOS 12/13 the selector does not exist and the message goes throughdoesNotRecognizeSelector:→std::terminate→SIGABRT.User report. X86-64 / macOS 12.7.6 (MacBookPro11,4) / navop 0.18.3, uncaught Objective-C exception
EXC_CRASH (SIGABRT)with frames__exceptionPreprocess→objc_exception_throw→___forwarding___→_CF_forwarding_prep_0. Reproducible: open an SSH terminal window → minimize to tray → restore. The regression was introduced with the tray feature in 0.18.3, and this call site is the only place in the repository using that selector.Fix. Dispatch on runtime selector availability instead of hard-coding the new API:
The legacy path calls
activateIgnoringOtherApps:and is isolated in its own#[allow(deprecated)]function so the deprecated API is confined to one call site. Both branches run on systems that natively support them.No UI change, so no screenshots are attached.
How to Test
cargo check -p main— passes.cargo test -p main --bin navop window_activation—1 passed; 0 failed. The new source-level guard test asserts that availability is checked, that the legacy fallback still exists, that the new selector is only reached after the check, and that callers do not bypass the helper.Checklist
cargo runfor story tests related to the changes.