From 21ffa178c9c03f819753a1395322c722313d54cb Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Tue, 17 Nov 2026 13:06:03 +0700 Subject: [PATCH 1/2] fix: take focus for the full menu bar option on macOS 14 and later activate(ignoringOtherApps:) is ignored under cooperative activation, so the option switched to a regular app but never became the active one and the front app's menus kept the bar. Use activate() from macOS 14, keep the old call before it. The call sits behind a small seam so a unit test covers both paths. --- .../ExpandCollapseActionTests.swift | 29 +++++++++++++++ .../StatusBar/ExpandCollapseAction.swift | 36 +++++++++++++++++++ .../StatusBar/StatusBarController.swift | 5 ++- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/HiddenBarTests/ExpandCollapseActionTests.swift b/HiddenBarTests/ExpandCollapseActionTests.swift index a9425a36..19306cd2 100644 --- a/HiddenBarTests/ExpandCollapseActionTests.swift +++ b/HiddenBarTests/ExpandCollapseActionTests.swift @@ -101,3 +101,32 @@ final class ExpandCollapseActionTests: XCTestCase { } } } + +// The full menu bar option must take focus: activate(ignoringOtherApps:) is +// ignored from macOS 14, so there the cooperative call is the one to make (#142). +final class FullBarActivationTests: XCTestCase { + + private final class SpyApp: FullBarActivating { + var calls: [String] = [] + func activateIgnoringOtherApps() { calls.append("ignoringOtherApps") } + func activateCooperatively() { calls.append("cooperative") } + } + + func testMacOS14AndLaterUsesTheCooperativeCall() { + let app = SpyApp() + FullBarActivation.activate(app, cooperative: true) + XCTAssertEqual(app.calls, ["cooperative"]) + } + + func testOlderMacOSKeepsTheIgnoringOtherAppsCall() { + let app = SpyApp() + FullBarActivation.activate(app, cooperative: false) + XCTAssertEqual(app.calls, ["ignoringOtherApps"]) + } + + func testDefaultFollowsTheRunningOS() { + let app = SpyApp() + FullBarActivation.activate(app) + XCTAssertEqual(app.calls, [FullBarActivation.usesCooperativeActivation ? "cooperative" : "ignoringOtherApps"]) + } +} diff --git a/hidden/Features/StatusBar/ExpandCollapseAction.swift b/hidden/Features/StatusBar/ExpandCollapseAction.swift index 23ba2bb9..4d9390ff 100644 --- a/hidden/Features/StatusBar/ExpandCollapseAction.swift +++ b/hidden/Features/StatusBar/ExpandCollapseAction.swift @@ -57,3 +57,39 @@ enum ExpandCollapseActionResolver { } } } + +// What the full menu bar option needs from the app to make it the active one. +// A seam so the choice of API is unit-testable without activating a real app. +protocol FullBarActivating { + func activateIgnoringOtherApps() + func activateCooperatively() +} + +extension NSApplication: FullBarActivating { + func activateIgnoringOtherApps() { + activate(ignoringOtherApps: true) + } + + func activateCooperatively() { + if #available(macOS 14.0, *) { + activate() + } + } +} + +enum FullBarActivation { + // From macOS 14 activate(ignoringOtherApps:) is ignored (cooperative + // activation), so the full menu bar option never took focus and the front + // app's menus kept the bar (#142). Older systems keep the old call. + static var usesCooperativeActivation: Bool { + return ProcessInfo.processInfo.isOperatingSystemAtLeast(OperatingSystemVersion(majorVersion: 14, minorVersion: 0, patchVersion: 0)) + } + + static func activate(_ app: FullBarActivating, cooperative: Bool = usesCooperativeActivation) { + if cooperative { + app.activateCooperatively() + } else { + app.activateIgnoringOtherApps() + } + } +} diff --git a/hidden/Features/StatusBar/StatusBarController.swift b/hidden/Features/StatusBar/StatusBarController.swift index e3619c32..132b3919 100644 --- a/hidden/Features/StatusBar/StatusBarController.swift +++ b/hidden/Features/StatusBar/StatusBarController.swift @@ -498,8 +498,7 @@ class StatusBarController: MenuBarItemProvider { if activatingApp && wantsFullBar { NSApp.setActivationPolicy(.regular) - NSApp.activate(ignoringOtherApps: true) - + FullBarActivation.activate(NSApp) } #if HIDDENBAR_NATIVE_VISIBILITY presentationController?.barExpanded() @@ -518,7 +517,7 @@ class StatusBarController: MenuBarItemProvider { let keyWindow = NSApp.isActive ? NSApp.keyWindow : nil NSApp.setActivationPolicy(policy) if wantsRegular { - NSApp.activate(ignoringOtherApps: true) + FullBarActivation.activate(NSApp) } else if let keyWindow { // Dropping to .accessory deactivates the app, so bring back the window in use. DispatchQueue.main.async { keyWindow.bringToFront() } From 5eee1f8ce0f231ac5183c709b6a7c9f0315b94b5 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Tue, 17 Nov 2026 13:21:33 +0700 Subject: [PATCH 2/2] fix: take the active state from the front app on macOS 14 and later A plain activate() is ignored too under cooperative activation: on macOS 27.0.1 the full menu bar option stayed inactive after the arrow click. The front app is now named as the one to take the active state from, with activate() as the fallback. Checked in a macOS 27.0.1 VM: the arrow click makes Hidden Bar the front app, in windowed and full screen Safari, and collapse hands focus back. --- CHANGELOG.md | 1 + .../ExpandCollapseActionTests.swift | 10 ++++----- .../StatusBar/ExpandCollapseAction.swift | 22 ++++++++++++------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10913971..6570da63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Settings › Advanced: the switch "Show all icons while macOS hides one right of the arrow" is now "Pause hiding while macOS shows Now Playing, Focus and similar items", with a note that Hidden Bar hides nothing while one of them shows. Same stored setting, same behavior ([#446](https://github.com/dwarvesf/hidden/issues/446)). ### Fixed +- macOS 14 and later: "Use the full menu bar on expanding" now takes focus. Hidden Bar became a regular app but never the active one, so the front app's menus kept the bar and the option did nothing, in full screen too. It now takes the active state from the front app, and collapsing hands focus back ([#142](https://github.com/dwarvesf/hidden/issues/142)). - Test runs no longer read or write Hidden Bar's real preferences or act on the installed app. A test host uses its own preferences suite, and skips the "Move to Applications" offer, the App Store migration prompts, Sparkle and the saved arrow positions, so a test run cannot trash or move the installed copy. - macOS 27 (direct build): Little Snitch's icon no longer hides on every collapse. Little Snitch turns Accessibility off for its apps, so Hidden Bar could not see its icon, left it off the list of apps to keep, and macOS hid it wherever it sat. Hidden Bar now keeps an app it cannot see visible, as it does for an app that does not answer. Its position stays unknown, so to hide it, set it to Hidden in Settings › Icons. This likely also covers [#514](https://github.com/dwarvesf/hidden/issues/514), whose app was not identified ([#502](https://github.com/dwarvesf/hidden/issues/502)). - Upgrading from a version before 1.11 (the GitHub builds up to 1.10 or the App Store build) no longer leaves the old "LauncherApplication" login item behind. System Settings › General › Login Items & Extensions lists it inside "Hidden Bar" under Allow in the Background, not as a row of its own, and the old cleanup failed on every launch. Now, with "Open Hidden Bar at login" on, Hidden Bar turns its login item off and on once, which removes the old one. With it off, nothing is touched until you turn it on. If the cleanup fails, the log says once where the row is and how to remove it ([#456](https://github.com/dwarvesf/hidden/issues/456)). diff --git a/HiddenBarTests/ExpandCollapseActionTests.swift b/HiddenBarTests/ExpandCollapseActionTests.swift index 19306cd2..0d79b0a9 100644 --- a/HiddenBarTests/ExpandCollapseActionTests.swift +++ b/HiddenBarTests/ExpandCollapseActionTests.swift @@ -103,19 +103,19 @@ final class ExpandCollapseActionTests: XCTestCase { } // The full menu bar option must take focus: activate(ignoringOtherApps:) is -// ignored from macOS 14, so there the cooperative call is the one to make (#142). +// ignored from macOS 14, so there the active state is taken from the front app (#142). final class FullBarActivationTests: XCTestCase { private final class SpyApp: FullBarActivating { var calls: [String] = [] func activateIgnoringOtherApps() { calls.append("ignoringOtherApps") } - func activateCooperatively() { calls.append("cooperative") } + func activateFromFrontApp() { calls.append("fromFrontApp") } } - func testMacOS14AndLaterUsesTheCooperativeCall() { + func testMacOS14AndLaterTakesTheActiveStateFromTheFrontApp() { let app = SpyApp() FullBarActivation.activate(app, cooperative: true) - XCTAssertEqual(app.calls, ["cooperative"]) + XCTAssertEqual(app.calls, ["fromFrontApp"]) } func testOlderMacOSKeepsTheIgnoringOtherAppsCall() { @@ -127,6 +127,6 @@ final class FullBarActivationTests: XCTestCase { func testDefaultFollowsTheRunningOS() { let app = SpyApp() FullBarActivation.activate(app) - XCTAssertEqual(app.calls, [FullBarActivation.usesCooperativeActivation ? "cooperative" : "ignoringOtherApps"]) + XCTAssertEqual(app.calls, [FullBarActivation.usesCooperativeActivation ? "fromFrontApp" : "ignoringOtherApps"]) } } diff --git a/hidden/Features/StatusBar/ExpandCollapseAction.swift b/hidden/Features/StatusBar/ExpandCollapseAction.swift index 4d9390ff..f38d5363 100644 --- a/hidden/Features/StatusBar/ExpandCollapseAction.swift +++ b/hidden/Features/StatusBar/ExpandCollapseAction.swift @@ -62,7 +62,7 @@ enum ExpandCollapseActionResolver { // A seam so the choice of API is unit-testable without activating a real app. protocol FullBarActivating { func activateIgnoringOtherApps() - func activateCooperatively() + func activateFromFrontApp() } extension NSApplication: FullBarActivating { @@ -70,24 +70,30 @@ extension NSApplication: FullBarActivating { activate(ignoringOtherApps: true) } - func activateCooperatively() { - if #available(macOS 14.0, *) { - activate() + // From macOS 14 a plain activate() is also ignored when another app is + // frontmost, so name the front app as the one to take the active state from. + func activateFromFrontApp() { + guard #available(macOS 14.0, *) else { return } + if let front = NSWorkspace.shared.frontmostApplication, front != NSRunningApplication.current, + NSRunningApplication.current.activate(from: front, options: []) { + return } + activate() } } enum FullBarActivation { - // From macOS 14 activate(ignoringOtherApps:) is ignored (cooperative - // activation), so the full menu bar option never took focus and the front - // app's menus kept the bar (#142). Older systems keep the old call. + // From macOS 14 activate(ignoringOtherApps:) and a plain activate() are + // ignored (cooperative activation), so the full menu bar option never took + // focus and the front app's menus kept the bar (#142). Older systems keep + // the old call. static var usesCooperativeActivation: Bool { return ProcessInfo.processInfo.isOperatingSystemAtLeast(OperatingSystemVersion(majorVersion: 14, minorVersion: 0, patchVersion: 0)) } static func activate(_ app: FullBarActivating, cooperative: Bool = usesCooperativeActivation) { if cooperative { - app.activateCooperatively() + app.activateFromFrontApp() } else { app.activateIgnoringOtherApps() }