Skip to content

refactor(desktop): stay resident through the single UI engine - #6725

Merged
ARE404 merged 4 commits into
apache:rust-previewfrom
ARE404:refactor/desktop-single-engine-tray
Nov 10, 2026
Merged

ARE404 merged 4 commits into
apache:rust-previewfrom
ARE404:refactor/desktop-single-engine-tray

Conversation

@ARE404

@ARE404 ARE404 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Summary

#6695 kept the Rust preview available after its window closed by tearing the UI engine down and adding a separate tray and lifecycle to each desktop backend. The post-merge review on #6695 asked for this to go through one engine, and it is step 3 of the Quick Tools split agreed in #6707, because the launcher needs the same resident engine.

This replaces those paths with nsh/desktop:

  • The workbench sets closeOnPress: false, hides on closePress, and owns the Tray (desktopResidency.ts). Tray labels are localized.
  • Closing hides the window. The one engine and its Host client stay. The tray's Open brings it back, and Quit detaches and exits.
  • The per-backend residency code and the ksni dependency are gone.

Refs #6668, #6695, #6707

Behavior kept from #6695

  • Explicit Quit detaches from the Host.
  • Linux without a panel hosting the tray: closing quits, and a panel that leaves brings a hidden window back.
  • A Host replacement does not pop up a hidden window. On macOS a failed reconnect does, because the tray stops with the engine.

Root causes fixed on the way

With closeOnPress: false, three exit paths stopped working:

  • Windows quit_app posted WM_CLOSE, which became a hide. It now quits directly.
  • Linux Ctrl+Q and terminal.exit went through the close request. They now run a real quit. Ctrl+W still hides.
  • macOS ignored the close button while no engine was running to answer it. It now closes.

Review focus

The engine now stays alive while the window is hidden, so a hidden app uses more memory than under #6695. Unmounting heavy subtrees while hidden is not part of this PR.

Verification

  • macOS, cargo clippy -p maka-desktop-shell -p nsh-platform-macos --all-targets -- -D warnings: passes.
  • macOS, real desktop renderer, native-desktop terminal::desktop_new_session under an English locale: 22 passed. The tests look controls up by English label, so they fail on a zh-CN system.
  • node --test products/maka/workbench/tests/*.test.mjs: 160 passed.
  • node scripts/ci.mjs check notices and scripts/asf-license-headers.mjs check: pass.
  • node --test scripts/ci.test.mjs: 38 passed, 1 failed locally because this machine's Python has no tomllib.
  • node scripts/ci.mjs run contracts: the only errors are DOM names missing in node_modules/pele declarations. None are in the changed sources.
  • Windows: nsh-platform-windows is type-checked from macOS. maka-desktop-shell could not be, because aws-lc-sys needs windows.h. terminal_exit_closes_the_native_window now sets closeOnPress: false first, and only runs on Windows CI.
  • Linux: not compiled or run locally. linux.rs relies on CI.
  • Not run on any platform: a manual close, tray reopen and tray quit. No automated test drives the native tray.

AI use

Select exactly one:

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

Tool(s) and scope: Claude Code helped with implementation and debugging under the author's direction. The author reviewed the scope and direction.

Checklist

  • Tests cover the change and fail without it (the only new assertion is the Windows quit path; see Verification)
  • Format, typecheck and the affected suites pass locally (exceptions under Verification)

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

Closing the Rust preview window tore the engine down and kept a separate
tray and lifecycle in each desktop backend. Replace that with the
nsh/desktop Tray and closeOnPress: false from the workbench: closing hides
the window, the one engine and Host client stay, and the tray's Quit
detaches and exits.

Quit now really quits. Windows quit_app posted WM_CLOSE, which
closeOnPress: false turns into a hide. Linux Ctrl+Q and terminal.exit went
through the close request. macOS honours the close button while no engine
is running to answer it.

Linux without a panel hosting the tray closes as quit, and a panel leaving
brings a hidden window back. On macOS a failed reconnect shows a hidden
window, because the tray stopped with the engine.

@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 the 38-file change at c8ac438d71abb743030c0ea9fabecbc675e8cc36 against Rust baseline 09ca38c23ae9d46214c2743e182fe018c6544429. I found one P2 issue, detailed inline: Linux treats ownership of the tray watcher's bus name as proof that its icon can restore the window.

This replaces the separate resident runners and close-state handshake with one retained workbench engine and the standard NSH tray. I checked App-owned residency, the native WindowRef.on lifetime (it already cleans itself up with its reactive owner), ordinary reload state capture, GTK close/quit and Host reconnection, AppKit close without an engine, Windows explicit Quit, native runner removals, license inputs and CI routing. The no-watcher and watcher-loss branches retain a fallback, but registration failure while the watcher remains present bypasses it.

I ran all 160 workbench JavaScript tests and all 39 CI-script tests successfully. Four controlled executions of the production residency module cover close, tray click/Open, explicit Quit and locale updates. For the finding, an extracted copy of the production watch_tray function driven by controlled bus callbacks sets readiness on name appearance regardless of icon registration; loss of that name clears readiness and restores the window. Separately, a real private D-Bus session demonstrates a watcher owning the expected name while rejecting RegisterStatusNotifierItem. This is source/protocol validation with controlled window adapters, not a native GTK reproduction.

The actual merge into 09ca38c2 succeeds. There is no database-schema change. CI 42648285382 is still running, with several workers queued; I do not claim its native builds or tests have passed. This and #6723 are alternative changes to the same lifecycle, and their current heads conflict in 13 files. I did not locally compile the native backends or execute manual tray, populated-session, historical-state or packaged-app acceptance; the author-reported macOS and cross-compilation checks remain attributed to the author.


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.

Owning org.kde.StatusNotifierWatcher does not mean the watcher accepted
the icon, so a rejected registration left a closed window unreachable.
NSH now records the watcher's answer, the shell asks it when the window
closes, and losing an accepted icon brings a hidden window back.

@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 checked the three-file follow-up from c8ac438d71abb743030c0ea9fabecbc675e8cc36 to 6fa98ebc1d1d3bf55133fc140343c5a9b035f215, including the author's reply to my earlier finding. This is an incremental review of that fix; the earlier review's broader scope and native acceptance limits still apply.

The immediate rejection case is fixed: close-request now uses NSH's registration result instead of watcher-name ownership, and losing an accepted registration restores a hidden window. However, the P2 is not fully resolved: a successful reply from a watcher that has already withdrawn can set registration back to true. The inline comment describes the remaining sequence.

I compiled an extracted, unchanged copy of tray_registered, on_tray_lost and record_registration with controlled tray state. Four checks pass (acceptance, rejection, loss notification and ignoring a removed item); the fifth fails because a late success after watcher loss revives permission to hide. Separately, a real private D-Bus session produces the relevant ordering: the watcher receives registration, releases its well-known name while keeping its connection, the client observes disappearance, and the old service then replies successfully. This validates the asynchronous protocol premise; it is not a full GTK/window reproduction.

The actual merge into current Rust 12971e440e93af1501872ec8eaf6bd781360ba92 succeeds. No database schema changes are involved. Current-head CI 42655492170 is still pending/running; the previous head's run was cancelled after the update and is not evidence for this head. I did not locally compile GTK or repeat manual tray, packaging or populated-session acceptance.


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.

A watcher can give up its name and still answer afterwards. The late
success marked the icon registered with no watcher holding it, so
closing the Linux window hid it for good. Each registration is now an
attempt that the watcher's disappearance forgets.

@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 the follow-up from 6fa98ebc1d1d3bf55133fc140343c5a9b035f215 to a3ef0f05ce8284a27e2a196847bc749e42d1e626, after reading the author's reply. The directly observed rejection and late-registration-reply paths from my two earlier P2 comments are now fixed in this reviewed scope; I found no additional demonstrated P0–P2 issue in this delta.

Registration::Pending(attempt) now identifies the request being awaited. Watcher disappearance changes the state to Absent, and a result is accepted only if its attempt is still pending. This prevents an old watcher's success from re-enabling hiding after withdrawal or replacing a newer registration's result. GTK still allows hiding only after tray_registered() becomes true, and loss of an accepted registration restores the window.

I compiled unchanged copies of the production registration functions with controlled tray state and ran eight checks successfully: absent/pending/rejected state, current acceptance, one-time loss notification, late success after disappearance, replacement attempts, removed/recreated items and overlapping attempts. The previous 6fa98ebc functions fail the late-success assertion. My separate real private D-Bus fixture demonstrated that a service can release the watcher name and still reply successfully on its original connection; the new attempt check rejects that sequence.

These are source/protocol and extracted-function checks, not native GTK compilation or a real tray/window acceptance run. The earlier review's manual platform, packaging, populated-session and historical-state limits remain. The actual merge into Rust 12971e440e93af1501872ec8eaf6bd781360ba92 succeeds. There is no schema change. Current-head CI 42671988062 has not completed; the older cancelled runs are not evidence for this head.


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.

currentWindow() throws outside a render, so the module-level call
stopped the script before it posted terminal.exit and the test timed
out without exercising the close.

@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 the one-file follow-up from a3ef0f05ce8284a27e2a196847bc749e42d1e626 to 6748bc371e95e9dab56dcd3dd3ac22e0c7d39555. It changes only the JavaScript fixture in direct2d::tests::terminal_exit_closes_the_native_window; I found no additional demonstrated P0–P2 issue in this delta.

The fixture previously called currentWindow() at module scope. I checked its actual implementation in nsh-js/src/window.rs: it requires a reactive owner and otherwise throws before the following host.post('terminal.exit') can execute. The new fixture moves both operations into mount's callback. I traced the real mount implementation, which invokes that callback inside reactive::with_root, and the existing terminal.exit handler through the exit channel to Windows quit_app. The 30-second watchdog and timeout assertion remain, so a watchdog-triggered exit is still rejected by the test.

The preceding head's Windows job 129410284961 failed this test after 30.055 seconds with terminal.exit did not close the native window. That log establishes the timeout; the explanation for the missing post is supported by the source path above, rather than a logged JavaScript exception. The same head's macOS job passed its four shell tests, 107 platform tests and ten native input tests, then failed a separate Desktop test waiting for Start a response (observed: Null, 68.321 seconds; two passed, one failed, 19 unrun). This Windows-only fixture change does not establish a fix for that macOS failure.

The Direct2D production prefix and all three Linux registration-related source files are unchanged from the previously reviewed head. The earlier rejection and late-reply P2 fixes therefore remain present; I did not rerun their eight extracted-function checks in this follow-up. An actual merge into current Rust 12971e440e93af1501872ec8eaf6bd781360ba92 succeeds, and there is no schema change.

Current-head CI 42706549065, attempt 1 has completed with failure. I read the three failing native/CLI job logs. Their explicit checkout is 6134e79f8895dbaa9594857670dcac7838385b4c; its parents are current Rust 12971e44 and this PR's 6748bc37, and its tree matches my actual merge above.

The corrected Windows exit test now passes in 0.181 seconds, and all three Windows shell tests pass. Its 226 platform tests also pass with one skipped. The Windows job later fails Desktop test 20, desktop_steering_freezes_each_message_and_queue_is_one_shot, waiting for Check keyboard focus too. (observed: Null, 73.698 seconds): 19 Desktop tests pass, one fails and two remain unrun. On macOS, four shell and 107 platform tests pass, but native test 8, rich_editor_composition_commit_matches_preedit_and_keeps_shortcuts, times out settling the app after 6.017 seconds (seven pass, one fails, two unrun); that stops the job before Desktop acceptance. CLI shard 2 fails the editor-copy/undo/interrupt UI wait after 65.954 seconds (18 pass, one fails, 94 skipped). The current 12971e44 baseline also has a recorded failure of that CLI case, so that particular failure is not new evidence of this PR causing it. The other failures have not been isolated as PR-caused or harmless.

The Windows result supports this fixture correction, not overall CI success or complete residency acceptance. I did not locally build or execute Windows, compile GTK, or perform manual tray, populated-session, historical-state or packaged-app acceptance. Those limits remain; no rerun was triggered.


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.

@ARE404
ARE404 merged commit c20025e into apache:rust-preview Nov 10, 2026
33 of 37 checks passed
@ARE404
ARE404 deleted the refactor/desktop-single-engine-tray branch November 10, 2026 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants