From 2db7f40957f8344d47119070f9138279aacc867a Mon Sep 17 00:00:00 2001 From: hongdongjian Date: Wed, 18 Nov 2026 19:24:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(native):=20=E4=BF=AE=E5=A4=8D=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E6=A0=8F=E6=BA=A2=E5=87=BA=E9=9A=90=E8=97=8F=E5=92=8C?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E5=90=8E=E7=9A=84=E8=87=AA=E5=8A=A8=E9=87=8D?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HiddenBarTests/MenuBarEngineTests.swift | 87 +++++++++++++++---- .../Engine/MenuBarEngineFactory.swift | 3 + .../Engine/NativeVisibilityEngine.swift | 27 +++--- .../StatusBar/Layout/MenuBarLayout.swift | 3 +- .../StatusBar/StatusBarController.swift | 1 + 5 files changed, 95 insertions(+), 26 deletions(-) diff --git a/HiddenBarTests/MenuBarEngineTests.swift b/HiddenBarTests/MenuBarEngineTests.swift index 51e4f318..5b08cd72 100644 --- a/HiddenBarTests/MenuBarEngineTests.swift +++ b/HiddenBarTests/MenuBarEngineTests.swift @@ -313,13 +313,17 @@ final class MultiDisplayLayoutTests: XCTestCase { systemIdentifier: "menu-bar-overflow-indicator") func testOverflowIndicatorMarksTheReadIncompleteAndIsNoItem() { - let layout = MenuBarLayoutResolver.resolve( - inventory: [overflow, listed("com.visible", on: portrait, fromRight: 150)], - separatorFrame: arrow(on: portrait, fromRight: 200), alwaysHiddenSeparatorFrame: nil, - displays: bothDisplays, isLTR: true, excludingBundle: nil) - XCTAssertTrue(layout.isIncomplete) - XCTAssertEqual(layout.sections, ["com.visible": .visible]) - XCTAssertEqual(layout.unprovenVisibleSystemItems, [], "the chevron is not an item macOS could be asked to keep") + for identifier in ["menu-bar-overflow-indicator", "menu-bar-overflow-indicator-expanded"] { + var indicator = overflow + indicator.systemIdentifier = identifier + let layout = MenuBarLayoutResolver.resolve( + inventory: [indicator, listed("com.visible", on: portrait, fromRight: 150)], + separatorFrame: arrow(on: portrait, fromRight: 200), alwaysHiddenSeparatorFrame: nil, + displays: bothDisplays, isLTR: true, excludingBundle: nil) + XCTAssertTrue(layout.isIncomplete, identifier) + XCTAssertEqual(layout.sections, ["com.visible": .visible]) + XCTAssertEqual(layout.unprovenVisibleSystemItems, [], "the chevron is not an item macOS could be asked to keep") + } } func testIncompleteReadTakesMissingAppsFromAnEarlierRead() { @@ -330,23 +334,76 @@ final class MultiDisplayLayoutTests: XCTestCase { ["com.kept": .visible, "com.moved": .hidden, "com.hidden": .hidden]) } - private func engineOnBothDisplays(_ inventory: FakeInventory, _ visibility: FakeVisibility, arrowOn display: MenuBarDisplay) -> NativeVisibilityEngine { + private func engineOnBothDisplays(_ inventory: FakeInventory, _ visibility: FakeVisibility, arrowOn display: MenuBarDisplay, + running: Set = [], + memory: MenuBarSectionMemory = InMemorySectionMemory(), + pinned: MenuBarSectionMemory = InMemorySectionMemory(), + pins: Bool = false) -> NativeVisibilityEngine { let items = FakeItems() return NativeVisibilityEngine(items: items, inventory: inventory, visibility: visibility, ownBundleIdentifier: "com.dwarvesv.minimalbar", - itemFrame: { _ in arrow(on: display, fromRight: 200) }, - displays: { bothDisplays }, isLTR: { true }) + itemFrame: { $0 === items.toggleItem ? arrow(on: display, fromRight: 200) : nil }, + displays: { bothDisplays }, runningBundleIdentifiers: { running }, isLTR: { true }, + sectionMemory: memory, pinnedSections: pinned, pinsSections: { pins }) } - func testOverflowingFirstReadLeavesTheBarWhole() { + func testOverflowingFirstReadHidesListedAppsAndKeepsUnlistedAppsVisible() { let inventory = FakeInventory() - inventory.items = [overflow, listed("com.visible", on: portrait, fromRight: 150)] + inventory.items = [overflow, listed("com.visible", on: portrait, fromRight: 150), + listed("com.hidden", on: portrait, fromRight: 300)] let visibility = FakeVisibility() - let engine = engineOnBothDisplays(inventory, visibility, arrowOn: portrait) + let engine = engineOnBothDisplays(inventory, visibility, arrowOn: portrait, + running: ["com.unlisted", "com.apple.MenuBarAgent", "com.dwarvesv.minimalbar"]) var result: CollapseResult? engine.collapse { result = $0 } - XCTAssertEqual(result, .unavailable) - XCTAssertTrue(visibility.requests.isEmpty) + XCTAssertEqual(visibility.requests.first?.bundles, ["com.dwarvesv.minimalbar", "com.unlisted", "com.visible"]) + XCTAssertEqual(engine.menuBarItemOwners, ["com.hidden", "com.visible"], "an unlisted running app is not a known menu-bar owner") + guard !visibility.requests.isEmpty else { return } + visibility.succeed(0) + XCTAssertEqual(result, .collapsed) + XCTAssertEqual(engine.state, .collapsed) + } + + func testOverflowingFirstReadUsesRememberedSectionsWhenPinsAreOff() { + let inventory = FakeInventory() + inventory.items = [overflow, listed("com.visible", on: portrait, fromRight: 150)] + let visibility = FakeVisibility() + let memory = InMemorySectionMemory() + memory.sections = ["com.saved-hidden": .hidden, "com.saved-visible": .visible] + let pinned = InMemorySectionMemory() + pinned.sections = ["com.saved-hidden": .visible] + let engine = engineOnBothDisplays(inventory, visibility, arrowOn: portrait, + running: ["com.saved-hidden", "com.saved-visible", "com.unknown"], + memory: memory, pinned: pinned) + engine.collapse { _ in } + XCTAssertEqual(visibility.requests.first?.bundles, + ["com.dwarvesv.minimalbar", "com.saved-visible", "com.unknown", "com.visible"]) + XCTAssertEqual(engine.layout?.sections["com.saved-hidden"], .hidden) + } + + func testOverflowingFirstReadUsesPinnedSectionsWithoutInventingDrags() { + let inventory = FakeInventory() + inventory.items = [overflow, listed("com.visible", on: portrait, fromRight: 150)] + let visibility = FakeVisibility() + let memory = InMemorySectionMemory() + memory.sections = ["com.saved": .visible] + let pinned = InMemorySectionMemory() + pinned.sections = ["com.saved": .hidden] + let engine = engineOnBothDisplays(inventory, visibility, arrowOn: portrait, + running: ["com.saved", "com.unknown"], + memory: memory, pinned: pinned, pins: true) + engine.collapse { _ in } + XCTAssertEqual(visibility.requests.first?.bundles, ["com.dwarvesv.minimalbar", "com.unknown", "com.visible"]) + XCTAssertEqual(pinned.sections["com.saved"], .hidden) + XCTAssertEqual(memory.sections["com.saved"], .visible, "an omitted icon was not observed moving") + XCTAssertNil(pinned.sections["com.unknown"], "a running app need not own any menu-bar icon") + guard !visibility.requests.isEmpty else { return } + visibility.succeed(0) + engine.expand() + inventory.items = [listed("com.saved", on: portrait, fromRight: 150)] + engine.collapse { _ in } + XCTAssertEqual(visibility.requests.last?.bundles, ["com.dwarvesv.minimalbar"]) + XCTAssertEqual(pinned.sections["com.saved"], .hidden) } // Collapsed once on the wide display, then again while the narrow one is diff --git a/hidden/Features/StatusBar/Engine/MenuBarEngineFactory.swift b/hidden/Features/StatusBar/Engine/MenuBarEngineFactory.swift index fe9a751f..d2871ccf 100644 --- a/hidden/Features/StatusBar/Engine/MenuBarEngineFactory.swift +++ b/hidden/Features/StatusBar/Engine/MenuBarEngineFactory.swift @@ -30,6 +30,9 @@ enum MenuBarEngineFactory { }) let engine = NativeVisibilityEngine(items: items, captureActivity: CaptureActivityMonitor(), + runningBundleIdentifiers: { + Set(NSWorkspace.shared.runningApplications.compactMap(\.bundleIdentifier)) + }, runsFromApplicationsFolder: runsFromApplicationsFolder, pausesHidingForUnkeepableItems: { Preferences.pauseHidingForUnkeepableItems }, expandsWhenCaptureStarts: { Preferences.showWholeBarWhenCaptureStarts }, diff --git a/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift b/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift index a1759b82..9c93638e 100644 --- a/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift +++ b/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift @@ -95,6 +95,7 @@ final class NativeVisibilityEngine: MenuBarEngine { private let ownBundleIdentifier: String? private let itemFrame: (NSStatusItem) -> CGRect? private let displays: () -> [MenuBarDisplay] + private let runningBundleIdentifiers: () -> Set private let isLTR: () -> Bool private let runsFromApplicationsFolder: () -> Bool @@ -180,6 +181,7 @@ final class NativeVisibilityEngine: MenuBarEngine { ownBundleIdentifier: String? = Bundle.main.bundleIdentifier, itemFrame: @escaping (NSStatusItem) -> CGRect? = { $0.button?.window?.frame }, displays: @escaping () -> [MenuBarDisplay] = MenuBarDisplay.current, + runningBundleIdentifiers: @escaping () -> Set = { [] }, isLTR: @escaping () -> Bool = { Constant.isUsingLTRLanguage }, runsFromApplicationsFolder: @escaping () -> Bool = { true }, pausesHidingForUnkeepableItems: @escaping () -> Bool = { false }, @@ -208,6 +210,7 @@ final class NativeVisibilityEngine: MenuBarEngine { self.ownBundleIdentifier = ownBundleIdentifier self.itemFrame = itemFrame self.displays = displays + self.runningBundleIdentifiers = runningBundleIdentifiers self.isLTR = isLTR self.runsFromApplicationsFolder = runsFromApplicationsFolder self.sectionMemory = sectionMemory @@ -454,14 +457,9 @@ final class NativeVisibilityEngine: MenuBarEngine { isLTR: isLTR, excludingBundle: self.ownBundleIdentifier) if layout.isIncomplete { - // Apps macOS left out would be hidden although they may be - // right of the arrow; with no complete read to take them from, - // nothing may be hidden. - guard let complete = self.lastCompleteLayout else { - NSLog("NativeVisibility: the active menu bar overflows and no complete read exists yet; leaving the bar whole") - return body(nil) + if let complete = self.lastCompleteLayout { + layout = layout.fillingIn(from: complete) } - layout = layout.fillingIn(from: complete) NSLog("NativeVisibility: the active menu bar overflows; apps it does not list keep their last known section") } else { self.lastCompleteLayout = layout @@ -482,8 +480,15 @@ final class NativeVisibilityEngine: MenuBarEngine { // What the read listed, before apps that only started are filled in: // those may have no menu-bar icon at all. self.onUnrestrictedRead?(layout, inventory) - for bundle in self.launchedSinceRead { - // Started, but its icon was not listed yet. + var missing = self.launchedSinceRead + if layout.isIncomplete { + missing.formUnion(self.runningBundleIdentifiers()) + } + for bundle in missing where layout.sections[bundle] == nil + && bundle != self.ownBundleIdentifier + && !MenuBarLayoutResolver.systemItemOwners.contains(bundle) { + // A launch or overflow can leave an app out of the read. Its + // saved section wins; unknown apps stay visible. layout.sections[bundle] = self.rememberedSection(of: bundle) } NSLog("NativeVisibility: arrow at x=\(boundary.midX); visible \(layout.bundles(in: [.visible])), hidden \(layout.bundles(in: [.hidden])), always hidden \(layout.bundles(in: [.alwaysHidden]))") @@ -697,7 +702,9 @@ final class NativeVisibilityEngine: MenuBarEngine { var menuBarItemOwners: Set { let read = layout?.sections.keys.map { $0 } ?? [] let complete = lastCompleteLayout?.sections.keys.map { $0 } ?? [] - return Set(read + complete) + // Overflow allows other running apps too; only observed owners can + // defer auto-collapse for a menu-bar popup. + return Set(read + complete).intersection(sectionMemory.sections.keys) } var hiddenSectionBundles: Set { diff --git a/hidden/Features/StatusBar/Layout/MenuBarLayout.swift b/hidden/Features/StatusBar/Layout/MenuBarLayout.swift index a1a4a55d..2594990e 100644 --- a/hidden/Features/StatusBar/Layout/MenuBarLayout.swift +++ b/hidden/Features/StatusBar/Layout/MenuBarLayout.swift @@ -368,7 +368,8 @@ enum MenuBarLayoutResolver { } continue } - if systemItemOwners.contains(key), item.systemIdentifier == overflowIndicator { + if systemItemOwners.contains(key), + item.systemIdentifier == overflowIndicator || item.systemIdentifier == "\(overflowIndicator)-expanded" { layout.isIncomplete = true continue } diff --git a/hidden/Features/StatusBar/StatusBarController.swift b/hidden/Features/StatusBar/StatusBarController.swift index 63ab4c2e..c2a63a84 100644 --- a/hidden/Features/StatusBar/StatusBarController.swift +++ b/hidden/Features/StatusBar/StatusBarController.swift @@ -457,6 +457,7 @@ class StatusBarController: MenuBarItemProvider { if wantsFullBar { NSApp.setActivationPolicy(.regular) } + autoCollapseIfNeeded() } private var collapsedArrowImage: NSImage? { From 7a708c2b9ce5ce2b162e9fe9de990389e84babc6 Mon Sep 17 00:00:00 2001 From: hongdongjian Date: Wed, 18 Nov 2026 19:24:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(build):=20=E6=98=8E=E7=A1=AE=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E6=88=AA=E5=9B=BE=E6=B8=90=E5=8F=98=E8=89=B2=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hidden/Features/Palette/PaletteSnapshot.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hidden/Features/Palette/PaletteSnapshot.swift b/hidden/Features/Palette/PaletteSnapshot.swift index 8636dbb7..a9cd8a34 100644 --- a/hidden/Features/Palette/PaletteSnapshot.swift +++ b/hidden/Features/Palette/PaletteSnapshot.swift @@ -129,7 +129,8 @@ enum PaletteSnapshot { wallpaper.frame = backdrop.bounds wallpaper.startPoint = CGPoint(x: 0, y: 1) wallpaper.endPoint = CGPoint(x: 1, y: 0) - wallpaper.colors = (appearance == .darkAqua ? [0x101A30, 0x1D1A36, 0x2E1C2E] : [0xD6E3F5, 0xE3DAF0, 0xF2E2D6]).map { hex in + let wallpaperColors: [Int] = appearance == .darkAqua ? [0x101A30, 0x1D1A36, 0x2E1C2E] : [0xD6E3F5, 0xE3DAF0, 0xF2E2D6] + wallpaper.colors = wallpaperColors.map { hex in NSColor(srgbRed: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: 1).cgColor }