fix(tray): handle role-only Linux quit items#547
Conversation
avifenesh
left a comment
There was a problem hiding this comment.
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, () => { |
There was a problem hiding this comment.
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.
Summary
Fix Linux tray Quit when the upstream menu contains a role-only
{role: "quit"}item.Electron ignores
clickhandlers whenroleis 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
getNativeTrayMenuItems()with an explicit label/click handler.Menu.buildFromTemplate([{ role: "quit" }])keep working.Verified
node --test --test-name-pattern='role-only tray quit' scripts/patch-linux-window-ui.test.jsnode --test --test-name-pattern='upstream renames the quit label helper' scripts/patch-linux-window-ui.test.jsnode --test --test-name-pattern='explicit tray quit patching when minified aliases drift' scripts/patch-linux-window-ui.test.jsnode --check scripts/patches/main-process/quit-lifecycle.jsnode --check scripts/patch-linux-window-ui.test.jsgit diff --checkFull
node scripts/patch-linux-window-ui.test.jsstill has two existing CLI--enforce-criticalassertion failures; the same two fail with this diff reverted.