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 a9425a36..0d79b0a9 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 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 activateFromFrontApp() { calls.append("fromFrontApp") } + } + + func testMacOS14AndLaterTakesTheActiveStateFromTheFrontApp() { + let app = SpyApp() + FullBarActivation.activate(app, cooperative: true) + XCTAssertEqual(app.calls, ["fromFrontApp"]) + } + + 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 ? "fromFrontApp" : "ignoringOtherApps"]) + } +} diff --git a/hidden/Features/StatusBar/ExpandCollapseAction.swift b/hidden/Features/StatusBar/ExpandCollapseAction.swift index 23ba2bb9..f38d5363 100644 --- a/hidden/Features/StatusBar/ExpandCollapseAction.swift +++ b/hidden/Features/StatusBar/ExpandCollapseAction.swift @@ -57,3 +57,45 @@ 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 activateFromFrontApp() +} + +extension NSApplication: FullBarActivating { + func activateIgnoringOtherApps() { + activate(ignoringOtherApps: true) + } + + // 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:) 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.activateFromFrontApp() + } 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() }