diff --git a/AX.swift b/AX.swift index d4efdc4..d2cd19d 100644 --- a/AX.swift +++ b/AX.swift @@ -88,6 +88,15 @@ func menuBarCanShow(running: URL?, resolved: URL?) -> Bool { return running.standardizedFileURL.path.hasPrefix("/Applications/") } +/// Bundles the allow-list keeps on the bar, before the always-hidden list. An item created while its app is off the list is +/// never placed and never shows up in AX (relaunch repro 2026-11-04), so we would never see it to allow it: known menu bar +/// apps (`knownApps`) are allowed ahead, running or not, unless seen left of us. +// shortcut: knownApps skips com.apple.* bundles, so a relaunched Apple menu extra still needs our restart; add them if reported. +func visibleBundles(hidden: Bool, right: Set, left: Set, parked: Set, known: Set, + denied: Set) -> Set { + hidden ? right.union(parked.union(known).subtracting(denied)) : right.union(left).union(parked).union(known) +} + /// Bundles kept on the bar while hiding. The allow-list is per bundle, so an app with items on both sides of our icon is /// shown whole, or hidden whole with Settings › "Apps on both sides of the icon" = Hide (`splitHides`). func rightOfUs(_ right: Set, _ left: Set, splitHides: Bool) -> Set { diff --git a/CHANGELOG.md b/CHANGELOG.md index 49b0b2e..1a802e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.6.1] - 2026-11-04 + +### Fixed +- A menu bar app that was quit and opened again while SmartHiddenBar was hiding stayed hidden until SmartHiddenBar itself restarted, even right of the icon or while items were shown. macOS never lists an icon created while its app is off the allow-list, so SmartHiddenBar never saw it to allow it. Menu bar apps it already knows are now allowed ahead of time, running or not, unless they sit left of the icon. An app that sat left of the icon before SmartHiddenBar last started can show for a few seconds after it opens, until the next check hides it. + +### Added +- The log names apps whose menu bar items appear or leave, with their position, so a missing icon can be traced. + ## [1.6.0] - 2026-11-04 ### Added diff --git a/CLAUDE.md b/CLAUDE.md index 8786ec9..01e340d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -8,7 +8,7 @@ macOS 27 menu bar app: hides every status item left of its own icon via MenuBarA - Signing: `build.sh` uses a stable local code-signing identity (the name set in `build.sh`; ad-hoc fallback) so the Accessibility grant survives rebuilds. Ad-hoc signing changes the cdhash every build and re-prompts. Reset a broken grant with `tccutil reset Accessibility com.roypadina.SmartHiddenBar` (Screen Recording: `tccutil reset ScreenCapture com.roypadina.SmartHiddenBar`). - Log: `~/Library/Logs/SmartHiddenBar.log`. Defaults domain `com.roypadina.SmartHiddenBar`. - Git: public repo `roypadina/SmartHiddenBar`, pushed over SSH. Commit with the repo-level GitHub noreply address (GitHub email privacy rejects a private address). Commit + push after each working fix. -- `probe/` (gitignored) holds two trivial status-item apps for isolating menu bar issues. To test allow-list behaviour, copy a probe to `/Applications` with a fresh bundle id: MenuBarAgent matches allow-listed bundle ids only for apps running inside `/Applications` (a helper nested in an `/Applications` app works; `~/Library/Application Support` never does, even as the only registered copy; allowing the parent app's id does not help a nested helper — probe matrix 2026-10-30) and only when LaunchServices resolves the id to that copy, so a probe run from `probe/build` is never "allowed" (this misled the 1.1.3 release-once fix). `menuBarCanShow` (AX.swift) encodes the rule and `applyHide` logs violators. Prove visibility by AX hit-test at the item's frame (must return the probe's pid) or a screenshot (`screencapture -x -R0,0,,30`: the session terminal has Screen Recording but no Accessibility); AX frames stay on-bar for restriction-hidden items. A standalone allow-list harness (MenuBarClientCore activate → screenshot → invalidate) tests the rule without SmartHiddenBar running. New probes always appear leftmost (`NSStatusItem Preferred Position` is ignored on macOS 27), so placing one right of our icon needs Roy's ⌘-drag. Apps with System Settings → Menu Bar → "Allow in the Menu Bar" off are parked by macOS at creation, whatever our list says. +- `probe/` (gitignored) holds two trivial status-item apps for isolating menu bar issues. To test allow-list behaviour, copy a probe to `/Applications` with a fresh bundle id: MenuBarAgent matches allow-listed bundle ids only for apps running inside `/Applications` (a helper nested in an `/Applications` app works; `~/Library/Application Support` never does, even as the only registered copy; allowing the parent app's id does not help a nested helper — probe matrix 2026-10-30) and only when LaunchServices resolves the id to that copy, so a probe run from `probe/build` is never "allowed" (this misled the 1.1.3 release-once fix). `menuBarCanShow` (AX.swift) encodes the rule and `applyHide` logs violators. Prove visibility by AX hit-test at the item's frame (must return the probe's pid) or a screenshot (`screencapture -x -R0,0,,30`: the session terminal has Screen Recording but no Accessibility); AX frames stay on-bar for restriction-hidden items. A standalone allow-list harness (MenuBarClientCore activate → screenshot → invalidate) tests the rule without SmartHiddenBar running. New probes always appear leftmost (`NSStatusItem Preferred Position` is ignored on macOS 27), so placing one right of our icon needs Roy's ⌘-drag. Apps with System Settings → Menu Bar → "Allow in the Menu Bar" off are parked by macOS at creation, whatever our list says. An item created while its bundle is off the allow-list never shows up in AX at all (not even parked), so `knownApps` are allowed ahead, running or not, unless denied (`visibleBundles`, AX.swift; relaunch bug 1.6.1); the log line `apps: +["id x=…"] -["id"]` names items that appear/leave. Ghostex sessions have no Screen Recording (`screencapture`: "could not create image from rect") — use that log line as the oracle there. - Left/right is decided only on a settled read (`settledRead`, AX.swift): our own frame is sampled from 0.5 s before the AX walk to its end; any move = retry (3×, 0.3 s), then keep the list. Other apps' AX frames trail a re-layout (iStat Menus, Slack), so a read during or right after items appear/vanish/resize mislabels neighbours (issue #7 follow-up, 1.4.1). Stress test: a probe whose title flips width on a flag file, placed right of a second probe right of our icon. - Self-check (pure logic, no app): `swiftc -target arm64-apple-macos27.0 AX.swift tests/main.swift -o build/selfcheck && build/selfcheck`. Not in CI (the runner can't run a macOS 27 binary). - In zsh, `log` is a builtin: use `/usr/bin/log stream ...`. diff --git a/Hiding.swift b/Hiding.swift index 07139c3..f56bbd3 100644 --- a/Hiding.swift +++ b/Hiding.swift @@ -101,7 +101,13 @@ extension Lister { } } DispatchQueue.main.async { - let changed = Set(all.compactMap(\.app.bundleIdentifier)) != Set(self.last.compactMap(\.app.bundleIdentifier)) + let before = Set(self.last.compactMap(\.app.bundleIdentifier)), now = Set(all.compactMap(\.app.bundleIdentifier)) + let changed = now != before + if changed, !self.last.isEmpty { // names apps that appear/leave, so "icon never came back" reports are diagnosable + let added = all.filter { !before.contains($0.app.bundleIdentifier ?? "") } + .map { "\($0.app.bundleIdentifier ?? "?") \(onBar($0.y) ? "x=\(Int($0.x))" : "parked")" } + log("apps: +\(added) -\(before.subtracting(now).sorted())") + } self.last = all self.lastMe = me self.noteNewApps(all) @@ -111,8 +117,8 @@ extension Lister { } } - /// Hidden: allow = us + system owners + every bundle with an item right of our midX + parked bundles never seen left of us. - /// Shown: allow = every bundle on the bar. Either way minus the always-hidden list (shown + empty list = no restriction). + /// Hidden: allow = us + system owners + every bundle with an item right of our midX + parked or known bundles never seen + /// left of us (`visibleBundles`). Shown: allow = every bundle on the bar + known ones. Either way minus the always-hidden list (shown + empty list = no restriction). /// Several displays: positions are compared as distance from their own display's right edge (`fromRight`). func applyHide(_ all: [Extra], _ me: CGRect?) { let always = alwaysHidden @@ -153,7 +159,8 @@ extension Lister { let own = Bundle.main.bundleIdentifier ?? "com.roypadina.SmartHiddenBar" // System owners too: phase 1 never hides macOS's own items (Now Playing may be bundle-owned, not a system id). let system = ["com.apple.MenuBarAgent", "com.apple.controlcenter", "com.apple.systemuiserver"] - let visible = hidden ? right.union(parked.subtracting(denied)) : right.union(left).union(parked) + let known = Set(UserDefaults.standard.stringArray(forKey: "knownApps") ?? []) + let visible = visibleBundles(hidden: hidden, right: right, left: left, parked: parked, known: known, denied: denied) let allow = Set([own] + system).union(visible.subtracting(always)).sorted() // Allowed but MenuBarAgent can't match it (outside /Applications, or LaunchServices picks another copy): it stays // off the bar while we hide, wherever it sits, and its leaving shifts our icon. Say so once per process. diff --git a/Info.plist b/Info.plist index d77971d..dcf5213 100644 --- a/Info.plist +++ b/Info.plist @@ -13,9 +13,9 @@ CFBundleIconFile AppIcon CFBundleShortVersionString - 1.6.0 + 1.6.1 CFBundleVersion - 16 + 17 LSMinimumSystemVersion 27.0 NSHumanReadableCopyright diff --git a/README.md b/README.md index 7c0d3ac..58a49fb 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ Settings (sections: General, Click, Shortcuts, Icon Bar, Permissions, Always Hid macOS 27's `MenuBarAgent` has a private "assessment mode" allow-list (`MenuBarClientCore`): while a process holds it, the bar shows only the allowed apps plus system items. SmartHiddenBar allows -itself, the system items, and every app whose item sits to the right of its icon; apps left of the icon are denied. Hiding is +itself, the system items, every app whose item sits to the right of its icon, and apps it has seen before that never sat left of it (so a reopened app's icon comes back); apps left of the icon are denied. Hiding is therefore **per app, not per item** (the API takes app ids only; there is no per-item call). Nothing is moved or modified: quitting SmartHiddenBar (or "Show Items") releases the allow-list and the full bar comes back. Item lists and menus are read, and menu items pressed, through the Accessibility API (`AXExtrasMenuBar`). Mirroring copies the real menu, closes it, and replays your pick on the real one. diff --git a/tests/main.swift b/tests/main.swift index bef11ba..f2be706 100644 --- a/tests/main.swift +++ b/tests/main.swift @@ -56,4 +56,13 @@ let seenLeft: Set = ["com.bjango.istatmenus.status", "ru.keepcoder.Telegram"] precondition(rightOfUs(seenRight, seenLeft, splitHides: false) == seenRight, "split app shown: default, as before") precondition(rightOfUs(seenRight, seenLeft, splitHides: true) == ["HamedElfayome.Claude-Usage"], "split app hidden") +// Relaunch repro 2026-11-04: Agents Monitor quit and relaunched while hiding never showed up in the walk (an item created +// while its app is off the list is not placed, so AX never lists it): known apps are allowed though absent from the walk. +let known: Set = ["com.roy.agentsmonitor", "com.padina.vaultbar"] +precondition(visibleBundles(hidden: true, right: ["com.roy.meetalert"], left: [], parked: [], known: known, + denied: ["com.padina.vaultbar"]) == ["com.roy.meetalert", "com.roy.agentsmonitor"], + "hidden: relaunched known app allowed ahead, one seen left of us still denied") +precondition(visibleBundles(hidden: false, right: [], left: [], parked: [], known: known, denied: ["com.padina.vaultbar"]) + == known, "shown: every known app, denied ones too") + print("selfcheck: ok")