Skip to content

fix(desktop): retain the Rust preview client after window close - #6695

Merged
me2seeks merged 17 commits into
rust-previewfrom
fix/6668-desktop-tray
Nov 9, 2026
Merged

me2seeks merged 17 commits into
rust-previewfrom
fix/6668-desktop-tray

Conversation

@me2seeks

@me2seeks me2seeks commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #6668.

Keep Desktop and its real, already-admitted Host client alive after an ordinary window close, without retaining the UI engine. This branch now integrates upstream rust-preview through 1cba85e51 (including the merged #6705 native compilation, clipboard and focus fixes): AppKit on macOS, Direct2D on Windows, GTK4 on Linux. It does not restore upstream's removed GPUI backends.

  • Close captures active plugin presentation state, then destroys the window, rendering resources, engine and window-scoped subscriptions. Open creates a fresh UI on the retained connection; an existing window is only focused.
  • The tray/menu-bar entry belongs to Desktop, not Host. Only explicit Quit performs bounded client detach and exits. No synthetic keepalive client, shared Host termination or Host lifecycle policy change.
  • Without a usable tray, close exits. Linux watcher loss while hidden restores an operable window; Windows Explorer restart re-registers the tray.
  • Host following remains application-owned while hidden. A successor updates the retained recipe without opening a closed window. Native permission utilities close with their main UI or original Host connection.
  • Preserve the upstream shared native Window close callbacks, terminal thread ownership, IME and permission architecture.

Verification

Latest head: a48c7c4, integrating upstream 1cba85e and merged #6705.

  • Hosted CI 42555575165 completed: 33/35 jobs succeeded, with no skipped, cancelled or remaining jobs. Dependency audit and license checks also passed.
  • All 22 root partitions, root build, Linux native, Linux NSH, packaging, product, bridge, NSH, tooling and Windows native passed. The real Win32 resident close/reopen/hidden-Quit regression passed on the hosted runner.
  • macOS compilation and all 107 macOS NSH unit tests passed. The first seven native surface cases passed, including the previously failing hidden/clipped subtree test.
  • The remaining macOS failure is inherited from fix(nsh): restore rust-preview CI, isolate macOS clipboard, and scope editor focus #6705: rich_editor_composition_commit_matches_preedit_and_keeps_shortcuts fails at cases.rs:1335 when the composition commit returns false. The final upstream job and this PR's job fail the same assertion. Unified test correctly fails because that required suite failed. Overall CI is not green; later macOS suites were blocked by fail-fast and are not presented as passed.
  • Latest-head local verification: workbench 158/158, Windows product lifecycle/protocol 4/4, actual Win32 resident lifecycle 1/1, all passed. CI-script tests: 39 passed, one blocked by missing local Python; hosted tooling passed.
  • Earlier actual UI declaration generation plus TypeScript checking passed. The dedicated Linux display-backed suite previously verified 8/8 tests, 0 skipped, including three GTK engine/surface release/reopen cycles and both D-Bus watcher recovery cases.

The child-approval fixture now configures effective chat defaults consistently and checks the parent's read-only policy before delegation. No approval rule, timeout or selector was loosened. Superseded compile variants from closed #6709 were removed in favor of #6705; its diagnostic-only follow-up was not carried here.

Earlier Windows and GNOME/XWayland lifecycle runs at bc93674ab verified repeated painted close/Open cycles, the retained Host, watcher recovery, hidden Quit and no-tray exit. GPUI-specific code/tests were retired with upstream. The attached screenshot remains historical pre-integration evidence, not a current GTK4 image.

Public API

Application-owned native runners are opt-in; ordinary runners keep their existing lifecycle:

  • Windows TrayOptions { title, open_label, quit_label } and run_resident_app(configuration, options, tray, on_active, on_closed, should_close) provide a native tray with a disposable window factory.
  • macOS StatusMenuOptions { title, open_label, quit_label }, StatusMenu::new(options, open, quit) and run_resident_app_with_config(...) provide equivalent menu-bar residency.
  • Workbench UiReload::remember(state) stores presentation state without requesting a reload.

Review limits

  • The contributor authorized merging when remaining failures are unrelated to this PR. The inherited macOS IME failure and the resulting red unified check are documented above; no branch protection is bypassed and no all-green claim is made.

A real GNOME panel icon and a populated business-session/panel restoration walkthrough have not been manually accepted. No GNOME extension was installed, desktop configuration changed, or user session unlocked. Snapshot behavior and native protocol integration are not presented as a full manual business-session walkthrough.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Maka assisted with implementation, diagnosis, behavior tests, upstream integration, CI, notices and this description. Material commits carry Generated-by: Maka; retain it when squashing. The human contributor remains responsible for review and provenance.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

Healthy isolated Linux workbench at bc93674ab before upstream integration

Keep the admitted client until explicit application exit and capture presentation state before native window teardown.

Refs #6668

Generated-by: Maka
Keep the admitted Host connection alive without retaining the AppKit window or UI engine. Add an opt-in resident runner and a reusable native Open/Quit status menu; Dock reopen rebuilds the UI and all explicit Quit paths return to bounded Desktop detach.

Generated-by: Maka
Keep Ctrl+C twice aligned with the shell's window-close contract. Explicit native Quit remains the process-exit and bounded-detach path, and future reopened workbenches can close through the same request receiver.

Generated-by: Maka
Gate resident window close through a nonblocking opt-in callback and reissue close when the shared shell snapshot completes. Native Quit bypasses the gate, and terminal exit keeps its explicit application-Quit semantics.

Generated-by: Maka
Release the window UI on close and reconstruct it from process-owned configuration on Open. Gate native Quit on bounded detach and keep Host following active while no window exists.

Add Linux SNI readiness, watcher recovery and isolated D-Bus action/re-registration coverage; reuse the native macOS status menu for optional GPUI.

Generated-by: Maka
Re-enter the ordinary close path after Shell snapshot readiness and release the UI only once prepare_close admits it. Keep explicit Quit independent of snapshot readiness and detach on ordinary close if no tray is available.

Generated-by: Maka
Validate close-attempt identities and avoid reading resident state during unrelated reentrant Win32 messages.

Generated-by: Maka
Preserve the admitted client while releasing each closed UI, reject stale close replies, and route native macOS consumers and embedded tray artwork through CI. Exercise the actual native event loop through quiescence so close-and-exit regressions cannot hide behind immediately queued Open commands.

Refs #6668

Generated-by: Maka
Generate and review the native distribution closure with the locked npm dependencies. Preserve the existing Pele and Lucide notices and include the shared Unlicense text for ksni and existing Unlicense components.

Refs #6668

Generated-by: Maka
Take the published native input handler while Window still drops inside the final App update. Otherwise deferred native cleanup releases its strong entity owner after the last collection pass, leaving the UI engine alive until another window opens.

Exercise real focused paint with native state retained, verify the regression red and green, and run its locked standalone suite through the existing GPUI CI worker. Document the native cleanup boundary without changing Host policy.

Refs #6668

Generated-by: Maka
Merge upstream/rust-preview at 0a5ce77. Preserve resident desktop ownership alongside successor Host following, permission utilities and explicit reload pause states. Cover close admission during a pending native reload.

Generated-by: Maka
@me2seeks me2seeks self-assigned this Nov 7, 2026
@github-actions github-actions Bot added the effort/XXL Over 2500 readable lines label Nov 8, 2026
Integrate upstream/rust-preview cb2cc89 without restoring removed GPUI backends. Retain the admitted client in the GTK application owner, exercise release under Xvfb, and preserve shared native window lifecycle callbacks. Fix production macOS feature gates and Objective-C close ABI, and keep transport errors separate from localized message keys. The upstream fixture policy fix restores the intended human child-approval boundary.

Generated-by: Maka
Install nextest for the Linux native worker now that it executes desktop tests. Keep the generated TSV's trailing empty columns intact and import the updated native Windows fixture runner.

Generated-by: Maka
Update the existing native worker tool-discovery assertion to include the display-backed Linux desktop consumer. Fold the duplicate Linux assertion into that coverage.

Generated-by: Maka
Keep Linux's Escape reservation query inside the window module so both
keyboard paths share the policy without exposing window attributes.

Share AppKit menu tracking with selected text's Copy menu while keeping
Menu.popup completion scoped to application menus. Pass the terminal
root view to native hit testing instead of its surface.

The upstream baseline fails these platform compilations independently
of PR #6695. Native build and test validation is delegated to the main
session; only stable rustfmt and git diff --check ran here.

Generated-by: Maka
@me2seeks
me2seeks marked this pull request as ready for review November 9, 2026 02:22
Capture the UI thread while creating each window and dispatch the engine callback through that handle. The upstream global window invoke helper no longer exists.

Generated-by: Maka

@Astro-Han Astro-Han left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reviewed all 40 changed files (+2,794/−264) at 32f6c4ffcdb9c8cb4caa32ec4ae3cece00ff2dc4 against rust-preview cb2cc895896220d8dffea66d16b31329defbbf76. This separates the lifetime of the Desktop client and tray from its UI: ordinary close captures presentation state and destroys the window/engine; Open recreates a window on the admitted connection, and explicit Quit detaches the client. This is a reasonable opt-in extension to the existing native runners. An actual merge succeeds. I found no confirmed P0–P2 defect in the reviewed code; native acceptance remains incomplete.

I checked the close handshake's request identity, five-second timeout, failure recovery, and pointer-identity guard that prevents a late response from closing a replacement window. The Workbench registry holds catalog changes and commands during capture, rejects close during a pending reload, and suppresses stale/disposed responses. The existing conversation capture path flushes drafts before returning; the root state records selected conversations, side panes, settings and plugin panels. This is in-process presentation recovery, not a durable database migration or a guarantee about all pending native input.

I also checked the GTK window release and application hold, SNI registration/loss and retry, no-tray exit, AppKit status-menu ownership and Dock reopen, Windows tray/message-loop ownership, deferred destruction, repeated Open, Explorer restart fallback, and Quit while no window exists. The existing Windows limitation remains: it does not reconnect after its Host stops. AppKit/Linux continue following replacement Hosts without opening a closed workbench; permission windows stay with their original UI/connection. Host lifecycle policy and accepted work are unchanged. The new native runner APIs are opt-in. There is no database schema or protocol epoch change.

Locally, 54 targeted Node tests pass across the close/reload regressions, CI routing and license-file discovery. These tests use controlled native bindings; they do not create AppKit or Windows windows. I separately inspected the raw log of current Linux native CI: all eight Desktop tests actually ran and passed, including the explicitly enabled ignored GTK lifecycle test under Xvfb and private-D-Bus tray registration/loss/recovery/Open/Quit. The GTK case creates and releases real engines/views three times; the tray test uses a controlled SNI watcher, so neither proves a GNOME panel displays a usable icon. Current root build, packaging, tooling, Linux NSH, license and audit checks pass; macOS and Windows are still running.

The Linux/macOS baseline compile repairs are byte-for-byte identical to the four files in #6709. I checked those changes separately: window-owned Escape policy, shared native context-menu tracking without an extra application-menu completion event, and the native-hit-test root argument. Their unrelated baseline compile failures must not be counted as resident-mode regressions.

I have not locally run the AppKit or Windows resident runners, inspected a real GNOME/Explorer tray, or accepted a complete populated business-session lifecycle. Remaining acceptance includes ordinary/minimized close, reopening selected conversations/drafts/panels, duplicate Open, pending-input behavior, hidden Host replacement, utility-window cleanup, no-tray behavior and bounded Quit under real desktop conditions. Current author-provided macOS/Windows observations and historical GPUI screenshots are not my verification. The passing Linux fixture tests and code review do not close that wider acceptance scope.

Current integration update: #6705 has since been merged by another contributor, advancing rust-preview to 8c1b8fc16d647dce0960137840c72f8253c63d7d. An actual merge of this unchanged PR into that current base now fails with content conflicts in scripts/ci.test.mjs and third-party/nsh/crates/nsh-platform-macos/src/chrome.rs. The successful merge above refers to the preceding cb2cc895 base. Please reconcile those overlaps before merging; this does not establish a new runtime defect.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

Merge upstream/rust-preview through 1cba85e, including #6705 native clipboard and focus fixes. Prefer the upstream native compile repairs and remove the superseded local query/menu variants, while retaining Linux desktop routing, nextest installation and its behavioral coverage.

Generated-by: Maka

@Astro-Han Astro-Han left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reviewed merge commit a48c7c49a069018d4013152c32a7fd5e050b36a9, whose parents are the previously reviewed 32f6c4ffcdb9c8cb4caa32ec4ae3cece00ff2dc4 and then-current rust-preview 1cba85e51aad22958d1af2fb856a0e5ca01ece4d. The PR now has 36 residual files (+2,759/−232) against that base. The two previously reported integration conflicts are resolved, and an actual merge succeeds. I found no confirmed new P0–P2 issue in this merge review.

I separated incoming changes from this PR: of the 58 files changed from the previous PR head, 56 are byte-for-byte identical to the incoming base. Of the 36 files remaining in the PR, 34 are identical to the already reviewed implementation. The two combined files are scripts/ci.test.mjs and scripts/ci/setup.mjs. The resolved test file retains both the Linux display-backed Desktop selection test and the incoming release-tool/digest/retry test. Setup retains the Desktop's nextest selection and XRandR/XFixes dependencies alongside the incoming setup changes. I ran the actual current close/reload, CI and license-discovery Node tests: all 55 pass.

I also checked the merge resolutions and incoming replacements. macOS chrome.rs takes the base's shared track_menu implementation/signature; application-popup completion remains separate from native context-menu tracking. The Linux scroll/window code takes the base's Escape predicate and pub(crate) attributes visibility together, rather than retaining a private-field access with mismatched visibility. These files match the incoming base. This review does not claim a fresh audit of the incoming agent replay feature in #6654.

CI 42555575165 has completed with failure; tooling, license and audit checks have passed. The current macOS job has now failed: 107 platform library tests pass, then the inherited rich_editor_composition_commit_matches_preedit_and_keeps_shortcuts test fails at third-party/nsh/crates/nsh-platform-macos/tests/terminal/cases.rs:1335 because the composition commit returns false (0.896 seconds). The native group records seven passes, one failure and two unrun tests; Desktop close/reopen tests are not reached. The incoming 1cba85e5 base fails the same assertion (0.734 seconds), and this entire test file has the same blob in the base and this PR. I therefore have no evidence that this residency change caused that failure; it is the already reported test failure from #6705. The Windows job has now completed successfully: 225 platform tests pass with one skipped, all 22 Desktop tests pass in 289.736 seconds, and both pixel tests pass in 1.481 seconds. The overall run has completed with failure because of the inherited macOS composition assertion. Full business-session and real tray behavior remain unverified. I have now also read the current Linux native job: all eight Desktop tests pass on this merge commit, including GTK view/engine release and reopen (1.356 seconds) and private-D-Bus tray recovery (5.525 seconds). This is Xvfb and a controlled SNI watcher, not a visible GNOME panel or full business-session acceptance. Real GNOME/Explorer tray behavior, AppKit/Windows close and reopen, pending input, populated conversations/drafts/panels, hidden Host replacement, permission-window cleanup and bounded Quit remain open acceptance items. No database schema or protocol epoch change is introduced by this merge.

Landed integration update: this PR has now been merged by another contributor as 9864d52160376f23aac53cfeb0d389e679e121a0. I verified that the actual merge tree of incoming 033e1a50 and reviewed head a48c7c49 exactly matches the landed tree. That incoming base includes #6710, whose macOS composition regression now passes; the earlier failure above belongs to this PR's pre-fix CI snapshot. The landed branch has its own running CI. I have also read its Linux native job: all eight Desktop tests pass, including GTK release/reopen (1.186 seconds) and controlled SNI recovery (5.486 seconds). This remains display-backed Xvfb/private-D-Bus testing. I have now read the landed macOS job: all 107 platform library tests and all 10 terminal-native tests pass, including the repaired composition regression (0.354 seconds). Desktop then stops at its sixth test, the Goal workflow: after 67.830 seconds it cannot find a single Pause Goal control (desktop_new_session.rs:230). Five Desktop tests pass, one fails and 16 are unrun; pixel tests are not reached. The same Goal test body passes on the incoming 033e1a50 run; this PR changes only a different test in that file. The log and uploaded failure artifact do not identify which of the repeated Pause Goal waits failed or isolate the cause. I have not established whether the residency change caused it, and full business-session acceptance remains open. The branch has since advanced to 75fe3d0e059c58b798782604668f37b56a420255 after #6683. I read that baseline's macOS job: all 107 platform library tests, all 10 terminal-native tests and all 22 Desktop tests pass (217.652 seconds), including the Goal workflow (14.450 seconds). The first pixel test passes; the second then fails after 0.355 seconds while loading the unchanged fixture that binds reserved Cmd+H. This newer passing Goal result does not establish the cause of the earlier 9864d521 failure. The landed Windows job has now succeeded: 226 platform tests pass with one skipped, including the resident close/reopen/hidden-Quit test (0.580 seconds). All 22 Desktop tests pass in 334.121 seconds, including the Goal workflow (21.428 seconds), and both pixel tests pass in 1.500 seconds. The overall 9864d521 run has completed with failure because of the macOS Goal failure described above; its cause remains unestablished. The newer 75fe3d0e Windows job has also succeeded: 226 platform tests pass with one skipped, all 22 Desktop tests pass in 327.844 seconds, and both pixel tests pass in 1.452 seconds. That overall run has completed with failure because of its separate macOS Cmd+H fixture error. At 606a11c27658484d52aa43c4f92066e68e6623f2, #6714 changed two test files (removing reserved Cmd+H and adding a Goal/Todo control wait); I inspected that diff and have now read its Windows job: 226 platform tests pass with one skipped, including the resident close/reopen/hidden-Quit test (0.496 seconds). All 22 Desktop tests pass in 323.098 seconds, including Goal (20.609 seconds), and both pixel tests pass in 1.510 seconds. The macOS job has now also succeeded: all 107 platform library tests, all 10 terminal-native tests, all 22 Desktop tests (196.573 seconds, Goal 14.948 seconds), and both pixel tests (2.182 seconds) pass. The overall 606a11c2 run has completed successfully. This provides passing native regression evidence after the fixture changes; it does not establish the cause of the older Goal timeout. The branch then advanced to ee7e906056aa256e584e21e060ae106e6399c094 through #6703. Its separate CI 42586921797 has now succeeded. I read the native logs: macOS passes 107 platform-library tests, 10 terminal-native tests, all 22 Desktop tests (257.876 seconds), and both pixel tests (3.842 seconds); Windows passes 226 platform tests with one skipped, all 22 Desktop tests (281.816 seconds), and both pixel tests (1.276 seconds). I inspected #6703's log and three-file change summary, not its implementation. These regression results do not complete the real resident-window, populated historical-session or cross-application acceptance described above. The complete native/business-session acceptance remains open.

Subsequent baseline CI update (2026-11-09): The separate Rust baseline 09ca38c23ae9d46214c2743e182fe018c6544429 now has a successful CI run 42612011937, attempt 1. All 35 jobs have finished, including the final test aggregate; I read its log confirming that all planned work succeeded. The native logs I read for that baseline pass macOS 107 platform-library, 10 terminal-native, 22 Desktop (239.939 seconds) and two pixel tests (2.644 seconds); Windows passes 227 platform tests with one skipped, 22 Desktop (338.712 seconds) and two pixel tests (1.470 seconds). The 22 root-test shards total 2,271 passing tests. This closes the previously pending aggregate, while the original Goal-timeout cause, populated historical-state recovery, real desktop residency and cross-application acceptance limits above remain unresolved.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@me2seeks

me2seeks commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Maka CI diagnosis for current head a48c7c49a:

The macOS failure is also present in the final CI of merged #6705, independently of this PR:

  • Upstream: run 42553740495, native-macos, head 3b6336a6c.
  • This PR: run 42555575165, native-macos, head a48c7c49a.
  • Both fail rich_editor_composition_commit_matches_preedit_and_keeps_shortcuts at cases.rs:1335: apply_composition(&target, "方向", "", None, false) returns false.
  • Both pass the preceding seven native surface cases, including the formerly failing hidden/clipped subtree test. This head also passes all 107 macOS NSH unit tests.

The affected IME test and platform input implementation match the integrated upstream code; no assertion, deadline or selector was relaxed here. A queued-composition/focus-admission interaction is being investigated, but is not yet a confirmed runtime root cause or a fix.

All 22 root partitions, Linux native, Linux NSH, packaging, product, bridge, NSH, tooling, licenses and audit have passed. Windows hosted native verification is still pending, so this is not an all-green claim. Local Windows product tests (4) and the actual resident lifecycle regression (1) passed after this integration.

Automated diagnosis by Maka.

@me2seeks
me2seeks merged commit 9864d52 into rust-preview Nov 9, 2026
35 of 37 checks passed
@me2seeks
me2seeks deleted the fix/6668-desktop-tray branch November 9, 2026 04:54
@M4n5ter

M4n5ter commented Nov 9, 2026

Copy link
Copy Markdown
Member

@me2seeks

English

Post-merge review of 9864d52160 (#6695), especially in light of how it interacts with third-party/nsh (323a8663, synced in #6708) and downstream desktop features like #6707:

1. Architectural overlap and tension with third-party/nsh (nsh/desktop)

After #6708, upstream third-party/nsh already provides cross-platform native desktop primitives out of the box on a single nsh_engine::Engine:

  • System tray / status bar (nsh/desktop Tray / DesktopCommand::SetTray): implemented natively in nsh-platform-macos/src/tray.rs (NSStatusItem with SVG template icon tinting, VoiceOver labels, and primary/secondary click handling), nsh-platform-windows/src/tray.rs (Shell_NotifyIconW v4 with taskbar-theme template recoloring and TaskbarCreated recovery), and nsh-platform-linux/src/tray.rs (native D-Bus StatusNotifierItem + dbusmenu, without needing ksni).
  • Hide-on-close & explicit quit: closeOnPress: false on the main window (nsh-platform-macos/src/window.rs:1715, nsh-platform-windows/src/window_close.rs:41, nsh-platform-linux/src/window.rs:1483) + WindowRequest::{Hide, Show, Focus} + Application.quit() (DesktopCommand::Quit, which exits cleanly even when hidden to tray/Dock), plus GlobalShortcut and secondary <Window kind="popup"> windows.

Because #6695 chose to tear down the entire NSH Engine / Surface on every window close (rather than keeping the lightweight QuickJS engine alive, hiding the main window, and unmounting heavy Workbench subtrees while hidden), it could not use nsh/desktop's surface-owned Tray and instead introduced parallel tray/lifecycle machinery across three places:

  • Local fork additions in third-party/nsh: nsh-platform-macos/src/status_menu.rs + run_resident_app_with_config and nsh-platform-windows/src/app/resident.rs (515 lines duplicating Shell_NotifyIconW alongside tray.rs).
  • products/maka/desktop-shell/src/tray_linux.rs (343 lines + ksni, polling service.0.is_closed() with a 1s sleep loop at tray_linux.rs:86-88).
  • Any multi-window or background desktop capability (GlobalShortcut, <Window kind="popup">, or with_running_view callers) goes dead whenever the main window is closed because RUNNING / RUNNING_VIEW becomes None.

2. Concrete issues in 9864d52160

  1. HostChannel reset/drop wipes host handlers registered during host::connect:
    • products/maka/desktop-shell/src/appkit.rs:137 (config.host = HostChannel::new()), linux.rs:186, 273, and direct2d.rs:75, 86-93 (which drops first.config completely) discard any handlers attached to Connection.config.host in host.rs. Any feature registering host handlers at admission silently loses them on open/reopen (this directly broke #6707).
  2. macOS custom URL schemes (maka://...) do not reopen a closed resident window:
    • In third-party/nsh/crates/nsh-platform-macos/src/app.rs:643-664, open_urls queues the URL into URL_SCHEMES when RUNNING is None, calls app.activate(), and only raises an existing RUNNING window—it never calls reopen_window(self), so opening a deep link while closed to the menu bar leaves no window visible.
  3. Windows loses Maximized state across close/reopen:
    • third-party/nsh/crates/nsh-platform-windows/src/app/resident.rs:280-285 unconditionally overwrites placement.showCmd = SW_SHOWNORMAL.0 as u32 before SetWindowPlacement, restoring a previously maximized window as normal-sized on reopen; direct2d.rs:86-93 also drops transient AppView settings such as set_font_scale unless re-sent.
  4. Menu-bar presentation & localization (CONTRIBUTING.md):
    • status_menu.rs:99-101 sets a plain text title ("Maka") with no template icon or accessibility label, and tray menu labels ("Open Maka" / "Quit") are hardcoded in English in appkit.rs:101-103, direct2d.rs:81-83, and tray_linux.rs:150-156 rather than following en / zh-CN / zh-TW.
  5. Silent close drop on capture timeout/reload:
    • In products/maka/desktop-shell/src/shell/close.rs:130-161, if close capture times out (5s) or races a reload, prepare_close resets to Phase::Open and logs to stderr, leaving the user's close click with no visible effect.

Suggested follow-up

We should converge desktop residency back onto nsh/desktop's built-in single-engine Tray + closeOnPress: false + WindowRequest::{Hide, Focus} + Application.quit() (unmounting heavy Workbench view trees when hidden if needed), remove the custom resident/tray forks from third-party/nsh and tray_linux.rs (ksni), and keep one live HostChannel / NSH engine so global shortcuts and popup windows (#6707) work seamlessly while the main window is hidden.

中文

对已合入的 9864d52160(#6695)做一次补充复核,重点在于它与上游 third-party/nsh(#6708 同步的 323a8663)以及后续桌面能力(如 #6707)的架构关系:

1. 与 third-party/nsh(nsh/desktop)原生能力的重叠与冲突

#6708 同步后,third-party/nsh 在单 nsh_engine::Engine 模型下已经原生提供了完整的三端桌面基建:

  • 系统托盘 / 状态栏(nsh/desktop Tray / DesktopCommand::SetTray):nsh-platform-macos/src/tray.rs(NSStatusItem + SVG 模板图标自适应配色 + VoiceOver 标签 + 左右键分离)、nsh-platform-windows/src/tray.rs(Shell_NotifyIconW v4 + 随任务栏主题重绘模板图标 + TaskbarCreated Explorer 重启恢复)、nsh-platform-linux/src/tray.rs(原生 D-Bus StatusNotifierItem + dbusmenu,无需引入 ksni)。
  • 关闭隐藏与显式退出:三端主窗口均支持 closeOnPress: false + WindowRequest::{Hide, Show, Focus} + Application.quit()(DesktopCommand::Quit 在隐藏驻留时也会干净退出),同时支持三端 GlobalShortcut 和 <Window kind="popup"> 悬浮子窗口。

由于 #6695 采取了“关主窗口时销毁整个 NSH Engine / Surface、重开再新建引擎”的前提(而非保留轻量的 QuickJS 引擎、隐藏主窗口并按需卸载重型 Workbench 视图子树),导致无法使用归属 Surface 的原生 Tray,转而维护了三套平行实现:

  • 在 third-party/nsh 中新增了本地 fork 代码:nsh-platform-macos/src/status_menu.rs + run_resident_app_with_config,以及 nsh-platform-windows/src/app/resident.rs(515 行,在 tray.rs 旁重复实现了一套 Shell_NotifyIconW);
  • 在 desktop-shell 新增 ksni 依赖和 tray_linux.rs(343 行,86-88 行通过 sleep(1s) 轮询 is_closed());
  • 主窗口关闭期间 RUNNING / RUNNING_VIEW 为 None,导致任何依赖单引擎或 with_running_view 的多窗口/全局快捷键能力在驻留期间全部失效。

2. 9864d52160 中的具体缺陷

  1. 重建/丢弃 HostChannel 清空 host::connect 挂载的处理器:appkit.rs:137(config.host = HostChannel::new())、linux.rs:186, 273 以及直接 drop(config) 的 direct2d.rs:75, 86-93 会把 host.rs 在连接准入阶段注册的 HostChannel 处理器全部丢弃(在 #6707 合并后直接导致主窗口与非 macOS 端通道失效)。
  2. macOS 驻留隐藏期间收到 URL Scheme 不会拉起窗口:nsh-platform-macos/src/app.rs:643-664 的 open_urls 在 RUNNING 为 None 时只把链接塞进 URL_SCHEMES 并调用 app.activate(),未调用 reopen_window(self)。
  3. Windows 关闭再打开丢失最大化状态:nsh-platform-windows/src/app/resident.rs:280-285 将 placement.showCmd 强制改写为 SW_SHOWNORMAL,最大化窗口关闭后从托盘重开会退回普通尺寸。
  4. 菜单栏展示与多语言问题:status_menu.rs:99-101 只显示纯文本 "Maka"(无模板图标与无障碍标签),且三端托盘菜单硬编码英文 "Open Maka" / "Quit",未跟随 en / zh-CN / zh-TW。
  5. 关闭快照超时/冲突时静默吞掉关闭动作:shell/close.rs:130-161 在 5 秒超时或遇到 reload 时重置回 Phase::Open 并仅打日志,用户点击关闭无响应。

后续建议

建议后续将桌面常驻收敛回 nsh/desktop 原生单引擎模型(Tray + closeOnPress: false + WindowRequest::{Hide, Focus} + Application.quit(),隐藏时按需卸载重视图树),移除 third-party/nsh 中的 status_menu.rs / resident.rs fork 与 tray_linux.rs(ksni),让托盘、全局快捷键与悬浮子窗口(如 #6707)共享同一个 NSH 引擎与 HostChannel。


Automated review by Antigravity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/XXL Over 2500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants