Repository navigation
Open a menu route summoned during startup once the menu files load #15519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
omarchybot
wants to merge
4
commits into
quattro
Choose a base branch
from
omabot/pr-14055
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
43d787d
Open a menu route summoned during startup once the menu files load
buger 4840566
Wait for both menu files before opening a route summoned during startup
buger 3854c04
Merge quattro into fix/menu-pending-route
omarchybot e155850
Give a startup route its one try once both menu files have answered
omarchybot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,242 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| # The shell hands a summon queued during startup to the menu as soon as the | ||
| # plugin loads, before either FileView has read its JSONC file. These checks | ||
| # run Menu.qml's own open, navigation and FileView handler code in a vm | ||
| # context and load the two files in either order around the summon. | ||
| run_node_test <<'JS' | ||
| const fs = require('fs') | ||
| const vm = require('vm') | ||
|
|
||
| const MenuModel = requireFromRoot('shell/plugins/menu/MenuModel.js') | ||
| const menuQml = fs.readFileSync(path.join(root, 'shell/plugins/menu/Menu.qml'), 'utf8') | ||
| const defaultJsonc = fs.readFileSync(path.join(root, 'default/omarchy/omarchy-menu.jsonc'), 'utf8') | ||
| const stockUserJsonc = fs.readFileSync(path.join(root, 'config/omarchy/extensions/omarchy-menu.jsonc'), 'utf8') | ||
| const personalJsonc = '{ "personal": {"label":"Personal"}, "personal.notes": {"label":"Notes","action":"notes"} }' | ||
| const aboutOverrideJsonc = '{ "about": {"label":"About","action":"my-about"} }' | ||
|
|
||
| const qmlFunctions = ['open', 'close', 'openRoute', 'resolveRoute', 'item', 'openExistingMenu', 'openDmenu', 'cancel', | ||
| 'parseMenuJsonc', 'menuFilesAnswered', 'rebuildItemsFromSources', 'setFilter', 'setActiveMenu', 'goBack'].map(name => { | ||
| const fn = menuQml.match(new RegExp(` function ${name}\\([^]*?\\n }`)) | ||
| if (!fn) fail(`Menu.qml provides ${name}`) | ||
| return fn[0] | ||
| }) | ||
|
|
||
| function handler(fileId, signal) { | ||
| const found = menuQml.match(new RegExp(`id: ${fileId}\\n[^]*?${signal}: (\\{[^\\n]*\\})`)) | ||
| if (!found) fail(`Menu.qml ${fileId} handles ${signal}`) | ||
| return found[1] | ||
| } | ||
| const defaultLoaded = handler('defaultMenuFile', 'onLoaded') | ||
| const userLoaded = handler('userMenuFile', 'onLoaded') | ||
| const userLoadFailed = handler('userMenuFile', 'onLoadFailed') | ||
| const defaultLoadFailed = handler('defaultMenuFile', 'onLoadFailed') | ||
|
|
||
| // The menu's own initial values for the properties this path reads. | ||
| function initial(name) { | ||
| const found = menuQml.match(new RegExp(`property (?:string|var|bool) ${name}: ([^\\n]*)`)) | ||
| if (!found) fail(`Menu.qml declares ${name}`) | ||
| return vm.runInNewContext(found[1]) | ||
| } | ||
|
|
||
| // A freshly loaded plugin: no rows yet, nothing open. Display, guards and | ||
| // providers are QML-side effects outside this path, so they are no-ops here. | ||
| function startMenu() { | ||
| const menu = vm.createContext({ | ||
| MenuModel, | ||
| Qt: { callLater() {} }, | ||
| keyCatcher: { forceActiveFocus() {} }, | ||
| panel: { freezeCardTop() {} }, | ||
| pointerGate: { allowInitialSample() {} }, | ||
| appLibrary: null, | ||
| pendingInitialMenu: initial('pendingInitialMenu'), | ||
| defaultMenuItems: initial('defaultMenuItems'), | ||
| userMenuItems: initial('userMenuItems'), | ||
| defaultMenuSettled: initial('defaultMenuSettled'), | ||
| userMenuSettled: initial('userMenuSettled'), | ||
| menuCatalog: initial('menuCatalog'), | ||
| items: ({}), | ||
| itemOrder: [], | ||
| opened: false, | ||
| mode: 'menu', | ||
| rowsLoaded: false, | ||
| activeMenu: 'root', | ||
| filterText: '', | ||
| selectedIndex: 0, | ||
| cursorActive: false, | ||
| requestSerial: 0, | ||
| requestActive: false, | ||
| selectionFile: '', | ||
| doneFile: '', | ||
| navStack: [], | ||
| providerRevision: 0, | ||
| providersLoaded: ({}), | ||
| providerQueue: [], | ||
| actions: [], | ||
| evaluateGuards() {}, | ||
| rebuildDisplay() {}, | ||
| loadProvidersForSearch() {}, | ||
| loadProviderForMenu() {}, | ||
| invalidateVolatileProvider() {}, | ||
| disarmPointer() {}, | ||
| finishRequest() { menu.opened = false }, | ||
| runAction(action) { menu.actions.push(action) } | ||
| }) | ||
| menu.root = menu | ||
| Object.defineProperty(menu, 'dmenuActive', { get: () => menu.mode === 'select' || menu.mode === 'input' }) | ||
| for (const fn of qmlFunctions) vm.runInContext(fn, menu) | ||
| return menu | ||
| } | ||
|
|
||
| function load(menu, signal, raw) { | ||
| menu.text = () => raw | ||
| vm.runInContext(signal, menu) | ||
| } | ||
|
|
||
| const summon = (menu, payload) => menu.open(JSON.stringify(payload)) | ||
| const loadDefault = menu => load(menu, defaultLoaded, defaultJsonc) | ||
| const loadUser = (menu, raw) => load(menu, userLoaded, raw) | ||
| const noUserFile = menu => load(menu, userLoadFailed, '') | ||
| const noDefaultFile = menu => load(menu, defaultLoadFailed, '') | ||
|
|
||
| let menu = startMenu() | ||
| summon(menu, { menu: 'system' }) | ||
| loadDefault(menu) | ||
| assertEqual(menu.activeMenu, 'root', 'a route summoned during startup waits for the user file as well') | ||
| noUserFile(menu) | ||
| assertEqual(menu.activeMenu, 'system', 'a route summoned during startup opens once the default file loads and the user file is found missing') | ||
| menu.setActiveMenu('style', true) | ||
| loadDefault(menu) | ||
| assertEqual(menu.activeMenu, 'style', 'a replayed route is not replayed again by a later reload') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'system' }) | ||
| noUserFile(menu) | ||
| assertEqual(menu.activeMenu, 'root', 'with only the missing user file read, the route has nothing to resolve against yet') | ||
| loadDefault(menu) | ||
| assertEqual(menu.activeMenu, 'system', 'a route summoned during startup opens when the default file loads after the user file fails') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'power-menu' }) | ||
| loadUser(menu, stockUserJsonc) | ||
| loadDefault(menu) | ||
| assertEqual(menu.activeMenu, 'system', 'an alias summoned during startup opens when the default file loads after the stock user file') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'personal' }) | ||
| loadDefault(menu) | ||
| assertEqual(menu.activeMenu, 'root', 'a user-defined menu cannot resolve from the default file alone') | ||
| loadUser(menu, personalJsonc) | ||
| assertEqual(menu.activeMenu, 'personal', 'a user-defined menu summoned during startup opens when the user file loads after the default file') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'personal' }) | ||
| loadUser(menu, personalJsonc) | ||
| loadDefault(menu) | ||
| assertEqual(menu.activeMenu, 'personal', 'a user-defined menu summoned during startup opens when the user file loads first') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'personal.notes' }) | ||
| loadUser(menu, personalJsonc) | ||
| noDefaultFile(menu) | ||
| assertDeepEqual(menu.actions, ['notes'], 'a route summoned during startup gets its one try when the default file fails after the user file loads') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'system' }) | ||
| loadUser(menu, personalJsonc) | ||
| noDefaultFile(menu) | ||
| assertEqual(menu.activeMenu, 'root', 'a route the failed default file would have defined stays on root') | ||
| menu.rebuildItemsFromSources(true) | ||
| loadDefault(menu) | ||
| assertEqual(menu.activeMenu, 'root', 'a route already tried is not opened by a catalog load or a default file that reappears') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'reminder-set' }) | ||
| loadDefault(menu) | ||
| noUserFile(menu) | ||
| assertDeepEqual(menu.actions, ['omarchy-reminder -i'], 'an action alias summoned during startup runs its action once the files load') | ||
| assertEqual(menu.opened, false, 'running a replayed action alias closes the menu') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'about' }) | ||
| loadDefault(menu) | ||
| assertDeepEqual(menu.actions, [], 'an action summoned during startup does not run before the user file has answered') | ||
| loadUser(menu, aboutOverrideJsonc) | ||
| assertDeepEqual(menu.actions, ['my-about'], 'an action summoned during startup runs the user override, not the default command') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, {}) | ||
| const opens = menu.requestSerial | ||
| loadDefault(menu) | ||
| noUserFile(menu) | ||
| assertEqual(menu.activeMenu, 'root', 'a summon without a route opens root') | ||
| assertEqual(menu.requestSerial, opens, 'a summon without a route is not reopened when the files load') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'no-such-menu' }) | ||
| const missingOpens = menu.requestSerial | ||
| loadDefault(menu) | ||
| noUserFile(menu) | ||
| assertEqual(menu.activeMenu, 'root', 'a route to a missing menu still falls back to root') | ||
| assertEqual(menu.requestSerial, missingOpens, 'a route to a missing menu does not reopen root when the files load') | ||
| loadUser(menu, '{ "no-such-menu": {"label":"Added later"} }') | ||
| assertEqual(menu.requestSerial, missingOpens, 'a route to a missing menu is not opened by a later edit that adds it') | ||
|
|
||
| menu = startMenu() | ||
| loadDefault(menu) | ||
| noUserFile(menu) | ||
| summon(menu, { menu: 'personal' }) | ||
| assertEqual(menu.activeMenu, 'root', 'a summon after startup for a menu nobody defines falls back to root') | ||
| loadUser(menu, personalJsonc) | ||
| assertEqual(menu.activeMenu, 'root', 'a live edit that adds the menu later does not open it') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'personal' }) | ||
| loadDefault(menu) | ||
| menu.setActiveMenu('style', true) | ||
| loadUser(menu, personalJsonc) | ||
| assertEqual(menu.activeMenu, 'style', 'a pending route does not pull the user out of a menu they opened') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'personal' }) | ||
| loadDefault(menu) | ||
| menu.setActiveMenu('style', true) | ||
| menu.goBack() | ||
| loadUser(menu, personalJsonc) | ||
| assertEqual(menu.activeMenu, 'root', 'a pending route does not replace the root the user navigated back to') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'personal' }) | ||
| loadDefault(menu) | ||
| menu.setFilter('not') | ||
| menu.setFilter('') | ||
| loadUser(menu, personalJsonc) | ||
| assertEqual(menu.activeMenu, 'root', 'a pending route does not open after the user typed into the menu') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'system' }) | ||
| menu.close() | ||
| loadDefault(menu) | ||
| noUserFile(menu) | ||
| assertEqual(menu.opened, false, 'a route summoned and dismissed during startup stays closed') | ||
|
|
||
| menu = startMenu() | ||
| summon(menu, { menu: 'system' }) | ||
| summon(menu, { mode: 'select', prompt: 'Pick', options: ['a', 'b'] }) | ||
| loadDefault(menu) | ||
| noUserFile(menu) | ||
| assertEqual(menu.mode, 'select', 'a select prompt that replaced an early route summon is not replaced by it') | ||
|
|
||
| menu = startMenu() | ||
| loadDefault(menu) | ||
| noUserFile(menu) | ||
| summon(menu, { menu: 'system' }) | ||
| assertEqual(menu.activeMenu, 'system', 'a summon after startup opens its route directly') | ||
| menu.setActiveMenu('style', true) | ||
| loadDefault(menu) | ||
| assertEqual(menu.activeMenu, 'style', 'a later reload leaves the menu where the user navigated') | ||
| JS |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaying a pending submenu runs the guard batch twice.
rebuildItemsFromSources()already callsevaluateGuards()before this line. CallingopenRoute(pending)then reachesopenExistingMenu(), which calls it again. The first batch is still running, so the second call setsguardsPendingand queues another full batch.This adds avoidable work during startup. Skip the second evaluation when replaying a route from this rebuild.