Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions HiddenBarTests/ExpandCollapseActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,41 @@ final class ExpandCollapseActionTests: XCTestCase {
XCTAssertEqual(ExpandCollapseActionResolver.action(eventType: .otherMouseUp, optionPressed: false), .toggleSeparators)
}
}

final class FullBarActivationTests: XCTestCase {

private func run(isMacOS14OrLater: Bool, stillWanted: Bool) -> [String] {
var log: [String] = []
var pending: [() -> Void] = []
FullBarActivation.switchToRegularAndActivate(
isMacOS14OrLater: isMacOS14OrLater,
setPolicy: { log.append("policy:\($0 == .regular ? "regular" : "other")") },
deferToNextTurn: { pending.append($0) },
stillWanted: { stillWanted },
activate: { log.append("activate:\($0)") }
)
log.append("turn-boundary")
pending.forEach { $0() }
return log
}

func testPolicyChangesBeforeTheTurnAndActivationComesAfter() {
XCTAssertEqual(run(isMacOS14OrLater: true, stillWanted: true),
["policy:regular", "turn-boundary", "activate:cooperative"])
}

func testMacOS13KeepsTheLegacyCall() {
XCTAssertEqual(run(isMacOS14OrLater: false, stillWanted: true),
["policy:regular", "turn-boundary", "activate:legacy"])
}

func testCollapsedBeforeTheNextTurnSkipsActivation() {
XCTAssertEqual(run(isMacOS14OrLater: true, stillWanted: false),
["policy:regular", "turn-boundary"])
}

func testRequestKindPerOSVersion() {
XCTAssertEqual(FullBarActivation.request(isMacOS14OrLater: true), .cooperative)
XCTAssertEqual(FullBarActivation.request(isMacOS14OrLater: false), .legacy)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions docs/implementation-notes/shift-click-full-bar.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ dump-state `useFullStatusBarOnExpand` read false at every step.
- The same path serves the stored "use the full menu bar on expand" setting, so that setting likely shows the same on macOS 27; not run here.
- How step f was told apart from noise: other Debug Hidden Bar builds (test hosts of a parallel session) also answer the broadcast hook and wrote the same dump file, which gave two false triggers. Only this build's dump has `fullBarThisExpansion`, so the trigger was that key being true; the capture retried the dump until that key was present.

## Fix attempt (#496): activation on the next runloop turn

| Click (real, by Han) | Trigger | Frontmost app, sampled +0.12 s to +5.5 s | End state (dump-state / NSRunningApplication) | Result | Crops |
|---|---|---|---|---|---|
| Shift-click, setting off (01:49:40) | `fullBarThisExpansion` true | Orca (pid 17272) at all 30 samples | expanded, regular / regular, `isActive` false | FAIL: Hidden Bar never frontmost, app menu not shown | `fix-shift-0.3s-left.png`, `fix-shift-1s-left.png`, `fix-shift-2s-left.png`, `fix-shift-1s-right.png` |
| Plain click, `full-menu-bar on` (01:50:39) | state expanded | Orca (pid 17272) at all 30 samples | expanded, regular / regular, `isActive` false | FAIL: same; the stored setting fails the same way | `fix-plain-0.3s-left.png`, `fix-plain-1s-left.png`, `fix-plain-2s-left.png`, `fix-plain-1s-right.png` |

- Build: a local merge of `origin/develop` (`f8f2726`) and `fix/full-bar-activation` (`027be9b`), Debug-Direct, Developer ID signed, from /Applications (pid 25611); the branch had no Debug hooks of its own. The installed v1.12.0 was moved aside and back: CDHash identical, login items identical, prefs identical after a re-import (the `full-menu-bar` hook writes the stored setting).
- Trigger trusted only this pid (frontmost) or a state the poll read from this build; no other Hidden Bar process ran at either trigger. The frontmost app was sampled with `lsappinfo front` in a loop meant for every 0.1 s; real spacing was about 0.17 s, 30 samples over 5.5 s. The left crops at +0.3, +1 and +2 s are byte-identical per click (Orca's menus).
- So deferring `NSApp.activate()` one runloop turn after `setActivationPolicy(.regular)` does not make Hidden Bar active on macOS 27 from a status item click, Shift or plain.

## Not proven here

- The app menu in the menu bar after a Shift-click: not seen on macOS 27 (finding above). Shift detection itself is proven on screen by step f (`fullBarThisExpansion` true after a real click).
Expand Down
42 changes: 42 additions & 0 deletions hidden/Features/StatusBar/ExpandCollapseAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,45 @@ enum ExpandCollapseActionResolver {
}
}
}

// Switching to .regular and activating in the same runloop turn does not make the
// app active on macOS 14+, where activation is a cooperative request and
// activate(ignoringOtherApps:) is deprecated and ignored. The full menu bar needs
// Hidden Bar frontmost, so the request goes out on the next turn, after the policy
// change has registered, and is dropped if the bar collapsed in the meantime.
enum FullBarActivation {
enum Request: Equatable {
case cooperative
case legacy
}

static func request(isMacOS14OrLater: Bool) -> Request {
return isMacOS14OrLater ? .cooperative : .legacy
}

static func switchToRegularAndActivate(
isMacOS14OrLater: Bool = ProcessInfo.processInfo.isOperatingSystemAtLeast(OperatingSystemVersion(majorVersion: 14, minorVersion: 0, patchVersion: 0)),
setPolicy: (NSApplication.ActivationPolicy) -> Void = { _ = NSApp.setActivationPolicy($0) },
deferToNextTurn: (@escaping () -> Void) -> Void = { DispatchQueue.main.async(execute: $0) },
stillWanted: @escaping () -> Bool,
activate: @escaping (Request) -> Void = FullBarActivation.perform
) {
setPolicy(.regular)
let request = request(isMacOS14OrLater: isMacOS14OrLater)
deferToNextTurn {
guard stillWanted() else { return }
activate(request)
}
}

static func perform(_ request: Request) {
switch request {
case .cooperative:
if #available(macOS 14.0, *) {
NSApp.activate()
}
case .legacy:
NSApp.activate(ignoringOtherApps: true)
}
}
}
7 changes: 4 additions & 3 deletions hidden/Features/StatusBar/StatusBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,10 @@ class StatusBarController: MenuBarItemProvider {
autoCollapseIfNeeded()

if activatingApp && wantsFullBar {
NSApp.setActivationPolicy(.regular)
NSApp.activate(ignoringOtherApps: true)

FullBarActivation.switchToRegularAndActivate(stillWanted: { [weak self] in
guard let self else { return false }
return !self.isCollapsed && self.wantsFullBar
})
}
}

Expand Down