From 3d9c509054ac71872e706b486bc490cb53bab8d6 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 18 Nov 2026 23:20:37 +0700 Subject: [PATCH 1/6] fix(log): write app log lines public to the unified log and stderr Foundation's NSLog marks every value on recent macOS, so Console and log show only printed . A module-level NSLog now logs the message with os_log %{public}@ under the app's bundle id and writes the same line to stderr, as before. The Objective-C shim does the same by hand. --- Hidden Bar.xcodeproj/project.pbxproj | 4 ++ HiddenBarTests/AppLogTests.swift | 57 +++++++++++++++++++ hidden/Common/Constant.swift | 43 ++++++++++++++ .../Engine/Native/HBNativeVisibilityShim.m | 8 ++- 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 HiddenBarTests/AppLogTests.swift 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..26a385a4 --- /dev/null +++ b/HiddenBarTests/AppLogTests.swift @@ -0,0 +1,57 @@ +// +// AppLogTests.swift +// HiddenBarTests +// +// Copyright © 2026 Console Labs. All rights reserved. +// + +import XCTest + +final class AppLogTests: XCTestCase { + + func testNoArgumentsKeepsThePercentSignsOfAnAlreadyComposedMessage() { + // A call site that interpolates passes the finished text as the format. + XCTAssertEqual(AppLog.message("AutoCollapse: holding for 100% of /tmp/a%20b %@ %d", []), + "AutoCollapse: holding for 100% of /tmp/a%20b %@ %d") + } + + func testFormatArgumentsAreSubstituted() { + XCTAssertEqual(AppLog.message("AutoCollapse: a popup has been open for %.0f s", [12.4 as Double]), + "AutoCollapse: a popup has been open for 12 s") + XCTAssertEqual(AppLog.message("SettingsSnapshot: %@ %.0fx%.0f", ["a.png", 480.0 as Double, 320.0 as Double]), + "SettingsSnapshot: a.png 480x320") + } + + func testObjectArgumentWithPercentSignsIsInsertedVerbatim() { + // The guard logs through NSLog("%@", text); the text is data, not a format. + let text = "AutoCollapse: holding for a popup from com.example.app%d at layer 25" + XCTAssertEqual(AppLog.message("%@", [text]), text) + } + + func testMessageStartsWithTheCallSiteText() { + // `log show` predicates use eventMessage BEGINSWITH "AutoCollapse". + XCTAssertTrue(AppLog.message("AutoCollapse: holding for %@", ["the palette"]).hasPrefix("AutoCollapse")) + } + + func testStderrLineKeepsTheNSLogShape() { + XCTAssertEqual(AppLog.stderrLine("AutoStart: status = 1", 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] AutoStart: status = 1\n") + } + + func testShadowedNSLogWritesTheLineToStderr() 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) + NSLog("AutoStart: status = %d, name %@", 1, "50%") + fflush(stderr) + dup2(saved, STDERR_FILENO) + close(saved) + try handle.close() + let written = try String(contentsOf: file, encoding: .utf8) + XCTAssertTrue(written.hasSuffix("] AutoStart: status = 1, name 50%\n"), written) + } +} diff --git a/hidden/Common/Constant.swift b/hidden/Common/Constant.swift index 686bc5e6..99898a1a 100644 --- a/hidden/Common/Constant.swift +++ b/hidden/Common/Constant.swift @@ -7,9 +7,52 @@ // 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 on recent +// macOS, so Console and `log show` showed "" for each of our lines. +// This module-level NSLog shadows it for every caller in the target: the +// message is logged public (call sites keep user content out of it) and also +// written to stderr, which os_log alone does not reach. +enum AppLog { + static let category = "app" + + private static let log = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "com.dwarvesv.minimalbar", category: category) + 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 + }() + + // No arguments: the text is already composed (most call sites interpolate), + // so a "%" in it, such as a file name, must not be read as a format. + static func message(_ format: String, _ args: [CVarArg]) -> String { + args.isEmpty ? format : String(format: format, arguments: args) + } + + // The line NSLog wrote to stderr, which RUNBOOK checks read. + static func stderrLine(_ message: String, timestamp: String, process: String, pid: Int32, thread: UInt32) -> String { + "\(timestamp) \(process)[\(pid):\(thread)] \(message)\n" + } + + static func write(_ message: String) { + os_log("%{public}@", log: log, type: .default, message) + let line = stderrLine(message, + timestamp: timestamps.string(from: Date()), + process: ProcessInfo.processInfo.processName, + pid: ProcessInfo.processInfo.processIdentifier, + thread: pthread_mach_thread_np(pthread_self())) + fputs(line, stderr) + } +} + +func NSLog(_ format: String, _ args: CVarArg...) { + AppLog.write(AppLog.message(format, args)) +} diff --git a/hidden/Features/StatusBar/Engine/Native/HBNativeVisibilityShim.m b/hidden/Features/StatusBar/Engine/Native/HBNativeVisibilityShim.m index a1496230..d1bdc79b 100644 --- a/hidden/Features/StatusBar/Engine/Native/HBNativeVisibilityShim.m +++ b/hidden/Features/StatusBar/Engine/Native/HBNativeVisibilityShim.m @@ -19,6 +19,7 @@ #import #import +#import // MenuBarClientCore is the private framework behind macOS 27's assessment // (exam lockdown) mode, which can restrict the menu bar to an allow-list. It is @@ -80,7 +81,12 @@ void HBNativeVisibilityInvalidate(id assertion) { ((void (*)(id, SEL))objc_msgSend)(assertion, HBInvalidate()); } } @catch (NSException *exception) { - NSLog(@"NativeVisibility: invalidate raised %@: %@", exception.name, exception.reason); + // NSLog would show in the unified log; same subsystem and + // stderr line as the Swift side's NSLog. + NSString *line = [NSString stringWithFormat:@"NativeVisibility: invalidate raised %@: %@", exception.name, exception.reason]; + os_log_t log = os_log_create((NSBundle.mainBundle.bundleIdentifier ?: @"com.dwarvesv.minimalbar").UTF8String, "app"); + os_log(log, "%{public}@", line); + fprintf(stderr, "%s\n", line.UTF8String); } } From 805c1a2c0e01904a10f818451a4186ca21705cc6 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 18 Nov 2026 23:20:37 +0700 Subject: [PATCH 2/6] fix(native): keep the home folder name out of the public log The macOS 27 unavailable line logged the full app path; it now logs it with the home folder as ~, since the log is public. --- hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift b/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift index a1759b82..26ac84b1 100644 --- a/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift +++ b/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift @@ -262,7 +262,7 @@ final class NativeVisibilityEngine: MenuBarEngine { 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("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) } From 79ab40f997fd76f2492268af7ebc6d2d69df5489 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 18 Nov 2026 23:22:42 +0700 Subject: [PATCH 3/6] Revert "fix(log): write app log lines public to the unified log and stderr" This reverts commit 3d9c509054ac71872e706b486bc490cb53bab8d6. --- Hidden Bar.xcodeproj/project.pbxproj | 4 -- HiddenBarTests/AppLogTests.swift | 57 ------------------- hidden/Common/Constant.swift | 43 -------------- .../Engine/Native/HBNativeVisibilityShim.m | 8 +-- 4 files changed, 1 insertion(+), 111 deletions(-) delete mode 100644 HiddenBarTests/AppLogTests.swift diff --git a/Hidden Bar.xcodeproj/project.pbxproj b/Hidden Bar.xcodeproj/project.pbxproj index 14034c72..193686a0 100644 --- a/Hidden Bar.xcodeproj/project.pbxproj +++ b/Hidden Bar.xcodeproj/project.pbxproj @@ -90,7 +90,6 @@ 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 */; }; @@ -370,7 +369,6 @@ 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 = ""; }; @@ -562,7 +560,6 @@ 764544B7EDBB41A18087ED6F /* ExpandCollapseActionTests.swift */, A0C0F1E5D3B2470A9C1E2002 /* AutoCollapsePopupGuardTests.swift */, F013C3E5499B4EA7B816F7A8 /* AutoStartTests.swift */, - A9D0DE00000000000000E001 /* AppLogTests.swift */, A27C0DE00000000000000004 /* MacOS27NoticeTests.swift */, CC5FC25336EC320548CF4C87 /* AccessibilityPermissionTests.swift */, 60AFBE8D4C25548192E7D135 /* SettingsModelTests.swift */, @@ -1213,7 +1210,6 @@ 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 deleted file mode 100644 index 26a385a4..00000000 --- a/HiddenBarTests/AppLogTests.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// AppLogTests.swift -// HiddenBarTests -// -// Copyright © 2026 Console Labs. All rights reserved. -// - -import XCTest - -final class AppLogTests: XCTestCase { - - func testNoArgumentsKeepsThePercentSignsOfAnAlreadyComposedMessage() { - // A call site that interpolates passes the finished text as the format. - XCTAssertEqual(AppLog.message("AutoCollapse: holding for 100% of /tmp/a%20b %@ %d", []), - "AutoCollapse: holding for 100% of /tmp/a%20b %@ %d") - } - - func testFormatArgumentsAreSubstituted() { - XCTAssertEqual(AppLog.message("AutoCollapse: a popup has been open for %.0f s", [12.4 as Double]), - "AutoCollapse: a popup has been open for 12 s") - XCTAssertEqual(AppLog.message("SettingsSnapshot: %@ %.0fx%.0f", ["a.png", 480.0 as Double, 320.0 as Double]), - "SettingsSnapshot: a.png 480x320") - } - - func testObjectArgumentWithPercentSignsIsInsertedVerbatim() { - // The guard logs through NSLog("%@", text); the text is data, not a format. - let text = "AutoCollapse: holding for a popup from com.example.app%d at layer 25" - XCTAssertEqual(AppLog.message("%@", [text]), text) - } - - func testMessageStartsWithTheCallSiteText() { - // `log show` predicates use eventMessage BEGINSWITH "AutoCollapse". - XCTAssertTrue(AppLog.message("AutoCollapse: holding for %@", ["the palette"]).hasPrefix("AutoCollapse")) - } - - func testStderrLineKeepsTheNSLogShape() { - XCTAssertEqual(AppLog.stderrLine("AutoStart: status = 1", 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] AutoStart: status = 1\n") - } - - func testShadowedNSLogWritesTheLineToStderr() 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) - NSLog("AutoStart: status = %d, name %@", 1, "50%") - fflush(stderr) - dup2(saved, STDERR_FILENO) - close(saved) - try handle.close() - let written = try String(contentsOf: file, encoding: .utf8) - XCTAssertTrue(written.hasSuffix("] AutoStart: status = 1, name 50%\n"), written) - } -} diff --git a/hidden/Common/Constant.swift b/hidden/Common/Constant.swift index 99898a1a..686bc5e6 100644 --- a/hidden/Common/Constant.swift +++ b/hidden/Common/Constant.swift @@ -7,52 +7,9 @@ // 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 on recent -// macOS, so Console and `log show` showed "" for each of our lines. -// This module-level NSLog shadows it for every caller in the target: the -// message is logged public (call sites keep user content out of it) and also -// written to stderr, which os_log alone does not reach. -enum AppLog { - static let category = "app" - - private static let log = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "com.dwarvesv.minimalbar", category: category) - 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 - }() - - // No arguments: the text is already composed (most call sites interpolate), - // so a "%" in it, such as a file name, must not be read as a format. - static func message(_ format: String, _ args: [CVarArg]) -> String { - args.isEmpty ? format : String(format: format, arguments: args) - } - - // The line NSLog wrote to stderr, which RUNBOOK checks read. - static func stderrLine(_ message: String, timestamp: String, process: String, pid: Int32, thread: UInt32) -> String { - "\(timestamp) \(process)[\(pid):\(thread)] \(message)\n" - } - - static func write(_ message: String) { - os_log("%{public}@", log: log, type: .default, message) - let line = stderrLine(message, - timestamp: timestamps.string(from: Date()), - process: ProcessInfo.processInfo.processName, - pid: ProcessInfo.processInfo.processIdentifier, - thread: pthread_mach_thread_np(pthread_self())) - fputs(line, stderr) - } -} - -func NSLog(_ format: String, _ args: CVarArg...) { - AppLog.write(AppLog.message(format, args)) -} diff --git a/hidden/Features/StatusBar/Engine/Native/HBNativeVisibilityShim.m b/hidden/Features/StatusBar/Engine/Native/HBNativeVisibilityShim.m index d1bdc79b..a1496230 100644 --- a/hidden/Features/StatusBar/Engine/Native/HBNativeVisibilityShim.m +++ b/hidden/Features/StatusBar/Engine/Native/HBNativeVisibilityShim.m @@ -19,7 +19,6 @@ #import #import -#import // MenuBarClientCore is the private framework behind macOS 27's assessment // (exam lockdown) mode, which can restrict the menu bar to an allow-list. It is @@ -81,12 +80,7 @@ void HBNativeVisibilityInvalidate(id assertion) { ((void (*)(id, SEL))objc_msgSend)(assertion, HBInvalidate()); } } @catch (NSException *exception) { - // NSLog would show in the unified log; same subsystem and - // stderr line as the Swift side's NSLog. - NSString *line = [NSString stringWithFormat:@"NativeVisibility: invalidate raised %@: %@", exception.name, exception.reason]; - os_log_t log = os_log_create((NSBundle.mainBundle.bundleIdentifier ?: @"com.dwarvesv.minimalbar").UTF8String, "app"); - os_log(log, "%{public}@", line); - fprintf(stderr, "%s\n", line.UTF8String); + NSLog(@"NativeVisibility: invalidate raised %@: %@", exception.name, exception.reason); } } From ed0e7421a8dd8f1b1d3790ea37d3ff5b5cf0d0ae Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 18 Nov 2026 23:23:56 +0700 Subject: [PATCH 4/6] fix(log): public static lines for auto-collapse holds and hide failures NSLog stays private in the unified log. AppLog.publicLine takes a StaticString, so no run-time data can reach the public log, and also writes the line to stderr. The five auto-collapse hold reasons, the popup guard hold and cap, the hiding unavailable reasons and the collapse timeout use it; lines that carry data keep their private line beside it. --- Hidden Bar.xcodeproj/project.pbxproj | 4 +++ HiddenBarTests/AppLogTests.swift | 34 +++++++++++++++++++ .../AutoCollapsePopupGuardTests.swift | 18 +++++++++- hidden/Common/Constant.swift | 33 ++++++++++++++++++ .../StatusBar/AutoCollapsePopupGuard.swift | 10 ++++-- .../Engine/NativeVisibilityEngine.swift | 22 ++++++++---- .../StatusBar/StatusBarController.swift | 21 ++++++------ 7 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 HiddenBarTests/AppLogTests.swift 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..8a7ce772 --- /dev/null +++ b/HiddenBarTests/AppLogTests.swift @@ -0,0 +1,34 @@ +// +// 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) + XCTAssertTrue(written.hasSuffix("] AutoCollapse: holding for the palette 100%\n"), written) + XCTAssertEqual(written.components(separatedBy: "\n").filter { !$0.isEmpty }.count, 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/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 26ac84b1..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 as NSString).abbreviatingWithTildeInPath))") + 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() From b6574c4fede9544fa0096730fc3f52eca65718b8 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 18 Nov 2026 23:24:17 +0700 Subject: [PATCH 5/6] docs: capture a log with stderr; public log lines named --- CHANGELOG.md | 2 +- docs/MANUAL.md | 17 +++++++++++++++++ docs/RUNBOOK.md | 6 ++++-- 3 files changed, 22 insertions(+), 3 deletions(-) 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/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`) From b2603ec3b53b2e1c225a6142a210589b71347713 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 18 Nov 2026 23:27:24 +0700 Subject: [PATCH 6/6] test(log): count the NSLog-shaped line only; os_log mirrors under Xcode --- HiddenBarTests/AppLogTests.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/HiddenBarTests/AppLogTests.swift b/HiddenBarTests/AppLogTests.swift index 8a7ce772..f5c021e3 100644 --- a/HiddenBarTests/AppLogTests.swift +++ b/HiddenBarTests/AppLogTests.swift @@ -28,7 +28,9 @@ final class AppLogTests: XCTestCase { close(saved) try handle.close() let written = try String(contentsOf: file, encoding: .utf8) - XCTAssertTrue(written.hasSuffix("] AutoCollapse: holding for the palette 100%\n"), written) - XCTAssertEqual(written.components(separatedBy: "\n").filter { !$0.isEmpty }.count, 1, written) + // 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) } }