Skip to content

fix(tray): handle role-only Linux quit items#547

Closed
pradigmaz wants to merge 1 commit into
ilysenko:mainfrom
pradigmaz:fix/linux-tray-role-quit
Closed

fix(tray): handle role-only Linux quit items#547
pradigmaz wants to merge 1 commit into
ilysenko:mainfrom
pradigmaz:fix/linux-tray-role-quit

Conversation

@pradigmaz

Copy link
Copy Markdown
Contributor

Summary

Fix Linux tray Quit when the upstream menu contains a role-only {role: "quit"} item.

Electron ignores click handlers when role is set, so the Linux explicit-quit marker was not applied for that tray menu shape. The app could then re-enter the close-to-tray path instead of exiting.

Changes

  • Replace role-only tray Quit items inside getNativeTrayMenuItems() with an explicit label/click handler.
  • Scope the replacement to tray menu construction so helper uses of Menu.buildFromTemplate([{ role: "quit" }]) keep working.
  • Add regression coverage for the role-only tray Quit shape.

Verified

  • node --test --test-name-pattern='role-only tray quit' scripts/patch-linux-window-ui.test.js
  • node --test --test-name-pattern='upstream renames the quit label helper' scripts/patch-linux-window-ui.test.js
  • node --test --test-name-pattern='explicit tray quit patching when minified aliases drift' scripts/patch-linux-window-ui.test.js
  • node --check scripts/patches/main-process/quit-lifecycle.js
  • node --check scripts/patch-linux-window-ui.test.js
  • git diff --check

Full node scripts/patch-linux-window-ui.test.js still has two existing CLI --enforce-critical assertion failures; the same two fail with this diff reverted.

@avifenesh avifenesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is an auto review done by revuto.


Reviewed the role-only tray Quit fix in quit-lifecycle.js plus its regression test. Per the always-on check for scripts/patches/, I verified the new patchRoleOnlyTrayQuitItems replaces ALL eligible occurrences (it uses the global roleOnlyTrayQuitRegex inside each method body and walks every getNativeTrayMenuItems(){ via index-based cursor advancement, not a single string.replace()), and that idempotency holds (the patched output no longer contains {role:quit}, so a second pass is a no-op — confirmed by applyPatchTwice).

One scoping concern worth confirming below; the rest of the change looks consistent with the existing tray-quit patch helpers and the electronVar alias resolution.

}

const body = patchedSource.slice(openIndex + 1, closeIndex);
const patchedBody = body.replace(roleOnlyTrayQuitRegex, () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is an auto review done by revuto.


Scoping note (please confirm against the real bundle): the replacement targets any {role:quit} token anywhere inside the getNativeTrayMenuItems(){...} body. The PR's stated intent ("Scope the replacement to tray menu construction so helper uses of Menu.buildFromTemplate([{ role: \"quit\" }]) keep working") is satisfied only when the label-helper that calls Menu.buildFromTemplate([{role:quit}]) is defined outside this method. The test at line 1617 places mH as a sibling function, which passes — but if upstream ever inlines such a helper (or any other Menu.buildFromTemplate([{role:quit}]) call) inside getNativeTrayMenuItems, this regex would rewrite that template entry into a {label:Quit,click:...} item too, changing the helper's label-extraction result. Worth an assertion or a tighter anchor (e.g. requiring the token to be a top-level array element of the returned menu) if that shape is plausible in the bundle.

@pradigmaz pradigmaz closed this Jun 22, 2026
@pradigmaz pradigmaz deleted the fix/linux-tray-role-quit branch June 22, 2026 19:34
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