Skip to content

feat(foundation): shortcut recorder, hotkey registry, app catalog - #497

Merged
tieubao merged 2 commits into
developfrom
feat/next-features-foundation
Nov 15, 2026
Merged

tieubao merged 2 commits into
developfrom
feat/next-features-foundation

Conversation

@tieubao

@tieubao tieubao commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

What

The shared foundation for the next-features work (SG-01): three pieces other features plug into, plus the debug sender and a merge setting.

  • ShortcutRecorderRow (hidden/Features/Settings/): the inline recorder in PreferencesViewController (btnShortcut, btnClear, register/unregister, updateGlobalShortcut, updateModiferFlags, and the keyDown/flagsChanged forwarding in PreferencesWindowController) is now one control bound to a Data pref key. The "Keyboard shortcut" row uses it. A small orange triangle (tooltip "Also used by ...") appears when the chosen combination equals another Hidden Bar shortcut; with no clash the row is unchanged.
  • HotKeyRegistry (hidden/Models/): AppDelegate's single hotKey is a registry keyed by pref key. register(key:title:handler:), rebinds when the stored shortcut changes (it re-reads on .prefsChanged), unregister(key:), reload(), clashingTitle(for:excluding:). The type never imports the hot key library; HotKeyRegistry.shared (in AppDelegate.swift) supplies the Carbon binding.
  • MenuBarItemCatalog (direct build only, #if HIDDENBAR_NATIVE_VISIBILITY): menu-bar apps from the engine's reads of an unrestricted bar plus the pinned-sections table. Entry: bundle id, name, icon, section, firstSeen, isRunning. Posts .menuBarCatalogChanged and exposes arrivals. No new read, timer, permission or entitlement. The pure merge and diff logic is MenuBarCatalogState (compiled into HiddenBarTests).
  • dump-inventory debug hook and scripts/hb-cmd, documented in docs/RUNBOOK.md (Behavioral verification).
  • .gitattributes: hidden/*.lproj/Localizable.strings merge=union.

Why

F1, F2, F3 and F4 each need a shortcut recorder, a way to register a global shortcut, or a list of menu-bar apps, and the contract forbids copying the inline recorder. Building these once keeps every feature on one code path and gives the wave verifier a scripted way to drive Debug builds.

Decisions

  1. Registry rebinding is driven by the pref, not by the recorder. The recorder writes the key and posts .prefsChanged; the registry rebinds. So an imported preference set, a clear and a record all take one path, and AppDelegate.applyImportedPreferences just calls hotKeys.reload().
  2. Local key monitor instead of window-controller forwarding. While listening, the recorder installs an NSEvent local monitor (this app's events only, no Input Monitoring) and swallows the keys, so PreferencesWindowController loses its keyDown/flagsChanged overrides. performKeyEquivalent keeps its "do not close on Cmd+W while recording" guard through ShortcutRecorderRow.isRecording. Any pane can host a recorder.
  3. Three small recorder fixes that fall out of the extraction, none visible in the snapshots: a bare letter is refused and the old shortcut stays (before, it cleared the stored key but still registered the letter for the session); letting go of every modifier with no key cancels without clearing the stored shortcut (before, it cleared it); Escape cancels (before, it was taken as a bare key and cleared the shortcut). The recorder also stops on window resign.
  4. Clearing removes the pref key (removeObject) instead of writing the JSON null the old setter wrote. Preferences.globalKey reads nil either way.
  5. Clash warning is an icon with a tooltip and an accessibility label, not text, so the row keeps its layout. Titles come from register(key:title:); the expand/collapse shortcut registers as "Show or hide icons". Two new strings ("Also used by %@", "Show or hide icons") are in all 13 Localizable.strings with English text.
  6. First run seeds the catalog silently. The first read after the catalog starts persisting records every app with firstSeen = now and reports no arrivals, so upgrading never announces the apps the user already has. After that, an app read for the first time is an arrival. Table-only apps are recorded without being arrivals. firstSeen lives in menuBarCatalogFirstSeen (internal key, not in the import whitelist, per the contract).
  7. macOS's own extras (com.apple.controlcenter) are not cataloged: not an app to list, search or announce. The Menu Bar Apps tab still shows them as "macOS extras".
  8. arrivals is the diff of the latest read (empty after a read that finds none). A listener that needs every arrival reads it from the .menuBarCatalogChanged userInfo (MenuBarItemCatalog.arrivalsKey).
  9. Catalog refresh: on the engine's unrestricted reads (NativeVisibilityEngine.onUnrestrictedRead, called only from the read path, never from a held restriction) and on NSWorkspace and AgentLaunchNotifications launches and quits (these only change isRunning). No timer.
  10. hb-cmd extras: --timeout (default 15 s) and --dry-run (post nothing, still run the wait, to test parsing and the timeout path without an app). The wait counts only a file newer than the call, so a stale answer does not pass.
  11. dump-inventory answers out with the catalog JSON instead of the state dump; on the App Store build it writes {"available": false, ...} so a caller does not hang.

Tests

bash scripts/test.sh --dd ~/.cache/hidden-bar/dd-foundation: exit 0.

Scheme Passed Failed New
Direct (Hidden Bar, Debug-Direct) 371 0 50
App Store (Hidden Bar App Store, Debug) 244 0 27

New tests: HotKeyRegistryTests (13), GlobalKeybindPreferencesTests (2), MenuBarCatalogStateTests (10), UnrestrictedReadHookTests (2), ShortcutRecorderRowTests (11, direct), MenuBarItemCatalogTests (12, direct). SettingsWindowTests.test_shortcutRecorder_readsAndClearsGlobalKey now clears through the recorder. plutil -lint hidden/*.lproj/*.strings passes.

Hosted tests flake under heavy load: on a Mac with a load average of 50 to 90, two full runs ended with "Hidden Bar (pid) encountered an error (The test runner exited with code 0 before establishing connection)" for seven extra runners (every test that ran passed). The app's single-instance guard makes extra parallel host clones quit. The same command passed on the next try, and the unchanged develop passed 4 of 4 here. Not caused by this change; CI has no such load.

Negative control

  • Production files reverted to origin/develop, new production files moved aside (scripts/test.sh --scheme direct): exit 1, BUILD FAILED (Build input files cannot be found for the new files in the project). Nothing the new tests cover exists on develop.
  • One mutant at a time on the committed code (direct scheme, exit 1 each):
Mutant Failing tests
registry ignores .prefsChanged HotKeyRegistryTests.test_changedShortcutReplacesTheOldBinding, test_clearedShortcutIsUnbound, test_prefsChangedBindsAShortcutSetLater; ShortcutRecorderRowTests.test_typedCombinationIsStoredAndGoesLive
a bare letter is acceptable GlobalKeybindPreferencesTests.test_isAcceptableNeedsAModifierOrAFunctionKey; ShortcutRecorderRowTests.test_bareLetterIsRefused
recorder reports no clash ShortcutRecorderRowTests.test_clashWithAnotherShortcutShowsAWarning
clear keeps the stored pref SettingsWindowTests.test_shortcutRecorder_readsAndClearsGlobalKey; ShortcutRecorderRowTests.test_clearRemovesTheStoredShortcut
first run announces every app MenuBarCatalogStateTests.test_firstRunSeedsEveryAppWithoutArrivals; MenuBarItemCatalogTests.test_firstReadListsEveryAppAndAnnouncesNone, test_upgradeDoesNotAnnounceExistingApps, test_launchesAndQuitsUpdateIsRunning, test_pinnedTableFeedsSectionsAndEdits
catalog does not persist firstSeen MenuBarItemCatalogTests.test_firstSeenIsPersistedAcrossLaunches
engine never calls the read hook UnrestrictedReadHookTests.testACollapseReadReachesTheHook, testAHeldRestrictionReportsNoRead
system extras cataloged MenuBarCatalogStateTests.test_systemExtrasAreLeftOut; MenuBarItemCatalogTests.test_systemExtrasAreNotListed

Each mutant was restored with git checkout -- <file>; the working tree was clean afterwards.

Snapshots

Debug-Direct binary run with -settingsSnapshotDir, 26 PNGs (13 states, light and dark), compared pixel by pixel with a build of origin/develop:

  • Identical: direct-about, direct-advanced, direct-appearance, direct-menubarapps-empty, direct-menubarapps-off (light and dark each).
  • direct-general-<light|dark>: 1931 / 1923 pixels differ, all inside x 343-932, y 316-418, the menu-bar preview strip (its live clock "Mon 01:33" against "01:38"); the Keyboard shortcut row (y about 780) is pixel-identical, the layout is the same.
  • Same preview-strip clock only: direct-status-* (four states), direct-preview-macos26/27-alwayshidden. direct-menubarapps-on differs in 9 (dark) and 1214 (light) pixels in a small box at the left of the first rows (x 64-99, where the app icons sit); this change does not touch that pane.

No Screen Recording, Input Monitoring or new entitlement; the app was not launched live and no key or pointer input was sent.

@tieubao
tieubao force-pushed the feat/next-features-foundation branch from a937c46 to eb72644 Compare November 15, 2026 19:09
Shared pieces the next-features work builds on.

- ShortcutRecorderRow: the inline recorder in General, extracted into one
  control bound to a Data pref key, with a clash warning against the other
  Hidden Bar shortcuts. A bare letter is refused, Escape cancels, releasing
  every modifier cancels without clearing the stored shortcut.
- HotKeyRegistry: AppDelegate's single hotKey becomes a registry keyed by pref
  key; register(key:title:handler:) and it rebinds on prefsChanged.
- MenuBarItemCatalog (direct build): menu-bar apps from the engine's unrestricted
  reads plus the pinned-sections table, with first-seen times persisted so only
  apps new since then are arrivals. Pure merge logic is MenuBarCatalogState.
- dump-inventory debug hook, scripts/hb-cmd sender, RUNBOOK section.
- .gitattributes: merge=union for the Localizable.strings files.
The engine handed the catalog its layout after filling in apps that only started, so ordinary apps with no menu-bar icon became entries and arrivals. The hook now runs before that fill-in. menuBarCatalogFirstSeen is declared in UserDefaults.Key (internal, not importable). HotKeyRegistry removes its observer from the injected center.
@tieubao
tieubao force-pushed the feat/next-features-foundation branch from eb72644 to b0ae2d1 Compare November 15, 2026 19:16
@tieubao
tieubao merged commit 70f6a82 into develop Nov 15, 2026
3 checks passed
@tieubao
tieubao deleted the feat/next-features-foundation branch November 16, 2026 01:33
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.

1 participant