diff --git a/CHANGELOG.md b/CHANGELOG.md index b4a05ea4..e5ae1dc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ - macOS 27 (direct build): a plain notification no longer holds auto-hide for up to 10 minutes. macOS keeps a screen-tall Notification Center window up under a notification, and auto-hide took it for the open panel. It now checks that the panel itself is open (it has Edit Widgets) before waiting ([#524](https://github.com/dwarvesf/hidden/issues/524)). ### Changed -- When auto-hide holds back because of the Settings window, the new-apps prompt, Notification Center, the palette or the pointer sitting in the menu bar, the log now says which, once per expansion. Look for "AutoCollapse: holding for" in Console. +- When auto-hide holds back because of the Settings window, the new-apps prompt, Notification Center, the palette or the pointer sitting in the menu bar, the log now says which, once per expansion. The reason line ("AutoCollapse: holding for ...") is readable in Console; the app behind a popup hold and other details are in the stderr log, which the manual's "Capture a log" shows how to save. The lines for a collapse macOS never answered and for "hiding unavailable" are readable in Console too. ## v1.13.1 (2026-11-18) diff --git a/Hidden Bar.xcodeproj/project.pbxproj b/Hidden Bar.xcodeproj/project.pbxproj index 193686a0..14034c72 100644 --- a/Hidden Bar.xcodeproj/project.pbxproj +++ b/Hidden Bar.xcodeproj/project.pbxproj @@ -90,6 +90,7 @@ 988E6BB58BB0E21724D3421E /* StackView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55F3F11C2608925A0054B881 /* StackView+Extension.swift */; }; 99EA334772E1715B21C424BB /* MenuBarLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 092D9DE26A006349D87B304D /* MenuBarLayout.swift */; }; 9B1765C0B5634CFABD06A916 /* AutoStartTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F013C3E5499B4EA7B816F7A8 /* AutoStartTests.swift */; }; + A9D0DE00000000000000E002 /* AppLogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9D0DE00000000000000E001 /* AppLogTests.swift */; }; 9C79B5D97BC90E0174BC52BE /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6F2F828CAAE82A4D34BDDCBB /* Cocoa.framework */; }; 9CD9B70D63B58C9A7A31481A /* NotchOverflowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE73DB4E0664488997EEB6DE /* NotchOverflowController.swift */; }; 9F3C757469DFAA7965B8380E /* CaptureActivityMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C1A7E52B9D04F6A8E21C0D7 /* CaptureActivityMonitor.swift */; }; @@ -369,6 +370,7 @@ DEFBDF50E5A67397D95D1946 /* UpdateController.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = UpdateController.swift; sourceTree = ""; }; E3BF69BE15B7DE0272612470 /* NotchOverflowMenuBuilderTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = NotchOverflowMenuBuilderTests.swift; sourceTree = ""; }; F013C3E5499B4EA7B816F7A8 /* AutoStartTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoStartTests.swift; sourceTree = ""; }; + A9D0DE00000000000000E001 /* AppLogTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLogTests.swift; sourceTree = ""; }; F248811CF183BD0A4D71C4C6 /* NativeVisibilityEngine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeVisibilityEngine.swift; sourceTree = ""; }; F51314A736131BE28182E378 /* AccessibilityPermission.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AccessibilityPermission.swift; sourceTree = ""; }; FB0B14538BC3AE95D43DE899 /* AccessibilityMenuBarInventory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessibilityMenuBarInventory.swift; sourceTree = ""; }; @@ -560,6 +562,7 @@ 764544B7EDBB41A18087ED6F /* ExpandCollapseActionTests.swift */, A0C0F1E5D3B2470A9C1E2002 /* AutoCollapsePopupGuardTests.swift */, F013C3E5499B4EA7B816F7A8 /* AutoStartTests.swift */, + A9D0DE00000000000000E001 /* AppLogTests.swift */, A27C0DE00000000000000004 /* MacOS27NoticeTests.swift */, CC5FC25336EC320548CF4C87 /* AccessibilityPermissionTests.swift */, 60AFBE8D4C25548192E7D135 /* SettingsModelTests.swift */, @@ -1210,6 +1213,7 @@ B12AD86D3E924502860225CC /* ExpandCollapseActionTests.swift in Sources */, A0C0F1E5D3B2470A9C1E2014 /* AutoCollapsePopupGuardTests.swift in Sources */, 9B1765C0B5634CFABD06A916 /* AutoStartTests.swift in Sources */, + A9D0DE00000000000000E002 /* AppLogTests.swift in Sources */, A27C0DE00000000000000003 /* MacOS27Notice.swift in Sources */, A27C0DE00000000000000005 /* MacOS27NoticeTests.swift in Sources */, A27C0DE00000000000000006 /* String+Extension.swift in Sources */, diff --git a/HiddenBarTests/AppLogTests.swift b/HiddenBarTests/AppLogTests.swift new file mode 100644 index 00000000..f5c021e3 --- /dev/null +++ b/HiddenBarTests/AppLogTests.swift @@ -0,0 +1,36 @@ +// +// AppLogTests.swift +// HiddenBarTests +// +// Copyright © 2026 Console Labs. All rights reserved. +// + +import XCTest + +final class AppLogTests: XCTestCase { + + func testStderrLineKeepsTheNSLogShape() { + XCTAssertEqual(AppLog.stderrLine("AutoCollapse: holding for the palette", timestamp: "2026-11-18 09:00:00.123", + process: "Hidden Bar", pid: 321, thread: 4567), + "2026-11-18 09:00:00.123 Hidden Bar[321:4567] AutoCollapse: holding for the palette\n") + } + + func testPublicLineWritesTheTextOnceToStderr() throws { + let file = FileManager.default.temporaryDirectory.appendingPathComponent("applog-\(UUID().uuidString).txt") + FileManager.default.createFile(atPath: file.path, contents: nil) + defer { try? FileManager.default.removeItem(at: file) } + let saved = dup(STDERR_FILENO) + let handle = try FileHandle(forWritingTo: file) + dup2(handle.fileDescriptor, STDERR_FILENO) + AppLog.publicLine("AutoCollapse: holding for the palette 100%") + fflush(stderr) + dup2(saved, STDERR_FILENO) + close(saved) + try handle.close() + let written = try String(contentsOf: file, encoding: .utf8) + // Under Xcode and xcodebuild os_log also mirrors the line to stderr in its own + // shape ("[events] ..."); ours is the one with "[pid:thread]" before the text. + let ours = try NSRegularExpression(pattern: #"\[\d+:\d+\] AutoCollapse: holding for the palette 100%$"#, options: .anchorsMatchLines) + XCTAssertEqual(ours.numberOfMatches(in: written, range: NSRange(written.startIndex..., in: written)), 1, written) + } +} diff --git a/HiddenBarTests/AutoCollapsePopupGuardTests.swift b/HiddenBarTests/AutoCollapsePopupGuardTests.swift index 5f35fde1..5d8c6f69 100644 --- a/HiddenBarTests/AutoCollapsePopupGuardTests.swift +++ b/HiddenBarTests/AutoCollapsePopupGuardTests.swift @@ -31,6 +31,7 @@ final class AutoCollapsePopupGuardTests: XCTestCase { private var panelOpen = true private var panelReads = 0 private var logged: [String] = [] + private var loggedPublic: [String] = [] // A 1600 x 900 display with a 24 pt menu bar, and a 900 x 1600 one to its // right, raised so its menu bar sits higher. @@ -48,6 +49,7 @@ final class AutoCollapsePopupGuardTests: XCTestCase { panelOpen = true panelReads = 0 logged = [] + loggedPublic = [] } private func makeGuard() -> AutoCollapsePopupGuard { @@ -64,7 +66,8 @@ final class AutoCollapsePopupGuardTests: XCTestCase { notificationCenterPanelIsOpen: { [unowned self] in panelReads += 1; return panelOpen }, now: { [unowned self] in time }, ownPID: ownPID, - log: { [unowned self] in logged.append($0) }) + log: { [unowned self] in logged.append($0) }, + logPublic: { [unowned self] in loggedPublic.append("\($0)") }) } private func window(_ pid: pid_t, layer: Int, _ frame: CGRect) -> OnScreenWindow { @@ -109,6 +112,18 @@ final class AutoCollapsePopupGuardTests: XCTestCase { XCTAssertEqual(logged.count, 2) } + // The public log gets a line that names no app, window or layer; the detail + // stays in the private line above. + func testPublicLineIsStaticAndLoggedOncePerHold() { + let popupGuard = makeGuard() + list.windows = [window(netMonitor, layer: popUpMenu, CGRect(x: 1200, y: 24, width: 300, height: 400))] + XCTAssertTrue(popupGuard.defersCollapse()) + time = 10 + XCTAssertTrue(popupGuard.defersCollapse()) + XCTAssertEqual(loggedPublic, ["AutoCollapse: holding for a menu bar popup"]) + XCTAssertFalse(loggedPublic.joined().contains("netmon")) + } + // #319: a network monitor's graph is a status-level panel under its item. func testStatusLevelPopoverDefers() { let popupGuard = makeGuard() @@ -140,6 +155,7 @@ final class AutoCollapsePopupGuardTests: XCTestCase { XCTAssertTrue(popupGuard.defersCollapse()) time = 5 + 600 XCTAssertFalse(popupGuard.defersCollapse(), "the cap wins") + XCTAssertEqual(loggedPublic.last, "AutoCollapse: a menu bar popup held auto-hide for the full limit; collapsing anyway") time = 5 + 610 XCTAssertFalse(popupGuard.defersCollapse(), "until the bar is expanded again") diff --git a/docs/MANUAL.md b/docs/MANUAL.md index 74eb43ad..44e6f273 100644 --- a/docs/MANUAL.md +++ b/docs/MANUAL.md @@ -207,6 +207,23 @@ restarts. A ⌘-drag across the arrow still moves it. An app that recreates its icon without relaunching (BitBar, SwiftBar) can look like a drag; tick "Ignore drags" on its row to keep it where you put it. +### Capture a log + +Hidden Bar writes its log lines to stderr, so a log for a bug report is one command: + +```sh +# quit Hidden Bar first, then +open --stderr ~/Desktop/hiddenbar.log "/Applications/Hidden Bar.app" +``` + +Reproduce the problem, then attach `hiddenbar.log`. The file lists the bundle +identifiers of your menu bar apps (and a Mac's own error texts), so read it +before you share it. In Console and `log show`, macOS shows those lines as +``; only a few fixed lines are readable there, such as the auto-collapse +hold reasons (`AutoCollapse: holding for ...`) and the "hiding unavailable" +reasons (`NativeVisibility: hiding unavailable: ...`). Filter with +`log show --predicate 'process == "Hidden Bar" AND eventMessage BEGINSWITH "AutoCollapse"'`. + ## Requirements macOS 13 Ventura or later. Pre-Ventura (10.13 - 12.x): use diff --git a/docs/RUNBOOK.md b/docs/RUNBOOK.md index f495f41b..ad80f4eb 100644 --- a/docs/RUNBOOK.md +++ b/docs/RUNBOOK.md @@ -41,8 +41,10 @@ Standard checks before any release: - `hoverToExpand` off: no monitor log line, hover does nothing; on (the Preferences checkbox, no relaunch): dwell expands (synthesize a `mouseMoved` stream: cursor warping alone fires no events); -- autostart pref on -> `AutoStart: SMAppService.mainApp.status = 1` on stderr; - off -> `= 0` (run the binary directly to capture stderr); +- autostart pref on -> `AutoStart: status = 1` on stderr; + off -> `= 0` (`open --stderr FILE "/Applications/Hidden Bar.app"`, or run the binary + directly, to capture stderr; the unified log shows these lines as ``, only + the static lines logged with `AppLog.publicLine` are readable there); - localization tables stay parseable: `plutil -lint hidden/*.lproj/*.strings`. ### Debug hooks harness (`scripts/hb-cmd`) diff --git a/hidden/Common/Constant.swift b/hidden/Common/Constant.swift index 686bc5e6..d7b5d733 100644 --- a/hidden/Common/Constant.swift +++ b/hidden/Common/Constant.swift @@ -7,9 +7,42 @@ // import Foundation +import os enum Constant { static let appName = "Hidden Bar" static var isUsingLTRLanguage = false } + +// Foundation's NSLog marks every value in the unified log, which keeps +// bundle ids and error texts out of Console and sysdiagnoses. That stays the +// default. A line that needs to be readable there goes through publicLine: it +// takes a StaticString, so the compiler rejects anything built at run time and +// no user data can reach the public log. The same line also goes to stderr, as +// NSLog does, because os_log alone does not reach it. +enum AppLog { + private static let log = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "com.dwarvesv.minimalbar", category: "events") + private static let timestamps: DateFormatter = { + let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS" + return formatter + }() + + static func publicLine(_ text: StaticString) { + let message = "\(text)" + os_log("%{public}@", log: log, type: .default, message) + fputs(stderrLine(message, + timestamp: timestamps.string(from: Date()), + process: ProcessInfo.processInfo.processName, + pid: ProcessInfo.processInfo.processIdentifier, + thread: pthread_mach_thread_np(pthread_self())), + stderr) + } + + // The shape NSLog writes to stderr, so a captured file reads the same. + static func stderrLine(_ message: String, timestamp: String, process: String, pid: Int32, thread: UInt32) -> String { + "\(timestamp) \(process)[\(pid):\(thread)] \(message)\n" + } +} diff --git a/hidden/Features/StatusBar/AutoCollapsePopupGuard.swift b/hidden/Features/StatusBar/AutoCollapsePopupGuard.swift index ecba8740..7f8caa40 100644 --- a/hidden/Features/StatusBar/AutoCollapsePopupGuard.swift +++ b/hidden/Features/StatusBar/AutoCollapsePopupGuard.swift @@ -62,6 +62,7 @@ final class AutoCollapsePopupGuard { private let ownPID: pid_t private let cap: TimeInterval private let log: (String) -> Void + private let logPublic: (StaticString) -> Void private var deferringSince: TimeInterval? // menuBarItemOwners: bundles the engine read in the menu bar. On macOS 27 the @@ -79,7 +80,8 @@ final class AutoCollapsePopupGuard { now: @escaping () -> TimeInterval = { ProcessInfo.processInfo.systemUptime }, ownPID: pid_t = ProcessInfo.processInfo.processIdentifier, cap: TimeInterval = AutoCollapsePopupGuard.defaultCap, - log: @escaping (String) -> Void = { NSLog("%@", $0) }) { + log: @escaping (String) -> Void = { NSLog("%@", $0) }, + logPublic: @escaping (StaticString) -> Void = { AppLog.publicLine($0) }) { self.windows = windows self.displays = displays self.bundleIdentifier = bundleIdentifier @@ -89,6 +91,7 @@ final class AutoCollapsePopupGuard { self.ownPID = ownPID self.cap = cap self.log = log + self.logPublic = logPublic } // Before macOS 27 a notification keeps no screen-tall window up, so the window @@ -106,12 +109,15 @@ final class AutoCollapsePopupGuard { } let time = now() if deferringSince == nil { - // Owner and layer only: never a window title or other content. + // The public line is static so Console shows the hold; the owner and + // layer stay in the private line, never a window title or content. + logPublic("AutoCollapse: holding for a menu bar popup") log("AutoCollapse: holding for a popup from \(bundleIdentifier(holder.ownerPID) ?? "pid \(holder.ownerPID)") at layer \(holder.layer)") } let since = deferringSince ?? time deferringSince = since if time - since >= cap { + logPublic("AutoCollapse: a menu bar popup held auto-hide for the full limit; collapsing anyway") NSLog("AutoCollapse: a menu-bar popup has been open for %.0f s; collapsing anyway", time - since) return false } diff --git a/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift b/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift index a1759b82..56ce5a00 100644 --- a/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift +++ b/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift @@ -257,12 +257,13 @@ final class NativeVisibilityEngine: MenuBarEngine { } guard visibility.isAvailable else { - logUnavailableOnce("the native menu-bar visibility API is not available in this build or on this macOS") + logUnavailableOnce("NativeVisibility: hiding unavailable: the native menu-bar visibility API is not available in this build or on this macOS") state = .unavailable return completion(.unavailable) } guard runsFromApplicationsFolder() else { - logUnavailableOnce("macOS 27 would also hide Hidden Bar's own arrow: it hides only apps it knows by bundle id, and Hidden Bar runs from outside an Applications folder (\(Bundle.main.bundlePath))") + logUnavailableOnce("NativeVisibility: hiding unavailable: Hidden Bar runs from outside an Applications folder, so macOS 27 would also hide its arrow", + detail: "macOS 27 would also hide Hidden Bar's own arrow: it hides only apps it knows by bundle id, and Hidden Bar runs from outside an Applications folder (\((Bundle.main.bundlePath as NSString).abbreviatingWithTildeInPath))") state = .unavailable return completion(.unavailable) } @@ -276,7 +277,7 @@ final class NativeVisibilityEngine: MenuBarEngine { // hide icons the user kept visible. Not latched: it works as soon as // the permission is granted. inventory.requestAuthorization() - logUnavailableOnce("Accessibility permission is needed to read the menu-bar sections") + logUnavailableOnce("NativeVisibility: hiding unavailable: Accessibility permission is needed to read the menu-bar sections") return completion(.unavailable) } state = .calibrating @@ -288,13 +289,13 @@ final class NativeVisibilityEngine: MenuBarEngine { if self.holdsPresentationList { return self.holdPresentationListUnread(completion) } - self.logUnavailableOnce("the arrow's position cannot be read yet") + self.logUnavailableOnce("NativeVisibility: hiding unavailable: the arrow's position cannot be read yet") self.state = .expanded return completion(.unavailable) } if !self.holdsPresentationList, self.pausesHidingForUnkeepableItems(), let reason = layout.reasonToKeepBarWhole(unkeepableSystemItems: self.unkeepableSystemItems) { - self.logUnavailableOnce(reason) + self.logUnavailableOnce("NativeVisibility: hiding unavailable: an icon right of the arrow cannot be kept visible, so the bar stays whole", detail: reason) self.state = .expanded return completion(.unavailable) } @@ -623,6 +624,7 @@ final class NativeVisibilityEngine: MenuBarEngine { let attempt = collapseAttempt scheduleCollapseTimeout(Self.collapseTimeout) { [weak self] in guard let self = self, attempt == self.collapseAttempt, self.state == .calibrating else { return } + AppLog.publicLine("NativeVisibility: macOS did not answer the hide request; showing the whole menu bar") NSLog("NativeVisibility: macOS did not answer the hide request within \(Int(Self.collapseTimeout)) s; showing the whole menu bar") self.revealAll() self.state = .expanded @@ -1098,10 +1100,16 @@ final class NativeVisibilityEngine: MenuBarEngine { } // Logged when the reason changes, so a retried collapse does not spam. - private func logUnavailableOnce(_ reason: String) { + // `line` is the public line (static, so no user data); `detail`, when the + // reason carries data such as a path or app names, stays in the private line. + private func logUnavailableOnce(_ line: StaticString, detail: String? = nil) { + let reason = detail ?? "\(line)" guard reason != lastUnavailableReason else { return } lastUnavailableReason = reason - NSLog("NativeVisibility: hiding unavailable: \(reason)") + AppLog.publicLine(line) + if let detail { + NSLog("NativeVisibility: hiding unavailable: \(detail)") + } } // Checks whether macOS hid a system extra the allow-list could only try to diff --git a/hidden/Features/StatusBar/StatusBarController.swift b/hidden/Features/StatusBar/StatusBarController.swift index ef5b17a4..bcce8bc0 100644 --- a/hidden/Features/StatusBar/StatusBarController.swift +++ b/hidden/Features/StatusBar/StatusBarController.swift @@ -541,23 +541,24 @@ class StatusBarController: MenuBarItemProvider { // A popup hanging from the menu bar (#319) defers for up to 10 minutes; the // window list is read last, only when nothing else defers. private var defersCollapseApartFromPointer: Bool { - return holdsCollapse(for: "the Settings window", if: isPreferencesWindowVisible) - || holdsCollapse(for: "the new-apps prompt", if: arrivalsPromptIsShown) - || holdsCollapse(for: "Notification Center", if: menuBarEngine.defersAutoCollapse) - || holdsCollapse(for: "the palette", if: isRevealingForPalette) + return holdsCollapse("AutoCollapse: holding for the Settings window", if: isPreferencesWindowVisible) + || holdsCollapse("AutoCollapse: holding for the new-apps prompt", if: arrivalsPromptIsShown) + || holdsCollapse("AutoCollapse: holding for Notification Center", if: menuBarEngine.defersAutoCollapse) + || holdsCollapse("AutoCollapse: holding for the palette", if: isRevealingForPalette) || popupGuard.defersCollapse() } - // Reasons already logged since the bar last expanded, so a hold that lasts - // many timer fires logs once. Only the reason is logged, never window titles. + // Holds already logged since the bar last expanded, so a hold that lasts + // many timer fires logs once. The line is a StaticString and goes to the + // public log: only the reason, never window titles. private var loggedCollapseHolds = Set() // The condition is evaluated lazily, so the order and short-circuit of the // callers do not change. - private func holdsCollapse(for reason: String, if condition: @autoclosure () -> Bool) -> Bool { + private func holdsCollapse(_ line: StaticString, if condition: @autoclosure () -> Bool) -> Bool { guard condition() else { return false } - if loggedCollapseHolds.insert(reason).inserted { - NSLog("AutoCollapse: holding for %@", reason) + if loggedCollapseHolds.insert("\(line)").inserted { + AppLog.publicLine(line) } return true } @@ -582,7 +583,7 @@ class StatusBarController: MenuBarItemProvider { // from the clock collapses the bar itself once it closes. A popup // hanging from the menu bar (#319) defers too, for up to 10 minutes; // the window list is read last, only when nothing else defers. - if self.holdsCollapse(for: "the pointer in the menu bar", if: self.isMouseInMenuBar) || self.defersCollapseApartFromPointer { + if self.holdsCollapse("AutoCollapse: holding for the pointer in the menu bar", if: self.isMouseInMenuBar) || self.defersCollapseApartFromPointer { self.startTimerToAutoHide() } else { self.collapseMenuBar()