diff --git a/Hidden Bar.xcodeproj/project.pbxproj b/Hidden Bar.xcodeproj/project.pbxproj index 8bc02703..39f14b5d 100644 --- a/Hidden Bar.xcodeproj/project.pbxproj +++ b/Hidden Bar.xcodeproj/project.pbxproj @@ -184,6 +184,19 @@ 2AC2C7C96BE96B588BEDAFA7 /* ShortcutRecorderRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE27CCE27C72C84408884605 /* ShortcutRecorderRowTests.swift */; }; 187C86957CFDA673F042D998 /* MenuBarItemCatalogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A491DF3D79E610456CB4D42A /* MenuBarItemCatalogTests.swift */; }; F59D5C1E5A222F26AC56C853 /* MenuBarItemCatalog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 573B38F9552D434AB7F4C8B7 /* MenuBarItemCatalog.swift */; }; + 1E07FB2B324AC1DAB96AAADE /* ArrivalsInbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF902E9BE3B1BE10C995E132 /* ArrivalsInbox.swift */; }; + 13F8DC7217013A737A563D04 /* ArrivalsInbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF902E9BE3B1BE10C995E132 /* ArrivalsInbox.swift */; }; + 675A6B7D509710674F140745 /* ArrivalsInbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF902E9BE3B1BE10C995E132 /* ArrivalsInbox.swift */; }; + A66C490FB27F3054C3C7E124 /* ArrivalsInboxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45E056AC5F70549F7B5C193F /* ArrivalsInboxTests.swift */; }; + FF3D69EF93B8CD5A1F5C346C /* ArrivalsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90DE66BC312386D4D1892D2 /* ArrivalsController.swift */; }; + 6082C5353938E20315235AF7 /* ArrivalsPromptView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 629C4145C6F9C73CEF11661F /* ArrivalsPromptView.swift */; }; + 9525F394998A4A9504A1DCD6 /* ArrivalsPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90917F0CAC63090D048C38C /* ArrivalsPresenter.swift */; }; + 0A2078C23E9718AEB6895681 /* ArrivalsSnapshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 668908D9AD4320CBE15D2771 /* ArrivalsSnapshot.swift */; }; + 08CD9158FCFA204A9A30E774 /* ArrivalsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D932613B6FC583B367C9D8CE /* ArrivalsControllerTests.swift */; }; + 3AC58404F4AF6E3DB0DF74F9 /* ArrivalsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90DE66BC312386D4D1892D2 /* ArrivalsController.swift */; }; + 7CCBBD3DA63D07BE11208CB1 /* ArrivalsPromptView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 629C4145C6F9C73CEF11661F /* ArrivalsPromptView.swift */; }; + 385B2BC00024539915B249EC /* ArrivalsPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90917F0CAC63090D048C38C /* ArrivalsPresenter.swift */; }; + FC73E3ACF7ADF824E6896D79 /* ArrivalsSnapshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 668908D9AD4320CBE15D2771 /* ArrivalsSnapshot.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -326,6 +339,13 @@ 6323960AD76C15D25F359F81 /* MenuBarCatalogStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarCatalogStateTests.swift; sourceTree = ""; }; BE27CCE27C72C84408884605 /* ShortcutRecorderRowTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutRecorderRowTests.swift; sourceTree = ""; }; A491DF3D79E610456CB4D42A /* MenuBarItemCatalogTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarItemCatalogTests.swift; sourceTree = ""; }; + CF902E9BE3B1BE10C995E132 /* ArrivalsInbox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrivalsInbox.swift; sourceTree = ""; }; + 45E056AC5F70549F7B5C193F /* ArrivalsInboxTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrivalsInboxTests.swift; sourceTree = ""; }; + E90DE66BC312386D4D1892D2 /* ArrivalsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrivalsController.swift; sourceTree = ""; }; + 629C4145C6F9C73CEF11661F /* ArrivalsPromptView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrivalsPromptView.swift; sourceTree = ""; }; + E90917F0CAC63090D048C38C /* ArrivalsPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrivalsPresenter.swift; sourceTree = ""; }; + 668908D9AD4320CBE15D2771 /* ArrivalsSnapshot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrivalsSnapshot.swift; sourceTree = ""; }; + D932613B6FC583B367C9D8CE /* ArrivalsControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrivalsControllerTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -392,6 +412,7 @@ 8D80CEB42B2A2DF1177835EA /* Updates */, 8B146598250E90AA078F76E9 /* Settings */, A9E70DE0000000000000D001 /* Reveal */, + A9E70DE0000000000000A001 /* Arrivals */, ); path = Features; sourceTree = ""; @@ -467,6 +488,7 @@ CAF0C568A02BF9D8777E349B /* HotKeyRegistryTests.swift */, C0340E59AB11C9D5E8965965 /* GlobalKeybindingPreferencesTests.swift */, 6323960AD76C15D25F359F81 /* MenuBarCatalogStateTests.swift */, + 45E056AC5F70549F7B5C193F /* ArrivalsInboxTests.swift */, ); path = HiddenBarTests; sourceTree = ""; @@ -489,6 +511,7 @@ D7AAD0E40FFA01D5E3255A6C /* RevealSettingsTests.swift */, BE27CCE27C72C84408884605 /* ShortcutRecorderRowTests.swift */, A491DF3D79E610456CB4D42A /* MenuBarItemCatalogTests.swift */, + D932613B6FC583B367C9D8CE /* ArrivalsControllerTests.swift */, ); name = HiddenTests; path = HiddenTests; @@ -668,6 +691,18 @@ path = Reveal; sourceTree = ""; }; + A9E70DE0000000000000A001 /* Arrivals */ = { + isa = PBXGroup; + children = ( + E90DE66BC312386D4D1892D2 /* ArrivalsController.swift */, + CF902E9BE3B1BE10C995E132 /* ArrivalsInbox.swift */, + E90917F0CAC63090D048C38C /* ArrivalsPresenter.swift */, + 629C4145C6F9C73CEF11661F /* ArrivalsPromptView.swift */, + 668908D9AD4320CBE15D2771 /* ArrivalsSnapshot.swift */, + ); + path = Arrivals; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -899,6 +934,11 @@ 362FAF660DDC9E225B1786E0 /* ShortcutRecorderRow.swift in Sources */, 0AB67F8D3027DF064F4B5D75 /* MenuBarCatalogState.swift in Sources */, 15B6EC919BC2CB693739137C /* MenuBarItemCatalog.swift in Sources */, + 1E07FB2B324AC1DAB96AAADE /* ArrivalsInbox.swift in Sources */, + FF3D69EF93B8CD5A1F5C346C /* ArrivalsController.swift in Sources */, + 6082C5353938E20315235AF7 /* ArrivalsPromptView.swift in Sources */, + 9525F394998A4A9504A1DCD6 /* ArrivalsPresenter.swift in Sources */, + 0A2078C23E9718AEB6895681 /* ArrivalsSnapshot.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -921,6 +961,7 @@ E6D398FD9277C7ACB911BBB3 /* RevealSettingsTests.swift in Sources */, 2AC2C7C96BE96B588BEDAFA7 /* ShortcutRecorderRowTests.swift in Sources */, 187C86957CFDA673F042D998 /* MenuBarItemCatalogTests.swift in Sources */, + 08CD9158FCFA204A9A30E774 /* ArrivalsControllerTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -983,6 +1024,11 @@ 35A0CE4DDA4691309BF16489 /* ShortcutRecorderRow.swift in Sources */, 1B165ADA55704BC77434425D /* MenuBarCatalogState.swift in Sources */, F59D5C1E5A222F26AC56C853 /* MenuBarItemCatalog.swift in Sources */, + 13F8DC7217013A737A563D04 /* ArrivalsInbox.swift in Sources */, + 3AC58404F4AF6E3DB0DF74F9 /* ArrivalsController.swift in Sources */, + 7CCBBD3DA63D07BE11208CB1 /* ArrivalsPromptView.swift in Sources */, + 385B2BC00024539915B249EC /* ArrivalsPresenter.swift in Sources */, + FC73E3ACF7ADF824E6896D79 /* ArrivalsSnapshot.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1026,6 +1072,8 @@ 30D0EB437BE32F991D6F7971 /* HotKeyRegistryTests.swift in Sources */, 1E50082AD4E9CB0D4B5A0103 /* GlobalKeybindingPreferencesTests.swift in Sources */, 04E2F9742366D046C8AE9719 /* MenuBarCatalogStateTests.swift in Sources */, + 675A6B7D509710674F140745 /* ArrivalsInbox.swift in Sources */, + A66C490FB27F3054C3C7E124 /* ArrivalsInboxTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/HiddenBarTests/ArrivalsInboxTests.swift b/HiddenBarTests/ArrivalsInboxTests.swift new file mode 100644 index 00000000..d155c39e --- /dev/null +++ b/HiddenBarTests/ArrivalsInboxTests.swift @@ -0,0 +1,264 @@ +// +// ArrivalsInboxTests.swift +// HiddenBarTests +// +// Copyright © 2026 Dwarves Foundation. All rights reserved. +// + +import XCTest + +// The arrivals decisions: placement by the Settings default, the waiting queue, +// answers, the 24 hour lapse, and the upgrade rule. Fixtures only; the catalog's +// own diff is MenuBarCatalogStateTests. +final class ArrivalsInboxTests: XCTestCase { + private let t0 = Date(timeIntervalSince1970: 1_000_000) + + private func place(_ bundle: String, _ section: MenuBarSection) -> ArrivalsInbox.Placement { + ArrivalsInbox.Placement(bundle: bundle, section: section) + } + + // MARK: Show It and Hide It + + // Given Show It, when an app arrives that the engine's resolver left on its read position (hidden) + // Then nothing is written: the app stays hidden, exactly as 1.12 places it, and nothing is asked + func test_showIt_leavesTheResolversPlacementAlone() { + var inbox = ArrivalsInbox() + let placements = inbox.receive(["com.a"], choice: .show, pinsSections: true, table: ["com.a": .hidden]) + + XCTAssertEqual(placements, []) + XCTAssertEqual(inbox.pending, []) + } + + // Given Show It and an arrival the catalog never saw but the pinned table already holds + // (an App Store import, say), including one the user hid + // Then the entry is left untouched + func test_showIt_leavesAPinnedEntryTheCatalogNeverSawUntouched() { + var inbox = ArrivalsInbox() + let table: [String: MenuBarSection] = ["com.imported": .alwaysHidden, "com.other": .hidden] + + XCTAssertEqual(inbox.receive(["com.imported", "com.other"], choice: .show, pinsSections: true, table: table), []) + } + + // Given Hide It, when an app arrives + // Then it is placed hidden on first sight, and never asked + func test_hideIt_placesHiddenAndNeverAsks() { + var inbox = ArrivalsInbox() + let placements = inbox.receive(["com.a", "com.b"], choice: .hide, pinsSections: true, table: ["com.a": .visible]) + + XCTAssertEqual(placements, [place("com.a", .hidden), place("com.b", .hidden)]) + XCTAssertEqual(inbox.pending, []) + } + + // MARK: Ask Me + + // Given Ask Me, when an app arrives that the table put on the hidden side + // Then it is queued and written visible: it stays shown until the user answers + func test_askMe_queuesAndKeepsTheAppShown() { + var inbox = ArrivalsInbox() + let placements = inbox.receive(["com.a"], choice: .ask, pinsSections: true, table: ["com.a": .hidden]) + + XCTAssertEqual(inbox.pending, ["com.a"]) + XCTAssertEqual(placements, [place("com.a", .visible)]) + } + + // Given several apps found by one read + // Then each waits, in the order given + func test_severalArrivalsAtOnce_allWaitInOrder() { + var inbox = ArrivalsInbox() + _ = inbox.receive(["com.a", "com.b", "com.c"], choice: .ask, pinsSections: true, table: [:]) + + XCTAssertEqual(inbox.pending, ["com.a", "com.b", "com.c"]) + } + + // Given a waiting app, when the answer is Hide + // Then the app leaves the queue and the hidden section is returned for writing + func test_answer_clearsTheEntryAndReturnsTheSection() { + var inbox = ArrivalsInbox(pending: ["com.a", "com.b"]) + + XCTAssertEqual(inbox.answer("com.a", .hide), place("com.a", .hidden)) + XCTAssertEqual(inbox.pending, ["com.b"]) + XCTAssertEqual(inbox.answer("com.b", .alwaysHide), place("com.b", .alwaysHidden)) + XCTAssertEqual(inbox.pending, []) + } + + // Given an app that is not waiting, when an answer comes in (a stale prompt) + // Then nothing is written + func test_answerForAnAppNotWaiting_isIgnored() { + var inbox = ArrivalsInbox(pending: ["com.a"]) + + XCTAssertNil(inbox.answer("com.other", .hide)) + XCTAssertEqual(inbox.pending, ["com.a"]) + } + + // Given six waiting apps, when Hide All is pressed + // Then every one is placed hidden and the queue is empty + func test_answerAll_placesEveryWaitingApp() { + var inbox = ArrivalsInbox(pending: ["com.a", "com.b", "com.c"]) + + XCTAssertEqual(inbox.answerAll(.show), [place("com.a", .visible), place("com.b", .visible), place("com.c", .visible)]) + XCTAssertEqual(inbox.pending, []) + } + + // MARK: asked at most once + + // Given an answered app, when the catalog publishes the same arrivals again + // (it repeats the latest read's list on every later publish) + // Then the app is not queued again and the user's answer is not overwritten + func test_anAnsweredAppIsNotAskedAgainInTheSameRun() { + var inbox = ArrivalsInbox() + _ = inbox.receive(["com.a"], choice: .ask, pinsSections: true, table: [:]) + _ = inbox.answer("com.a", .hide) + + let again = inbox.receive(["com.a"], choice: .ask, pinsSections: true, table: ["com.a": .hidden]) + XCTAssertEqual(again, []) + XCTAssertEqual(inbox.pending, []) + } + + // Given Hide It and an app the user then moved to visible + // When the catalog repeats the arrival + // Then the placement is not applied a second time + func test_aRepeatedArrivalDoesNotUndoTheUsersEdit() { + var inbox = ArrivalsInbox() + _ = inbox.receive(["com.a"], choice: .hide, pinsSections: true, table: [:]) + + XCTAssertEqual(inbox.receive(["com.a"], choice: .hide, pinsSections: true, table: ["com.a": .visible]), []) + } + + // Given an answer and a restart + // When the catalog (which persists first-seen times) reads the same bar + // Then it announces nothing, so the new inbox asks nothing: the question is asked once, across restarts + func test_anAppIsAskedAtMostOnce_acrossARestart() { + var catalog = MenuBarCatalogState(firstSeen: nil) + _ = catalog.apply(read: ["com.old": .visible], now: t0) + var inbox = ArrivalsInbox() + let arrivals = catalog.apply(read: ["com.old": .visible, "com.new": .visible], now: t0) + _ = inbox.receive(arrivals, choice: .ask, pinsSections: true, table: [:]) + _ = inbox.answer("com.new", .show) + + // Launch again: the persisted first-seen map and the persisted queue come back. + var relaunchedCatalog = MenuBarCatalogState(firstSeen: catalog.firstSeen) + var relaunched = ArrivalsInbox(pending: inbox.pending) + let found = relaunchedCatalog.apply(read: ["com.old": .visible, "com.new": .visible], now: t0) + XCTAssertEqual(found, []) + XCTAssertEqual(relaunched.receive(found, choice: .ask, pinsSections: true, table: [:]), []) + XCTAssertEqual(relaunched.pending, []) + } + + // Given a question not answered before a quit + // When Hidden Bar starts again and the same app is injected or found + // Then it is still waiting, once, and not queued a second time + func test_aWaitingQuestionSurvivesARestart() { + var inbox = ArrivalsInbox(pending: ["com.a"]) + inbox.inject("com.a") + _ = inbox.receive(["com.a"], choice: .ask, pinsSections: true, table: ["com.a": .visible]) + + XCTAssertEqual(inbox.pending, ["com.a"]) + } + + // MARK: edge states + + // Given an app that quits before it is answered + // Then its entry stays (the icon returns with the app) until answered or removed + func test_aQuitAppStaysWaitingUntilAnsweredOrRemovedFromTheList() { + var inbox = ArrivalsInbox(pending: ["com.a", "com.b"]) + + inbox.prune(keeping: ["com.a": .visible, "com.b": .visible]) + XCTAssertEqual(inbox.pending, ["com.a", "com.b"]) + + inbox.prune(keeping: ["com.b": .visible]) + XCTAssertEqual(inbox.pending, ["com.b"]) + } + + // Given the upgrade run: the catalog has nothing persisted, the table holds the user's apps + // Then the first read announces none of them, and only a later new app waits + func test_upgrade_appsAlreadyOnTheBarAreNeverAsked() { + var catalog = MenuBarCatalogState(firstSeen: nil) + var inbox = ArrivalsInbox() + + let firstRun = catalog.apply(read: ["com.a": .visible, "com.b": .hidden], table: ["com.b": .hidden, "com.old": .alwaysHidden], now: t0) + XCTAssertEqual(inbox.receive(firstRun, choice: .ask, pinsSections: true, table: ["com.b": .hidden]), []) + XCTAssertEqual(inbox.pending, []) + + let later = catalog.apply(read: ["com.a": .visible, "com.b": .hidden, "com.new": .visible], now: t0 + 60) + _ = inbox.receive(later, choice: .ask, pinsSections: true, table: [:]) + XCTAssertEqual(inbox.pending, ["com.new"]) + } + + // Given the beta off (the table is not applied) + // Then nobody is placed or asked, and the arrival is not held for later + func test_pinnedSectionsOff_placesAndAsksNothing() { + var inbox = ArrivalsInbox() + + XCTAssertEqual(inbox.receive(["com.a"], choice: .ask, pinsSections: false, table: [:]), []) + XCTAssertEqual(inbox.receive(["com.b"], choice: .hide, pinsSections: false, table: [:]), []) + XCTAssertEqual(inbox.pending, []) + } + + // Given macOS's own extras (Control Center draws them) + // Then they are never asked about + func test_macOSExtrasAreNeverAsked() { + var inbox = ArrivalsInbox() + + XCTAssertEqual(inbox.receive([MenuBarLayoutResolver.systemExtrasBundle], choice: .ask, pinsSections: true, table: [:]), []) + XCTAssertEqual(inbox.pending, []) + } + + // MARK: lapse after 24 hours + + // Given a question under a day old + // Then it keeps waiting + func test_aQuestionUnderADayOldKeepsWaiting() { + var inbox = ArrivalsInbox(pending: ["com.a"]) + let placements = inbox.expire(now: t0 + ArrivalsInbox.expiry - 1, firstSeen: { _ in self.t0 }, choice: .hide, table: ["com.a": .visible]) + + XCTAssertEqual(placements, []) + XCTAssertEqual(inbox.pending, ["com.a"]) + } + + // Given a question a day old and the default now Hide It + // Then it lapses and the default is applied; under Ask Me the app simply stays shown + func test_aLapsedQuestionTakesTheSettingsDefault() { + var hide = ArrivalsInbox(pending: ["com.a"]) + XCTAssertEqual(hide.expire(now: t0 + ArrivalsInbox.expiry, firstSeen: { _ in self.t0 }, choice: .hide, table: ["com.a": .visible]), + [place("com.a", .hidden)]) + XCTAssertEqual(hide.pending, []) + + var ask = ArrivalsInbox(pending: ["com.a"]) + XCTAssertEqual(ask.expire(now: t0 + ArrivalsInbox.expiry, firstSeen: { _ in self.t0 }, choice: .ask, table: ["com.a": .visible]), []) + XCTAssertEqual(ask.pending, []) + } + + // Given a question whose first-seen time is unknown + // Then it is kept, not dropped on a guess + func test_aQuestionWithNoFirstSeenTimeIsKept() { + var inbox = ArrivalsInbox(pending: ["com.a"]) + _ = inbox.expire(now: t0 + 10 * ArrivalsInbox.expiry, firstSeen: { _ in nil }, choice: .ask, table: [:]) + + XCTAssertEqual(inbox.pending, ["com.a"]) + } + + // MARK: storage + + // Given the queue written under `arrivalsPending` + // Then it reads back in order, and a fresh defaults has none + func test_pendingRoundTripsThroughUserDefaults() throws { + let suite = "ArrivalsInboxTests.\(UUID().uuidString)" + let defaults = try XCTUnwrap(UserDefaults(suiteName: suite)) + defer { defaults.removePersistentDomain(forName: suite) } + let store = UserDefaultsArrivalsPending(defaults: defaults) + + XCTAssertEqual(store.bundles, []) + store.bundles = ["com.b", "com.a"] + XCTAssertEqual(UserDefaultsArrivalsPending(defaults: defaults).bundles, ["com.b", "com.a"]) + XCTAssertEqual(UserDefaultsArrivalsPending.key, "arrivalsPending") + } + + // The Settings default is stored as 0 ask, 1 show, 2 hide, and unknown values mean Show It. + func test_newAppDefaultStorage() { + XCTAssertEqual([NewAppDefault.ask, .show, .hide].map(\.rawValue), [0, 1, 2]) + XCTAssertNil(NewAppDefault.ask.section) + XCTAssertEqual(NewAppDefault.show.section, .visible) + XCTAssertEqual(NewAppDefault.hide.section, .hidden) + XCTAssertNil(NewAppDefault(rawValue: 7)) + } +} diff --git a/HiddenTests/AppStoreMigrationTests.swift b/HiddenTests/AppStoreMigrationTests.swift index af6b532d..bd622fa4 100644 --- a/HiddenTests/AppStoreMigrationTests.swift +++ b/HiddenTests/AppStoreMigrationTests.swift @@ -96,7 +96,7 @@ final class AppStoreMigrationTests: XCTestCase { UserDefaults.Key.notchOverflowEnabled, UserDefaults.Key.pauseHidingForUnkeepableItems, UserDefaults.Key.pinnedSectionsEnabled, UserDefaultsPinnedSections.key, UserDefaults.Key.revealOnScrollEnabled, UserDefaults.Key.revealOnEmptyClickEnabled, - UserDefaults.Key.revealOnShakeEnabled, + UserDefaults.Key.revealOnShakeEnabled, UserDefaults.Key.newAppDefaultSection, ] XCTAssertEqual(Set(AppStoreSettingsImport.importableKeys.keys), appKeys) } diff --git a/HiddenTests/ArrivalsControllerTests.swift b/HiddenTests/ArrivalsControllerTests.swift new file mode 100644 index 00000000..89379c68 --- /dev/null +++ b/HiddenTests/ArrivalsControllerTests.swift @@ -0,0 +1,367 @@ +// +// ArrivalsControllerTests.swift +// HiddenTests +// +// Copyright © 2026 Dwarves Foundation. All rights reserved. +// + +import XCTest +import AppKit +@testable import Hidden_Bar + +#if HIDDENBAR_NATIVE_VISIBILITY + +/// Contract: the controller turns the catalog's arrivals into placements and waiting +/// questions as the Settings default says, persists the questions under +/// `arrivalsPending`, applies an answer to the pinned-sections table, tells the arrow +/// and the Icons list when the queue changes, and never asks about an app twice. +/// Mock boundary: a throwaway UserDefaults suite, a private NotificationCenter, an +/// in-memory section table, a catalog with fixture apps and fixture reads. No +/// Accessibility, no window, no real app. +final class ArrivalsControllerTests: XCTestCase { + private final class FakeResolver: MenuBarAppResolving { + func name(of bundle: String) -> String? { bundle.replacingOccurrences(of: "com.test.", with: "").capitalized } + func icon(of bundle: String) -> NSImage? { NSImage(size: NSSize(width: 16, height: 16)) } + func isRunning(_ bundle: String) -> Bool { true } + } + + private var suite = "" + private var defaults: UserDefaults! + private var center: NotificationCenter! + private var table: InMemorySectionMemory! + private var catalog: MenuBarItemCatalog! + private var choice: NewAppDefault = .ask + private var pinsSections = true + private var clock = Date(timeIntervalSince1970: 1_000_000) + private var changes = 0 + private var observers: [NSObjectProtocol] = [] + + override func setUp() { + super.setUp() + suite = "ArrivalsControllerTests.\(UUID().uuidString)" + defaults = UserDefaults(suiteName: suite) + center = NotificationCenter() + table = InMemorySectionMemory() + choice = .ask + pinsSections = true + changes = 0 + catalog = makeCatalog() + observers = [center.addObserver(forName: .arrivalsChanged, object: nil, queue: nil) { [unowned self] _ in changes += 1 }] + } + + override func tearDown() { + observers.forEach(center.removeObserver) + defaults.removePersistentDomain(forName: suite) + super.tearDown() + } + + private func makeCatalog() -> MenuBarItemCatalog { + MenuBarItemCatalog(defaults: defaults, center: center, resolver: FakeResolver(), + pinnedTable: { [unowned self] in table.sections }, now: { [unowned self] in clock }) + } + + private func makeController(place: ((MenuBarSection, String) -> Void)? = nil) -> ArrivalsController { + let controller = ArrivalsController(defaults: defaults, center: center, table: table, + choice: { [unowned self] in choice }, pinsSections: { [unowned self] in pinsSections }, + lookup: { [unowned self] in catalog.entry(for: $0) }, + place: place ?? { [unowned self] section, bundle in table.sections[bundle] = section }, + now: { [unowned self] in clock }) + controller.start() + return controller + } + + /// One unrestricted read of the bar. The first read of a catalog seeds it. + private func read(_ bundles: [String], section: MenuBarSection = .hidden) { + let layout = MenuBarLayout(sections: Dictionary(uniqueKeysWithValues: bundles.map { ($0, section) })) + // The engine writes the table from the read before the catalog hears of it. + for bundle in bundles where table.sections[bundle] == nil { table.sections[bundle] = section } + catalog.record(layout: layout, inventory: []) + } + + private func seededController() -> ArrivalsController { + let controller = makeController() + read(["com.test.old"]) + return controller + } + + // Given Show It, when an app arrives that the table has at its hidden read position + // Then the controller writes nothing, nothing waits, and nothing is announced + func test_showIt_writesNothingAndAsksNothing() { + choice = .show + var placed: [String] = [] + let controller = makeController(place: { _, bundle in placed.append(bundle) }) + read(["com.test.old"]) + read(["com.test.old", "com.test.new"]) + + XCTAssertEqual(table.sections["com.test.new"], .hidden) + XCTAssertEqual(placed, []) + XCTAssertEqual(controller.pending, []) + XCTAssertEqual(changes, 0) + } + + // Given Hide It, when an app arrives + // Then it is placed hidden on first sight and never asked + func test_hideIt_placesHiddenAndAsksNothing() { + choice = .hide + let controller = seededController() + table.sections["com.test.new"] = .visible + read(["com.test.old", "com.test.new"], section: .visible) + + XCTAssertEqual(table.sections["com.test.new"], .hidden) + XCTAssertEqual(controller.pending, []) + } + + // Given the upgrade run (the catalog seeds on its first read) + // Then apps already on the bar are never asked, whatever the default is + func test_firstReadSeedsWithoutAsking() { + choice = .ask + let controller = makeController() + read(["com.test.a", "com.test.b"]) + + XCTAssertEqual(controller.pending, []) + XCTAssertEqual(changes, 0) + } + + // Given Ask Me, when an app arrives + // Then it waits under arrivalsPending, stays visible in the table, and the arrow and list are told + func test_askMe_keepsTheAppShownAndQueuesIt() { + let controller = seededController() + read(["com.test.old", "com.test.new"]) + + XCTAssertEqual(controller.pending, ["com.test.new"]) + XCTAssertEqual(table.sections["com.test.new"], .visible) + XCTAssertEqual(defaults.stringArray(forKey: "arrivalsPending"), ["com.test.new"]) + XCTAssertEqual(changes, 1) + } + + // Given a waiting app, when the answer is Hide + // Then the table says hidden, the entry is cleared in memory and on disk, and the arrow is told + func test_answer_writesTheSectionAndClearsTheEntry() { + let controller = seededController() + read(["com.test.old", "com.test.new"]) + + XCTAssertTrue(controller.answer("com.test.new", .hide)) + XCTAssertEqual(table.sections["com.test.new"], .hidden) + XCTAssertEqual(controller.pending, []) + XCTAssertEqual(defaults.stringArray(forKey: "arrivalsPending"), []) + XCTAssertEqual(changes, 2) + XCTAssertFalse(controller.answer("com.test.new", .show), "a stale prompt answers nothing") + XCTAssertEqual(table.sections["com.test.new"], .hidden) + } + + // Given the catalog republishing the latest arrivals after the answer (it does, on any later change) + // Then the answer stands and the app is not asked again + func test_aRepublishedArrivalNeverReAsks() { + let controller = seededController() + read(["com.test.old", "com.test.new"]) + controller.answer("com.test.new", .hide) + + controller.catalogChanged(arrivals: ["com.test.new"]) + XCTAssertEqual(controller.pending, []) + XCTAssertEqual(table.sections["com.test.new"], .hidden) + } + + // Given an answered app and a restart (new controller and catalog on the same defaults) + // Then a read of the same bar asks nothing + func test_anAppIsAskedAtMostOnce_acrossARestart() { + let first = seededController() + read(["com.test.old", "com.test.new"]) + first.answer("com.test.new", .show) + + catalog = makeCatalog() + let second = makeController() + read(["com.test.old", "com.test.new"]) + XCTAssertEqual(second.pending, []) + } + + // Given a question waiting at quit + // When Hidden Bar starts again + // Then it is still waiting, and the same read does not queue it twice + func test_aWaitingQuestionSurvivesARestart() { + let first = seededController() + read(["com.test.old", "com.test.new"]) + XCTAssertEqual(first.pending, ["com.test.new"]) + + catalog = makeCatalog() + let second = makeController() + XCTAssertEqual(second.pending, ["com.test.new"]) + read(["com.test.old", "com.test.new"]) + XCTAssertEqual(second.pending, ["com.test.new"]) + } + + // Given several apps found by one read, then Hide All + // Then each is placed hidden and nothing waits + func test_severalArrivals_hideAll() { + let controller = seededController() + read(["com.test.old", "com.test.a", "com.test.b", "com.test.c"]) + XCTAssertEqual(Set(controller.pending), ["com.test.a", "com.test.b", "com.test.c"]) + + controller.answerAll(.hide) + XCTAssertEqual(controller.pending, []) + for bundle in ["com.test.a", "com.test.b", "com.test.c"] { + XCTAssertEqual(table.sections[bundle], .hidden) + } + } + + // Given the beta off + // Then an arrival is neither placed by the controller nor asked + func test_pinnedSectionsOff_doesNothing() { + pinsSections = false + var placed: [String] = [] + let controller = makeController(place: { _, bundle in placed.append(bundle) }) + read(["com.test.old"]) + read(["com.test.old", "com.test.new"]) + + XCTAssertEqual(controller.pending, []) + XCTAssertEqual(placed, []) + } + + // Given a question a day old + // When the controller refreshes + // Then it lapses; with the default now Hide It the app goes hidden + func test_aQuestionLapsesAfterADay() { + let controller = seededController() + read(["com.test.old", "com.test.new"]) + choice = .hide + + clock += ArrivalsInbox.expiry - 1 + controller.refresh() + XCTAssertEqual(controller.pending, ["com.test.new"]) + + clock += 1 + controller.refresh() + XCTAssertEqual(controller.pending, []) + XCTAssertEqual(table.sections["com.test.new"], .hidden) + XCTAssertEqual(defaults.stringArray(forKey: "arrivalsPending"), []) + } + + // Given a waiting app the user removes from the Icons list + // Then the question goes with it + func test_removingAnAppFromTheListDropsItsQuestion() { + let controller = seededController() + read(["com.test.old", "com.test.new"]) + + table.sections.removeValue(forKey: "com.test.new") + controller.refresh() + XCTAssertEqual(controller.pending, []) + } + + // Given the default place closure + // Then an answer is written through PinnedSectionEdits.set: the table changes and the engine is told + func test_answerGoesThroughPinnedSectionEdits() { + let controller = ArrivalsController(defaults: defaults, center: center, table: table, choice: { .ask }, + pinsSections: { true }, lookup: { _ in nil }) + controller.debugInject("com.test.x") + var told = 0 + let observer = NotificationCenter.default.addObserver(forName: .pinnedSectionsChanged, object: nil, queue: nil) { _ in told += 1 } + defer { NotificationCenter.default.removeObserver(observer) } + + controller.answer("com.test.x", .alwaysHide) + XCTAssertEqual(table.sections["com.test.x"], .alwaysHidden) + XCTAssertEqual(told, 1) + } + + // Given an inventory where one app has two items + // Then its prompt row says two icons + func test_iconCountComesFromTheInventory() { + let controller = seededController() + let frame = CGRect(x: 0, y: 0, width: 20, height: 20) + controller.noteInventory([MenuBarInventoryItem(bundleIdentifier: "com.test.docker", frame: frame), + MenuBarInventoryItem(bundleIdentifier: "com.test.docker", frame: frame), + MenuBarInventoryItem(bundleIdentifier: "com.test.new", frame: frame)]) + + XCTAssertEqual(controller.info(for: "com.test.docker").iconCount, 2) + XCTAssertEqual(controller.info(for: "com.test.new").iconCount, 1) + XCTAssertEqual(controller.info(for: "com.test.unknown").iconCount, 1) + } +} + +/// The prompt as the board draws it: what it says and what its buttons do. +final class ArrivalsPromptTests: XCTestCase { + private let now = Date(timeIntervalSince1970: 1_000_000) + + private func info(_ bundle: String, ago: TimeInterval = 5, running: Bool = true, icons: Int = 1) -> ArrivalInfo { + ArrivalInfo(bundle: bundle, name: bundle.capitalized, icon: NSImage(), firstSeen: now.addingTimeInterval(-ago), + isRunning: running, iconCount: icons) + } + + private func views(in root: NSView) -> [NSView] { + root.subviews + root.subviews.flatMap { views(in: $0) } + } + + // Given one to three waiting apps + // Then the title is the board's, every app has a row, and the footer is the hint + func test_fewArrivals_listEachAndHint() { + let model = ArrivalsPromptModel.make(infos: [info("raycast"), info("tailscale", ago: 7200)], now: now) + + XCTAssertEqual(model.title, "New in your menu bar") + XCTAssertEqual(model.rows.map(\.name), ["Raycast", "Tailscale"]) + XCTAssertEqual(model.rows.map(\.caption), ["Added an icon just now", "Added an icon 2 hours ago"]) + XCTAssertEqual(model.footer, .hint) + } + + // Given six waiting apps + // Then three show, the title counts them, and the footer says "and 3 more" with bulk answers + func test_manyArrivals_showThreeAndABulkFooter() { + let model = ArrivalsPromptModel.make(infos: (1...6).map { info("app\($0)") }, now: now) + + XCTAssertEqual(model.title, "6 new apps in your menu bar") + XCTAssertEqual(model.rows.count, 3) + XCTAssertEqual(model.footer, .bulk(more: 3)) + } + + // Given an app with two icons, and one that is not running + // Then the first says they move together, the second that it stays shown until chosen + func test_edgeCaptions() { + XCTAssertEqual(ArrivalsPromptModel.caption(for: info("docker", icons: 2), now: now), "Added 2 icons. They show or hide together.") + XCTAssertEqual(ArrivalsPromptModel.caption(for: info("gone", running: false, icons: 2), now: now), + "Not running now. It stays shown until you choose.") + } + + // Given the prompt for two apps + // When pressing Hide in one row, Always hide in another, and Hide All + // Then each press reports the app and the answer + func test_buttonsReportAnswers() throws { + let view = ArrivalsPromptView(model: ArrivalsPromptModel.make(infos: [info("a"), info("b")], now: now)) + var answers: [String] = [] + view.onAnswer = { bundle, answer in answers.append("\(bundle):\(answer)") } + let all = views(in: view) + + let segments = try XCTUnwrap(all.compactMap { $0 as? NSSegmentedControl }.first { $0.identifier?.rawValue == ArrivalsPromptView.showIdentifier("a") }) + segments.selectedSegment = 1 + segments.sendAction(segments.action, to: segments.target) + segments.selectedSegment = 0 + segments.sendAction(segments.action, to: segments.target) + + let more = try XCTUnwrap(all.compactMap { $0 as? NSButton }.first { $0.identifier?.rawValue == ArrivalsPromptView.alwaysHideIdentifier("b") }) + let item = try XCTUnwrap(more.menu?.items.first) + XCTAssertEqual(item.title, "Always hide") + _ = item.target?.perform(item.action, with: item) + + XCTAssertEqual(answers, ["a:hide", "a:show", "b:alwaysHide"]) + } + + // Given six apps, when pressing Hide All and Show All + // Then the bulk callback gets each answer + func test_bulkButtons() throws { + let view = ArrivalsPromptView(model: ArrivalsPromptModel.make(infos: (1...5).map { info("app\($0)") }, now: now)) + var bulk: [ArrivalAnswer] = [] + view.onAnswerAll = { bulk.append($0) } + let buttons = views(in: view).compactMap { $0 as? NSButton } + try XCTUnwrap(buttons.first { $0.identifier?.rawValue == ArrivalsPromptView.hideAllIdentifier }).performClick(nil) + try XCTUnwrap(buttons.first { $0.identifier?.rawValue == ArrivalsPromptView.showAllIdentifier }).performClick(nil) + + XCTAssertEqual(bulk, [.hide, .show]) + } + + // The prompt is drawn at the board's width and grows with its rows. + func test_promptSizeFollowsItsRows() { + let few = ArrivalsPromptView(model: ArrivalsPromptModel.make(infos: [info("a")], now: now)).fittingContentSize + let more = ArrivalsPromptView(model: ArrivalsPromptModel.make(infos: [info("a"), info("b"), info("c")], now: now)).fittingContentSize + + XCTAssertEqual(few.width, ArrivalsPromptView.width) + XCTAssertGreaterThan(more.height, few.height + 80) + } +} + +#endif diff --git a/HiddenTests/SettingsWindowTests.swift b/HiddenTests/SettingsWindowTests.swift index f103c63f..0e81ec53 100644 --- a/HiddenTests/SettingsWindowTests.swift +++ b/HiddenTests/SettingsWindowTests.swift @@ -40,6 +40,7 @@ final class SettingsWindowTests: XCTestCase { UserDefaults.Key.arrowStyle, // arrow style popup UserDefaults.Key.globalKey, // global shortcut UserDefaultsPinnedSections.key, // Icons section popups (beta) + UserDefaults.Key.newAppDefaultSection, // Icons: when an app adds a new icon ] private var saved: [String: Any] = [:] @@ -223,7 +224,7 @@ final class SettingsWindowTests: XCTestCase { let views = allViews(PreferencesWindowController(context: context)) for key in [UserDefaults.Key.pauseHidingForUnkeepableItems, UserDefaults.Key.showWholeBarWhenCaptureStarts, UserDefaults.Key.pinnedSectionsEnabled, UserDefaults.Key.revealOnEmptyClickEnabled, - "SUEnableAutomaticChecks"] { + UserDefaults.Key.newAppDefaultSection, "SUEnableAutomaticChecks"] { XCTAssertNil(control(key, in: views), "\(key) shows in the App Store build") } // Scroll and shake need no Accessibility, so the App Store build keeps them. @@ -300,7 +301,8 @@ final class SettingsWindowTests: XCTestCase { XCTAssertFalse(button.isBordered, "a link in the caption line, so the controls column is the same on every row") XCTAssertEqual(views.compactMap { ($0 as? NSTextField)?.stringValue }.filter { $0.hasPrefix("Not running".localized) }.count, 1) pane.view.layoutSubtreeIfNeeded() - let edges = Set(views.compactMap { $0 as? NSPopUpButton }.map { $0.superview?.frame.minX ?? 0 }) + let sectionPopups = views.compactMap { $0 as? NSPopUpButton }.filter { $0.identifier?.rawValue != UserDefaults.Key.newAppDefaultSection } + let edges = Set(sectionPopups.map { $0.superview?.frame.minX ?? 0 }) XCTAssertEqual(edges.count, 1, "the controls column starts at the same x on every row") XCTAssertGreaterThan(edges.first ?? 0, 0, "the pane was laid out") XCTAssertEqual(store.runningReads, 1, "the running set is read once per rebuild, not per row") @@ -327,6 +329,104 @@ final class SettingsWindowTests: XCTestCase { XCTAssertEqual(store.runningReads, 3, "one read per appearance") } + // Given the Icons pane + // When picking Ask Me, then Hide It, then Show It in "When an app adds a new icon" + // Then newAppDefaultSection holds 0, 2, 1, and the popup starts on Show It when nothing is stored + func test_menuBarApps_newAppPopupWritesItsKey() throws { + UserDefaults.standard.set(true, forKey: UserDefaults.Key.pinnedSectionsEnabled) + UserDefaults.standard.removeObject(forKey: UserDefaults.Key.newAppDefaultSection) + var context = fullContext() + MenuBarAppsPane.makeViewController = { MenuBarAppsSettingsViewController(context: context) } + context.menuBarAppsAvailable = true + let controller = PreferencesWindowController(context: context) + windows.append(controller) + let views = Self.subviews(of: controller.pane(.menuBarApps).view) + let popup = try XCTUnwrap(control(UserDefaults.Key.newAppDefaultSection, in: views) as? NSPopUpButton) + + XCTAssertEqual(popup.selectedItem?.tag, NewAppDefault.show.rawValue) + XCTAssertEqual(popup.itemTitles, ["Ask Me", "Show It", "Hide It"]) + for choice in [NewAppDefault.ask, .hide, .show] { + popup.selectItem(withTag: choice.rawValue) + popup.sendAction(popup.action, to: popup.target) + XCTAssertEqual(UserDefaults.standard.integer(forKey: UserDefaults.Key.newAppDefaultSection), choice.rawValue) + XCTAssertEqual(Preferences.newAppDefaultSection, choice) + } + } + + // Given the Icons pane + // When picking each option in the new-app popup + // Then the caption under the title describes that option + func test_menuBarApps_newAppCaptionFollowsTheSelectedOption() throws { + UserDefaults.standard.set(true, forKey: UserDefaults.Key.pinnedSectionsEnabled) + UserDefaults.standard.removeObject(forKey: UserDefaults.Key.newAppDefaultSection) + let pane = MenuBarAppsSettingsViewController(context: fullContext()) + let views = Self.subviews(of: pane.view) + let popup = try XCTUnwrap(control(UserDefaults.Key.newAppDefaultSection, in: views) as? NSPopUpButton) + func captions() -> [String] { Self.subviews(of: pane.view).compactMap { ($0 as? NSTextField)?.stringValue } } + + XCTAssertTrue(captions().contains(MenuBarAppsSettingsViewController.newAppCaption(for: .show))) + for choice in [NewAppDefault.ask, .hide, .show] { + popup.selectItem(withTag: choice.rawValue) + popup.sendAction(popup.action, to: popup.target) + let shown = captions() + XCTAssertTrue(shown.contains(MenuBarAppsSettingsViewController.newAppCaption(for: choice)), "\(choice) caption missing") + for other in [NewAppDefault.ask, .show, .hide] where other != choice { + XCTAssertFalse(shown.contains(MenuBarAppsSettingsViewController.newAppCaption(for: other)), "\(other) caption still shown") + } + } + XCTAssertEqual(Set([NewAppDefault.ask, .show, .hide].map(MenuBarAppsSettingsViewController.newAppCaption)).count, 3) + } + + // Given a stored value outside 0 to 2, or none + // Then the preference reads as Show It, the 1.12 behavior + func test_newAppDefaultReadsShowItUnlessSet() { + UserDefaults.standard.removeObject(forKey: UserDefaults.Key.newAppDefaultSection) + XCTAssertEqual(Preferences.newAppDefaultSection, .show) + UserDefaults.standard.set(9, forKey: UserDefaults.Key.newAppDefaultSection) + XCTAssertEqual(Preferences.newAppDefaultSection, .show) + UserDefaults.standard.set(0, forKey: UserDefaults.Key.newAppDefaultSection) + XCTAssertEqual(Preferences.newAppDefaultSection, .ask) + } + + // Given the beta off + // Then the new-app popup is there but cannot be changed (nothing places a new app) + func test_menuBarApps_newAppPopupIsDisabledWithPinnedSectionsOff() throws { + UserDefaults.standard.set(false, forKey: UserDefaults.Key.pinnedSectionsEnabled) + var context = fullContext() + MenuBarAppsPane.makeViewController = { MenuBarAppsSettingsViewController(context: context) } + context.menuBarAppsAvailable = true + let controller = PreferencesWindowController(context: context) + windows.append(controller) + let popup = try XCTUnwrap(control(UserDefaults.Key.newAppDefaultSection, + in: Self.subviews(of: controller.pane(.menuBarApps).view)) as? NSPopUpButton) + + XCTAssertFalse(popup.isEnabled) + } + + // Given two apps waiting for an answer and two that are settled + // When the Icons pane builds + // Then the waiting ones come first, each with a NEW tag, and the settled ones have none + func test_menuBarApps_undecidedAppsSitFirstWithANewTag() { + let waitingKey = UserDefaultsArrivalsPending.key + let before = UserDefaults.standard.object(forKey: waitingKey) + addTeardownBlock { + if let before { UserDefaults.standard.set(before, forKey: waitingKey) } else { UserDefaults.standard.removeObject(forKey: waitingKey) } + } + UserDefaults.standard.set(true, forKey: UserDefaults.Key.pinnedSectionsEnabled) + UserDefaults.standard.set(["com.test.a": 0, "com.test.b": 1, "com.test.z": 0, "com.test.y": 0], forKey: UserDefaultsPinnedSections.key) + UserDefaults.standard.set(["com.test.z", "com.test.y"], forKey: waitingKey) + let pane = MenuBarAppsSettingsViewController(context: fullContext()) + let views = Self.subviews(of: pane.view) + + XCTAssertEqual(views.filter { $0 is NewTag }.count, 2) + let prefix = UserDefaultsPinnedSections.key + "." + let order = views.compactMap { ($0 as? NSPopUpButton)?.identifier?.rawValue } + .filter { $0.hasPrefix(prefix) }.map { String($0.dropFirst(prefix.count)) } + XCTAssertEqual(order, ["com.test.y", "com.test.z", "com.test.a", "com.test.b"]) + XCTAssertTrue(views.contains { ($0 as? NSTextField)?.stringValue.hasPrefix("Not chosen yet".localized) == true }) + XCTAssertEqual(UserDefaults.Key.arrivalsPending, waitingKey) + } + // Given the beta off // When opening Icons // Then it says so and lists no app diff --git a/hidden/Common/Preferences.swift b/hidden/Common/Preferences.swift index a6024acb..b27fd776 100644 --- a/hidden/Common/Preferences.swift +++ b/hidden/Common/Preferences.swift @@ -231,4 +231,17 @@ enum Preferences { NotificationCenter.default.post(Notification(name: .prefsChanged)) } } + + // macOS 27, direct build: what happens to an app that adds its first icon. + // Show It (the 1.12 behavior) unless the user picks otherwise. + static var newAppDefaultSection: NewAppDefault { + get { + NewAppDefault(rawValue: UserDefaults.standard.object(forKey: UserDefaults.Key.newAppDefaultSection) as? Int ?? NewAppDefault.show.rawValue) ?? .show + } + + set { + UserDefaults.standard.set(newValue.rawValue, forKey: UserDefaults.Key.newAppDefaultSection) + NotificationCenter.default.post(Notification(name: .prefsChanged)) + } + } } diff --git a/hidden/Extensions/UserDefault+Extension.swift b/hidden/Extensions/UserDefault+Extension.swift index e97ddb29..1e1ef19a 100644 --- a/hidden/Extensions/UserDefault+Extension.swift +++ b/hidden/Extensions/UserDefault+Extension.swift @@ -28,7 +28,9 @@ extension UserDefaults { static let pauseHidingForUnkeepableItems = "pauseHidingForUnkeepableItems" static let showWholeBarWhenCaptureStarts = "showWholeBarWhenCaptureStarts" static let pinnedSectionsEnabled = "pinnedSectionsEnabled" + static let newAppDefaultSection = "newAppDefaultSection" // Internal: not user-facing, so not in the App Store import whitelist. static let menuBarCatalogFirstSeen = "menuBarCatalogFirstSeen" + static let arrivalsPending = "arrivalsPending" } } diff --git a/hidden/Features/AppStoreMigration/AppStoreMigration.swift b/hidden/Features/AppStoreMigration/AppStoreMigration.swift index f1a0d1ea..6c9db608 100644 --- a/hidden/Features/AppStoreMigration/AppStoreMigration.swift +++ b/hidden/Features/AppStoreMigration/AppStoreMigration.swift @@ -57,6 +57,7 @@ enum AppStoreSettingsImport { UserDefaults.Key.notchOverflowEnabled: .number, UserDefaults.Key.pauseHidingForUnkeepableItems: .number, UserDefaults.Key.pinnedSectionsEnabled: .number, + UserDefaults.Key.newAppDefaultSection: .number, UserDefaultsPinnedSections.key: .dictionary, ] diff --git a/hidden/Features/Arrivals/ArrivalsController.swift b/hidden/Features/Arrivals/ArrivalsController.swift new file mode 100644 index 00000000..3d5accd7 --- /dev/null +++ b/hidden/Features/Arrivals/ArrivalsController.swift @@ -0,0 +1,164 @@ +// +// ArrivalsController.swift +// Hidden Bar +// +// Copyright © 2026 Dwarves Foundation. All rights reserved. +// + +#if HIDDENBAR_NATIVE_VISIBILITY +import AppKit + +extension Notification.Name { + // Posted on the main thread when the waiting arrivals change (a new one, an + // answer, a lapse). The arrow's dot and the Icons list follow it. + static let arrivalsChanged = Notification.Name("arrivalsChanged") +} + +// What the controller knows about one app, for the prompt. +struct ArrivalInfo { + let bundle: String + let name: String + let icon: NSImage + let firstSeen: Date + let isRunning: Bool + let iconCount: Int +} + +// Puts the inbox's decisions to work: it listens for the catalog's arrivals, +// applies the Settings default through `PinnedSectionEdits.set` (the same write +// the Icons list makes, so the engine follows at once), keeps the questions that +// wait under `arrivalsPending`, and applies answers. No window, no banner, no +// permission: the prompt itself is drawn by ArrivalsPresenter, from the arrow. +final class ArrivalsController { + static let shared = ArrivalsController() + + private(set) var inbox: ArrivalsInbox + // Items per app in the latest unrestricted read: Docker Desktop shows two. + private var iconCounts: [String: Int] = [:] + + private let store: UserDefaultsArrivalsPending + private let center: NotificationCenter + private let table: MenuBarSectionMemory + private let choice: () -> NewAppDefault + private let pinsSections: () -> Bool + private let lookup: (String) -> MenuBarCatalogEntry? + private let place: (MenuBarSection, String) -> Void + private let now: () -> Date + private var observer: NSObjectProtocol? + + init(defaults: UserDefaults = .standard, + center: NotificationCenter = .default, + table: MenuBarSectionMemory = UserDefaultsPinnedSections(defaults: .standard), + choice: @escaping () -> NewAppDefault = { Preferences.newAppDefaultSection }, + pinsSections: @escaping () -> Bool = { Preferences.pinnedSectionsEnabled }, + lookup: @escaping (String) -> MenuBarCatalogEntry? = { MenuBarItemCatalog.shared.entry(for: $0) }, + place: ((MenuBarSection, String) -> Void)? = nil, + now: @escaping () -> Date = Date.init) { + self.store = UserDefaultsArrivalsPending(defaults: defaults) + self.center = center + self.table = table + self.choice = choice + self.pinsSections = pinsSections + self.lookup = lookup + self.place = place ?? { section, bundle in PinnedSectionEdits.set(section, for: bundle, in: table) } + self.now = now + inbox = ArrivalsInbox(pending: store.bundles) + } + + deinit { + observer.map(center.removeObserver) + } + + // Starts listening. Safe to call twice. + func start() { + guard observer == nil else { return } + observer = center.addObserver(forName: .menuBarCatalogChanged, object: nil, queue: nil) { [weak self] note in + let arrivals = note.userInfo?[MenuBarItemCatalog.arrivalsKey] as? [String] ?? [] + self?.catalogChanged(arrivals: arrivals) + } + refresh() + } + + var pending: [String] { inbox.pending } + + // The engine's raw read, before the catalog folds it in: how many icons each app has. + func noteInventory(_ inventory: [MenuBarInventoryItem]) { + var counts: [String: Int] = [:] + for item in inventory { + if let bundle = item.bundleIdentifier { counts[bundle, default: 0] += 1 } + } + iconCounts = counts + } + + // A read found these apps for the first time (or the catalog republished the latest list). + func catalogChanged(arrivals: [String]) { + var next = inbox + let placements = next.receive(arrivals, choice: choice(), pinsSections: pinsSections(), table: table.sections) + apply(next, placements: placements) + } + + // Lapsed questions, and questions about apps the user removed from the Icons list. + func refresh() { + var next = inbox + next.prune(keeping: table.sections) + let placements = next.expire(now: now(), firstSeen: { self.lookup($0)?.firstSeen }, choice: choice(), table: table.sections) + apply(next, placements: placements) + } + + @discardableResult + func answer(_ bundle: String, _ answer: ArrivalAnswer) -> Bool { + var next = inbox + guard let placement = next.answer(bundle, answer) else { return false } + apply(next, placements: [placement]) + return true + } + + func answerAll(_ answer: ArrivalAnswer) { + var next = inbox + let placements = next.answerAll(answer) + apply(next, placements: placements) + } + + // The waiting apps, newest first, as the prompt lists them. + func waiting() -> [ArrivalInfo] { + let infos = inbox.pending.map(info(for:)) + return infos.sorted { $0.firstSeen > $1.firstSeen } + } + + func info(for bundle: String) -> ArrivalInfo { + let count = max(iconCounts[bundle] ?? 1, 1) + if let entry = lookup(bundle) { + return ArrivalInfo(bundle: bundle, name: entry.name, icon: entry.icon, firstSeen: entry.firstSeen, + isRunning: entry.isRunning, iconCount: count) + } + let resolver = WorkspaceAppResolver() + return ArrivalInfo(bundle: bundle, name: resolver.name(of: bundle) ?? bundle, + icon: resolver.icon(of: bundle) ?? NSWorkspace.shared.icon(for: .applicationBundle), + firstSeen: now(), isRunning: resolver.isRunning(bundle), iconCount: count) + } + + private func apply(_ next: ArrivalsInbox, placements: [ArrivalsInbox.Placement]) { + let changed = next.pending != inbox.pending + inbox = next + if changed { store.bundles = next.pending } + for placement in placements { + place(placement.section, placement.bundle) + } + if changed { center.post(name: .arrivalsChanged, object: self) } + } + + #if DEBUG + // `arrivals-inject `: asks about a bundle as if a read had just found + // it. It is placed visible, as Ask Me does. + func debugInject(_ bundle: String) { + var next = inbox + next.inject(bundle) + apply(next, placements: [ArrivalsInbox.Placement(bundle: bundle, section: .visible)]) + } + + var debugState: [String: Any] { + return ["arrivalsPending": inbox.pending, "newAppDefaultSection": choice().rawValue] + } + #endif +} +#endif diff --git a/hidden/Features/Arrivals/ArrivalsInbox.swift b/hidden/Features/Arrivals/ArrivalsInbox.swift new file mode 100644 index 00000000..2c8087c1 --- /dev/null +++ b/hidden/Features/Arrivals/ArrivalsInbox.swift @@ -0,0 +1,148 @@ +// +// ArrivalsInbox.swift +// Hidden Bar +// +// Copyright © 2026 Dwarves Foundation. All rights reserved. +// + +import Foundation + +// What happens to an app that adds its first icon (macOS 27, direct build). +// Raw values are the stored `newAppDefaultSection`: 1 is the 1.12 behavior. +enum NewAppDefault: Int, Equatable { + case ask = 0 + case show = 1 + case hide = 2 + + // The section a never-seen app goes to without asking; nil when it is asked. + var section: MenuBarSection? { + switch self { + case .ask: return nil + case .show: return .visible + case .hide: return .hidden + } + } +} + +// The answer to "show or hide?" in the arrivals prompt. +enum ArrivalAnswer: Equatable { + case show + case hide + case alwaysHide + + var section: MenuBarSection { + switch self { + case .show: return .visible + case .hide: return .hidden + case .alwaysHide: return .alwaysHidden + } + } +} + +// The decision logic of the arrivals inbox, free of AppKit and storage: which +// first-seen apps wait for an answer, where each one goes, and when a question +// lapses. The caller reads the arrivals from MenuBarItemCatalog (an app is an +// arrival only the first time it is ever read, and the first run of the +// catalog records the apps already on the bar without announcing them, so an +// upgrade asks about nothing) and writes the placements it returns. +struct ArrivalsInbox: Equatable { + // A question that nobody answers lapses after this long and the default applies. + static let expiry: TimeInterval = 24 * 60 * 60 + + struct Placement: Equatable { + let bundle: String + let section: MenuBarSection + } + + // Bundle ids waiting for an answer, oldest first. Persisted. + private(set) var pending: [String] + // Arrivals this run has already dealt with. A catalog notification repeats the + // latest read's arrivals on every later publish; handling each bundle once keeps + // a repeat from undoing an answer or the user's own edit. + private var handled: Set = [] + + init(pending: [String] = []) { + self.pending = pending + } + + // Apps a read found for the first time. Returns the sections to write. + // `pinsSections` false (the beta is off): the table is not applied, so nobody + // is placed or asked. Ask Me keeps the app shown until it is answered; Show It places nothing. + mutating func receive(_ arrivals: [String], choice: NewAppDefault, pinsSections: Bool, + table: [String: MenuBarSection]) -> [Placement] { + var placements: [Placement] = [] + for bundle in arrivals where Self.isAskable(bundle) && handled.insert(bundle).inserted { + // Show It is 1.12 exactly: the engine's resolver already places a never-seen + // app (launched apps visible, others at their read position), and a pinned + // entry this catalog never saw stays as it is. + guard pinsSections, choice != .show else { continue } + let section = choice.section ?? .visible + if choice == .ask, !pending.contains(bundle) { + pending.append(bundle) + } + if table[bundle] != section { + placements.append(Placement(bundle: bundle, section: section)) + } + } + return placements + } + + // The user's answer for one waiting app. Nil when it is not waiting. + mutating func answer(_ bundle: String, _ answer: ArrivalAnswer) -> Placement? { + guard let index = pending.firstIndex(of: bundle) else { return nil } + pending.remove(at: index) + return Placement(bundle: bundle, section: answer.section) + } + + // "Show All" / "Hide All": one answer for everything waiting. + mutating func answerAll(_ answer: ArrivalAnswer) -> [Placement] { + let answered = pending.map { Placement(bundle: $0, section: answer.section) } + pending = [] + return answered + } + + // Drops the questions that are over their time. The Settings default applies to + // them; Ask Me leaves the app where it is, shown. + mutating func expire(now: Date, firstSeen: (String) -> Date?, choice: NewAppDefault, + table: [String: MenuBarSection]) -> [Placement] { + let lapsed = pending.filter { bundle in + firstSeen(bundle).map { now.timeIntervalSince($0) >= Self.expiry } ?? false + } + guard !lapsed.isEmpty else { return [] } + pending.removeAll { lapsed.contains($0) } + guard let section = choice.section else { return [] } + return lapsed.filter { table[$0] != section }.map { Placement(bundle: $0, section: section) } + } + + // An app the user removed from the Icons list is no question any more. + mutating func prune(keeping table: [String: MenuBarSection]) { + pending.removeAll { table[$0] == nil } + } + + // Debug hook: asks about a bundle as if a read had found it. + mutating func inject(_ bundle: String) { + handled.insert(bundle) + if !pending.contains(bundle) { pending.append(bundle) } + } + + // macOS's own extras are drawn by Control Center: there is no app to ask about. + static func isAskable(_ bundle: String) -> Bool { + return MenuBarCatalogState.isCataloged(bundle) + } +} + +// The pending questions, kept across launches under `arrivalsPending`. +struct UserDefaultsArrivalsPending { + // Equal to UserDefaults.Key.arrivalsPending; written out so the logic tests need no Preferences code. + static let key = "arrivalsPending" + private let defaults: UserDefaults + + init(defaults: UserDefaults = .standard) { + self.defaults = defaults + } + + var bundles: [String] { + get { defaults.stringArray(forKey: Self.key) ?? [] } + nonmutating set { defaults.set(newValue, forKey: Self.key) } + } +} diff --git a/hidden/Features/Arrivals/ArrivalsPresenter.swift b/hidden/Features/Arrivals/ArrivalsPresenter.swift new file mode 100644 index 00000000..8040a308 --- /dev/null +++ b/hidden/Features/Arrivals/ArrivalsPresenter.swift @@ -0,0 +1,111 @@ +// +// ArrivalsPresenter.swift +// Hidden Bar +// +// Copyright © 2026 Dwarves Foundation. All rights reserved. +// + +#if HIDDENBAR_NATIVE_VISIBILITY +import AppKit + +// The dot on the arrow that says an app is waiting for an answer. +final class ArrivalsArrowDot: NSView { + static let diameter: CGFloat = 7 + + override var isFlipped: Bool { true } + override func hitTest(_ point: NSPoint) -> NSView? { nil } + + override func draw(_ dirtyRect: NSRect) { + NSColor.controlAccentColor.setFill() + NSBezierPath(ovalIn: bounds).fill() + } + + // Puts the dot top-right on `button`, or takes it away. + static func sync(on button: NSStatusBarButton?, visible: Bool) { + guard let button else { return } + let existing = button.subviews.compactMap { $0 as? ArrivalsArrowDot }.first + guard visible else { + existing?.removeFromSuperview() + return + } + guard existing == nil else { return } + let dot = ArrivalsArrowDot(frame: NSRect(x: button.bounds.maxX - diameter - 1, y: 2, width: diameter, height: diameter)) + dot.autoresizingMask = [.minXMargin, .maxYMargin] + dot.setAccessibilityElement(false) + button.addSubview(dot) + } +} + +// Asks from the arrow: a popover under it with one row per waiting app. It opens +// when the user clicks the arrow while something waits (the click that shows the +// hidden icons), and it stays until it is answered or clicked away; the dot on +// the arrow stays while anything waits. +final class ArrivalsPresenter: NSObject, NSPopoverDelegate { + private let controller: ArrivalsController + private let openSettings: () -> Void + private var popover: NSPopover? + private var promptView: ArrivalsPromptView? + private var observer: NSObjectProtocol? + + init(controller: ArrivalsController = .shared, openSettings: @escaping () -> Void) { + self.controller = controller + self.openSettings = openSettings + super.init() + observer = NotificationCenter.default.addObserver(forName: .arrivalsChanged, object: nil, queue: .main) { [weak self] _ in + // Not inside the button action that caused the change. + DispatchQueue.main.async { self?.reload() } + } + } + + deinit { + observer.map(NotificationCenter.default.removeObserver) + } + + var isShown: Bool { popover?.isShown ?? false } + + func present(from button: NSStatusBarButton?) { + guard let button, !isShown, !controller.pending.isEmpty else { return } + controller.refresh() + guard !controller.pending.isEmpty else { return } + let view = makeView() + let content = NSViewController() + content.view = view + let popover = NSPopover() + popover.behavior = .transient + popover.contentViewController = content + popover.contentSize = view.fittingContentSize + popover.delegate = self + self.popover = popover + promptView = view + popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY) + } + + func close() { + popover?.close() + } + + func popoverDidClose(_ notification: Notification) { + popover = nil + promptView = nil + } + + private func makeView() -> ArrivalsPromptView { + let view = ArrivalsPromptView(model: ArrivalsPromptModel.make(infos: controller.waiting(), now: Date())) + view.onAnswer = { [weak self] bundle, answer in self?.controller.answer(bundle, answer) } + view.onAnswerAll = { [weak self] answer in self?.controller.answerAll(answer) } + view.onOpenSettings = { [weak self] in + self?.close() + self?.openSettings() + } + return view + } + + // The queue changed while the popover is open: redraw it, or close it when it is empty. + private func reload() { + guard let popover, let promptView else { return } + guard !controller.pending.isEmpty else { return popover.close() } + promptView.update(ArrivalsPromptModel.make(infos: controller.waiting(), now: Date())) + popover.contentSize = promptView.fittingContentSize + } +} +#endif diff --git a/hidden/Features/Arrivals/ArrivalsPromptView.swift b/hidden/Features/Arrivals/ArrivalsPromptView.swift new file mode 100644 index 00000000..6af60f75 --- /dev/null +++ b/hidden/Features/Arrivals/ArrivalsPromptView.swift @@ -0,0 +1,323 @@ +// +// ArrivalsPromptView.swift +// Hidden Bar +// +// Copyright © 2026 Dwarves Foundation. All rights reserved. +// + +#if HIDDENBAR_NATIVE_VISIBILITY +import AppKit + +// What the prompt shows, decided apart from any view so a test can read it. +struct ArrivalsPromptModel { + enum Style: Equatable { + // Show / Hide, and Always hide behind the ellipsis. + case question + // A known app came back where the user put it: told, not asked. + case kept + // Something Hidden Bar cannot keep shown: told once, OK. + case notice + } + + struct Row { + let bundle: String + let name: String + let caption: String + let icon: NSImage + let style: Style + } + + enum Footer: Equatable { + // "Not sure?" and a way to Settings. + case hint + // "and N more", with one answer for everything waiting. + case bulk(more: Int) + case text(String) + case none + } + + var title: String + var subtitle: String? + var rows: [Row] + var footer: Footer + + // More than this and the rest sit behind "and N more" with Hide All / Show All. + static let visibleRows = 3 + + // `infos` is newest first. + static func make(infos: [ArrivalInfo], now: Date) -> ArrivalsPromptModel { + let more = max(infos.count - visibleRows, 0) + let title = infos.count > visibleRows + ? String(format: "%d new apps in your menu bar".localized, infos.count) + : "New in your menu bar".localized + let rows = infos.prefix(visibleRows).map { + Row(bundle: $0.bundle, name: $0.name, caption: caption(for: $0, now: now), icon: $0.icon, style: .question) + } + return ArrivalsPromptModel(title: title, + subtitle: "Choose once. Hidden Bar remembers, also after the app or your Mac restarts.".localized, + rows: rows, footer: more > 0 ? .bulk(more: more) : .hint) + } + + static func caption(for info: ArrivalInfo, now: Date) -> String { + if !info.isRunning { + return "Not running now. It stays shown until you choose.".localized + } + if info.iconCount > 1 { + return String(format: "Added %d icons. They show or hide together.".localized, info.iconCount) + } + return String(format: "Added an icon %@".localized, since(info.firstSeen, now: now)) + } + + static func since(_ date: Date, now: Date) -> String { + guard now.timeIntervalSince(date) >= 60 else { return "just now".localized } + let formatter = RelativeDateTimeFormatter() + formatter.unitsStyle = .full + return formatter.localizedString(for: date, relativeTo: now) + } +} + +// The inbox as the board draws it: a title, one row per waiting app with Show and +// Hide (and Always hide behind the ellipsis), and a footer. It owns no state. +final class ArrivalsPromptView: NSView { + static let width: CGFloat = 360 + static let padding: CGFloat = 12 + + static func showIdentifier(_ bundle: String) -> String { "arrivalsAnswer.\(bundle)" } + static func alwaysHideIdentifier(_ bundle: String) -> String { "arrivalsAlwaysHide.\(bundle)" } + static func okIdentifier(_ bundle: String) -> String { "arrivalsOK.\(bundle)" } + static let hideAllIdentifier = "arrivalsHideAll" + static let showAllIdentifier = "arrivalsShowAll" + static let settingsIdentifier = "arrivalsSettings" + + var onAnswer: (String, ArrivalAnswer) -> Void = { _, _ in } + var onAnswerAll: (ArrivalAnswer) -> Void = { _ in } + var onDismiss: (String) -> Void = { _ in } + var onOpenSettings: () -> Void = {} + + private(set) var model: ArrivalsPromptModel + private let stack = NSStackView() + + init(model: ArrivalsPromptModel) { + self.model = model + super.init(frame: .zero) + translatesAutoresizingMaskIntoConstraints = false + stack.orientation = .vertical + stack.alignment = .leading + stack.spacing = 0 + stack.translatesAutoresizingMaskIntoConstraints = false + addSubview(stack) + let pad = Self.padding + NSLayoutConstraint.activate([ + widthAnchor.constraint(equalToConstant: Self.width), + stack.topAnchor.constraint(equalTo: topAnchor, constant: pad), + stack.leadingAnchor.constraint(equalTo: leadingAnchor, constant: pad), + stack.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -pad), + stack.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -pad), + ]) + build() + } + + required init?(coder: NSCoder) { fatalError("init(coder:) is not used") } + + func update(_ model: ArrivalsPromptModel) { + self.model = model + stack.arrangedSubviews.forEach { $0.removeFromSuperview() } + build() + } + + // The size the popover needs. + var fittingContentSize: NSSize { + layoutSubtreeIfNeeded() + return NSSize(width: Self.width, height: fittingSize.height) + } + + private var innerWidth: CGFloat { Self.width - 2 * Self.padding } + + private func build() { + let title = NSTextField(labelWithString: model.title) + title.font = .systemFont(ofSize: 13.5, weight: .semibold) + add(title, spacingAfter: model.subtitle == nil ? 8 : 2) + if let subtitle = model.subtitle { + let sub = NSTextField(wrappingLabelWithString: subtitle) + sub.font = .systemFont(ofSize: 11.5) + sub.textColor = .secondaryLabelColor + sub.preferredMaxLayoutWidth = innerWidth + add(sub, spacingAfter: 4) + } + for row in model.rows { + add(separator(), fullWidth: true) + add(rowView(row), fullWidth: true) + } + if model.footer != .none { + add(separator(), fullWidth: true) + add(footerView(), fullWidth: true) + } + } + + private func add(_ view: NSView, spacingAfter: CGFloat = 0, fullWidth: Bool = false) { + view.translatesAutoresizingMaskIntoConstraints = false + stack.addArrangedSubview(view) + stack.setCustomSpacing(spacingAfter, after: view) + if fullWidth { view.widthAnchor.constraint(equalToConstant: innerWidth).isActive = true } + } + + private func separator() -> NSView { + let line = NSBox() + line.boxType = .separator + return line + } + + private func rowView(_ row: ArrivalsPromptModel.Row) -> NSView { + let icon = NSImageView(image: row.icon) + icon.imageScaling = .scaleProportionallyUpOrDown + icon.wantsLayer = true + icon.layer?.cornerRadius = 7 + icon.layer?.masksToBounds = true + icon.translatesAutoresizingMaskIntoConstraints = false + icon.widthAnchor.constraint(equalToConstant: 28).isActive = true + icon.heightAnchor.constraint(equalToConstant: 28).isActive = true + + let name = NSTextField(labelWithString: row.name) + name.font = .systemFont(ofSize: 13) + name.lineBreakMode = .byTruncatingTail + let caption = NSTextField(wrappingLabelWithString: row.caption) + caption.font = .systemFont(ofSize: 11) + caption.textColor = .secondaryLabelColor + caption.maximumNumberOfLines = 3 + let controls = controlsView(for: row) + // Every row gives its text the same width, so the controls line up in a column. + let textWidth = innerWidth - 8 - 28 - 20 - controls.fittingSize.width + caption.preferredMaxLayoutWidth = textWidth + let texts = NSStackView(views: [name, caption]) + texts.orientation = .vertical + texts.alignment = .leading + texts.spacing = 1 + texts.widthAnchor.constraint(equalToConstant: textWidth).isActive = true + + let line = NSStackView(views: [icon, texts, controls]) + line.orientation = .horizontal + line.alignment = .centerY + line.spacing = 10 + line.edgeInsets = NSEdgeInsets(top: 11, left: 4, bottom: 11, right: 4) + return line + } + + private func controlsView(for row: ArrivalsPromptModel.Row) -> NSView { + switch row.style { + case .question: + let segments = NSSegmentedControl(labels: ["Show".localized, "Hide".localized], trackingMode: .selectOne, + target: self, action: #selector(segmentPressed(_:))) + segments.controlSize = .small + segments.identifier = NSUserInterfaceItemIdentifier(Self.showIdentifier(row.bundle)) + segments.setAccessibilityLabel(row.name) + let more = NSButton(title: "", target: self, action: #selector(morePressed(_:))) + more.image = NSImage(systemSymbolName: "ellipsis", accessibilityDescription: "More".localized) + more.isBordered = false + more.imagePosition = .imageOnly + more.contentTintColor = .secondaryLabelColor + more.wantsLayer = true + more.layer?.cornerRadius = 6 + more.layer?.backgroundColor = NSColor.quaternaryLabelColor.cgColor + more.identifier = NSUserInterfaceItemIdentifier(Self.alwaysHideIdentifier(row.bundle)) + more.setAccessibilityLabel("More".localized + " " + row.name) + more.translatesAutoresizingMaskIntoConstraints = false + more.widthAnchor.constraint(equalToConstant: 22).isActive = true + more.heightAnchor.constraint(equalToConstant: 22).isActive = true + let menu = NSMenu() + let item = NSMenuItem(title: "Always hide".localized, action: #selector(alwaysHidePicked(_:)), keyEquivalent: "") + item.target = self + item.representedObject = row.bundle + menu.addItem(item) + more.menu = menu + let controls = NSStackView(views: [segments, more]) + controls.spacing = 6 + return controls + case .kept: + let pill = NSTextField(labelWithString: "\u{25CF} " + "Kept".localized) + pill.font = .systemFont(ofSize: 11, weight: .medium) + pill.textColor = .systemGreen + return pill + case .notice: + let ok = NSButton(title: "OK".localized, target: self, action: #selector(okPressed(_:))) + ok.bezelStyle = .rounded + ok.controlSize = .small + ok.identifier = NSUserInterfaceItemIdentifier(Self.okIdentifier(row.bundle)) + return ok + } + } + + private func footerView() -> NSView { + let footer = NSStackView() + footer.orientation = .horizontal + footer.alignment = .centerY + footer.edgeInsets = NSEdgeInsets(top: 8, left: 4, bottom: 0, right: 4) + func label(_ text: String, width: CGFloat) -> NSTextField { + let field = NSTextField(wrappingLabelWithString: text) + field.font = .systemFont(ofSize: 11) + field.textColor = .secondaryLabelColor + field.preferredMaxLayoutWidth = width + field.translatesAutoresizingMaskIntoConstraints = false + field.widthAnchor.constraint(equalToConstant: width).isActive = true + return field + } + func button(_ title: String, _ identifier: String, _ action: Selector) -> NSButton { + let button = NSButton(title: title, target: self, action: action) + button.bezelStyle = .rounded + button.controlSize = .small + button.identifier = NSUserInterfaceItemIdentifier(identifier) + return button + } + switch model.footer { + case .hint: + footer.addArrangedSubview(label("Not sure? It stays shown until you choose.".localized, width: innerWidth - 8 - 80)) + let settings = NSButton(title: "Settings\u{2026}".localized, target: self, action: #selector(settingsPressed)) + settings.isBordered = false + settings.controlSize = .small + settings.attributedTitle = NSAttributedString(string: "Settings\u{2026}".localized, attributes: [ + .font: NSFont.systemFont(ofSize: 11), .foregroundColor: NSColor.linkColor, + ]) + settings.identifier = NSUserInterfaceItemIdentifier(Self.settingsIdentifier) + footer.addArrangedSubview(settings) + case .bulk(let more): + footer.addArrangedSubview(label(String(format: "and %d more".localized, more), width: innerWidth - 8 - 160)) + let buttons = NSStackView(views: [button("Hide All".localized, Self.hideAllIdentifier, #selector(hideAllPressed)), + button("Show All".localized, Self.showAllIdentifier, #selector(showAllPressed))]) + buttons.spacing = 6 + footer.addArrangedSubview(buttons) + case .text(let text): + footer.addArrangedSubview(label(text, width: innerWidth - 8)) + case .none: + break + } + return footer + } + + @objc private func segmentPressed(_ sender: NSSegmentedControl) { + guard let raw = sender.identifier?.rawValue else { return } + let bundle = String(raw.dropFirst(Self.showIdentifier("").count)) + let answer: ArrivalAnswer = sender.selectedSegment == 0 ? .show : .hide + // Neither side stays pressed: the row is about to go. + sender.selectedSegment = -1 + onAnswer(bundle, answer) + } + + @objc private func morePressed(_ sender: NSButton) { + guard let menu = sender.menu else { return } + menu.popUp(positioning: nil, at: NSPoint(x: 0, y: sender.bounds.height + 2), in: sender) + } + + @objc private func alwaysHidePicked(_ sender: NSMenuItem) { + guard let bundle = sender.representedObject as? String else { return } + onAnswer(bundle, .alwaysHide) + } + + @objc private func okPressed(_ sender: NSButton) { + guard let raw = sender.identifier?.rawValue else { return } + onDismiss(String(raw.dropFirst(Self.okIdentifier("").count))) + } + + @objc private func hideAllPressed() { onAnswerAll(.hide) } + @objc private func showAllPressed() { onAnswerAll(.show) } + @objc private func settingsPressed() { onOpenSettings() } +} +#endif diff --git a/hidden/Features/Arrivals/ArrivalsSnapshot.swift b/hidden/Features/Arrivals/ArrivalsSnapshot.swift new file mode 100644 index 00000000..11f9d266 --- /dev/null +++ b/hidden/Features/Arrivals/ArrivalsSnapshot.swift @@ -0,0 +1,187 @@ +// +// ArrivalsSnapshot.swift +// Hidden Bar +// +// Copyright © 2026 Dwarves Foundation. All rights reserved. +// + +#if DEBUG && HIDDENBAR_NATIVE_VISIBILITY +import AppKit + +/// Debug builds only: draws the arrivals prompt into PNGs for `-settingsSnapshotDir`, +/// from fixture apps (no Accessibility read, no live catalog), as a menu bar strip +/// with the arrow and the prompt under it, like the design boards. +enum ArrivalsSnapshot { + struct Scene { + let name: String + let model: ArrivalsPromptModel? + let dot: Bool + } + + static func render(appearance: NSAppearance.Name, mode: String, to dir: URL) { + for scene in scenes() { + let view = ArrivalsSceneView(scene: scene, mode: mode) + view.appearance = NSAppearance(named: appearance) + view.layoutSubtreeIfNeeded() + guard let rep = view.bitmapImageRepForCachingDisplay(in: view.bounds) else { continue } + view.cacheDisplay(in: view.bounds, to: rep) + let url = dir.appendingPathComponent("direct-arrivals-\(scene.name)-\(mode).png") + try? rep.representation(using: .png, properties: [:])?.write(to: url) + NSLog("ArrivalsSnapshot: %@ %.0fx%.0f", url.lastPathComponent, view.bounds.width, view.bounds.height) + } + } + + static func scenes() -> [Scene] { + let now = Date() + func info(_ bundle: String, _ name: String, symbol: String, color: NSColor, ago: TimeInterval = 5, + running: Bool = true, icons: Int = 1) -> ArrivalInfo { + ArrivalInfo(bundle: bundle, name: name, icon: icon(symbol, color), firstSeen: now.addingTimeInterval(-ago), + isRunning: running, iconCount: icons) + } + let raycast = info("com.raycast.macos", "Raycast", symbol: "bolt.fill", color: NSColor(srgbRed: 0.90, green: 0.28, blue: 0.30, alpha: 1)) + let tailscale = info("io.tailscale.ipn.macos", "Tailscale", symbol: "network", color: NSColor(srgbRed: 0.18, green: 0.18, blue: 0.20, alpha: 1), + ago: 2 * 3600) + let drive = info("com.google.drivefs", "Google Drive", symbol: "externaldrive.fill", color: NSColor(srgbRed: 0.12, green: 0.64, blue: 0.39, alpha: 1)) + let docker = info("com.docker.docker", "Docker Desktop", symbol: "shippingbox.fill", color: NSColor(srgbRed: 0.11, green: 0.39, blue: 0.93, alpha: 1), + icons: 2) + let more = [ + info("com.example.one", "Bartender Helper", symbol: "ellipsis.circle.fill", color: .systemIndigo), + info("com.example.two", "Clipboard Tool", symbol: "doc.on.clipboard.fill", color: .systemTeal), + info("com.example.three", "Menu Weather", symbol: "cloud.sun.fill", color: .systemOrange), + ] + func model(_ infos: [ArrivalInfo]) -> ArrivalsPromptModel { ArrivalsPromptModel.make(infos: infos, now: now) } + + var known = model([]) + known.title = "No question for a known app" + known.subtitle = nil + known.rows = [ArrivalsPromptModel.Row(bundle: "com.tinyspeck.slackmacgap", name: "Slack", + caption: "10:02 quit to update. 10:03 back in Hidden, where you put it.", + icon: icon("number", NSColor(srgbRed: 0.29, green: 0.08, blue: 0.29, alpha: 1)), style: .kept)] + known.footer = .text("Only apps Hidden Bar has never seen are asked about.") + + var system = model([]) + system.subtitle = nil + system.rows = [ArrivalsPromptModel.Row(bundle: "com.apple.controlcenter", name: "Timer (Live Activity)", + caption: "A macOS item. macOS decides when it shows; Hidden Bar can't keep it shown while hiding.", + icon: icon("timer", NSColor.systemGray), style: .notice)] + system.footer = .none + + return [ + Scene(name: "entry", model: nil, dot: true), + Scene(name: "prompt", model: model([raycast, tailscale]), dot: true), + Scene(name: "edge-multi-icon", model: model([docker]), dot: true), + Scene(name: "edge-many", model: model([raycast, tailscale, drive] + more), dot: true), + Scene(name: "edge-known", model: known, dot: false), + Scene(name: "edge-system", model: system, dot: false), + Scene(name: "edge-not-running", model: model([raycast, + info("com.example.gone", "Fantastical Helper", symbol: "calendar", color: .systemRed, ago: 3 * 3600, running: false)]), dot: true), + ] + } + + // A stand-in app icon: a colored rounded square with a white symbol. + static func icon(_ symbol: String, _ color: NSColor) -> NSImage { + let size = NSSize(width: 28, height: 28) + return NSImage(size: size, flipped: false) { rect in + color.setFill() + NSBezierPath(roundedRect: rect, xRadius: 7, yRadius: 7).fill() + let config = NSImage.SymbolConfiguration(pointSize: 14, weight: .semibold) + if let glyph = NSImage(systemSymbolName: symbol, accessibilityDescription: nil)?.withSymbolConfiguration(config) { + let tinted = NSImage(size: glyph.size, flipped: false) { glyphRect in + glyph.draw(in: glyphRect) + NSColor.white.set() + glyphRect.fill(using: .sourceAtop) + return true + } + tinted.draw(in: NSRect(x: (rect.width - glyph.size.width) / 2, y: (rect.height - glyph.size.height) / 2, + width: glyph.size.width, height: glyph.size.height)) + } + return true + } + } +} + +/// The wallpaper, a 26 pt menu bar with the arrow (and its dot), and the prompt under it. +private final class ArrivalsSceneView: NSView { + private let scene: ArrivalsSnapshot.Scene + private let isDark: Bool + static let width: CGFloat = 560 + static let barHeight: CGFloat = 26 + + init(scene: ArrivalsSnapshot.Scene, mode: String) { + self.scene = scene + isDark = mode == "dark" + super.init(frame: .zero) + var height = Self.barHeight + 150 + if let model = scene.model { + let prompt = ArrivalsPromptView(model: model) + let panel = PromptPanel() + panel.translatesAutoresizingMaskIntoConstraints = false + prompt.translatesAutoresizingMaskIntoConstraints = false + panel.addSubview(prompt) + addSubview(panel) + let size = prompt.fittingContentSize + NSLayoutConstraint.activate([ + prompt.topAnchor.constraint(equalTo: panel.topAnchor), + prompt.leadingAnchor.constraint(equalTo: panel.leadingAnchor), + prompt.trailingAnchor.constraint(equalTo: panel.trailingAnchor), + prompt.bottomAnchor.constraint(equalTo: panel.bottomAnchor), + panel.widthAnchor.constraint(equalToConstant: size.width), + panel.heightAnchor.constraint(equalToConstant: size.height), + panel.topAnchor.constraint(equalTo: topAnchor, constant: Self.barHeight + 6), + panel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20), + ]) + height = Self.barHeight + 6 + size.height + 28 + } + frame = NSRect(x: 0, y: 0, width: Self.width, height: height) + } + + required init?(coder: NSCoder) { fatalError("init(coder:) is not used") } + + override var isFlipped: Bool { true } + + override func draw(_ dirtyRect: NSRect) { + let colors: [NSColor] = isDark + ? [NSColor(srgbRed: 0.06, green: 0.10, blue: 0.19, alpha: 1), NSColor(srgbRed: 0.18, green: 0.11, blue: 0.20, alpha: 1)] + : [NSColor(srgbRed: 0.84, green: 0.89, blue: 0.96, alpha: 1), NSColor(srgbRed: 0.95, green: 0.89, blue: 0.84, alpha: 1)] + NSGradient(colors: colors)?.draw(in: bounds, angle: -20) + (isDark ? NSColor.black.withAlphaComponent(0.30) : NSColor.white.withAlphaComponent(0.45)).setFill() + NSRect(x: 0, y: 0, width: bounds.width, height: Self.barHeight).fill() + let ink: NSColor = isDark ? NSColor(white: 0.96, alpha: 1) : NSColor(white: 0.11, alpha: 1) + let attributes: [NSAttributedString.Key: Any] = [.font: NSFont.systemFont(ofSize: 13), .foregroundColor: ink] + let bold: [NSAttributedString.Key: Any] = [.font: NSFont.systemFont(ofSize: 13, weight: .bold), .foregroundColor: ink] + ("Finder" as NSString).draw(at: NSPoint(x: 14, y: 4), withAttributes: bold) + ("File" as NSString).draw(at: NSPoint(x: 68, y: 4), withAttributes: attributes) + ("Edit" as NSString).draw(at: NSPoint(x: 100, y: 4), withAttributes: attributes) + ("9:41" as NSString).draw(at: NSPoint(x: bounds.width - 44, y: 4), withAttributes: attributes) + var x = bounds.width - 130 + for symbol in ["wifi", "battery.100", "chevron.left"].reversed() { + guard let image = NSImage(systemSymbolName: symbol, accessibilityDescription: nil) else { continue } + let tinted = NSImage(size: image.size, flipped: false) { rect in + image.draw(in: rect) + ink.set() + rect.fill(using: .sourceAtop) + return true + } + x -= tinted.size.width + 12 + tinted.draw(in: NSRect(x: x, y: 5, width: tinted.size.width, height: tinted.size.height)) + if symbol == "chevron.left", scene.dot { + NSColor.controlAccentColor.setFill() + NSBezierPath(ovalIn: NSRect(x: x + tinted.size.width - 2, y: 2, width: ArrivalsArrowDot.diameter, + height: ArrivalsArrowDot.diameter)).fill() + } + } + } +} + +/// What the popover draws around the prompt: the system's material, as a flat fill. +private final class PromptPanel: NSView { + override func draw(_ dirtyRect: NSRect) { + let path = NSBezierPath(roundedRect: bounds.insetBy(dx: 0.5, dy: 0.5), xRadius: 14, yRadius: 14) + NSColor.windowBackgroundColor.setFill() + path.fill() + NSColor.separatorColor.setStroke() + path.lineWidth = 1 + path.stroke() + } +} +#endif diff --git a/hidden/Features/Settings/MenuBarAppsSettingsViewController.swift b/hidden/Features/Settings/MenuBarAppsSettingsViewController.swift index 45fefca7..cb03aa2a 100644 --- a/hidden/Features/Settings/MenuBarAppsSettingsViewController.swift +++ b/hidden/Features/Settings/MenuBarAppsSettingsViewController.swift @@ -22,6 +22,14 @@ protocol MenuBarAppsStore { func resetAllToVisible() func remove(_ bundle: String) func enable() + /// What an app that adds its first icon gets: asked, shown or hidden. + var newAppDefault: NewAppDefault { get } + func setNewAppDefault(_ choice: NewAppDefault) +} + +extension MenuBarAppsStore { + var newAppDefault: NewAppDefault { Preferences.newAppDefaultSection } + func setNewAppDefault(_ choice: NewAppDefault) { Preferences.newAppDefaultSection = choice } } struct LiveMenuBarAppsStore: MenuBarAppsStore { @@ -32,7 +40,8 @@ struct LiveMenuBarAppsStore: MenuBarAppsStore { func entries() -> [PinnedSectionsList.Entry] { PinnedSectionsList.entries(table: UserDefaultsPinnedSections().sections, name: { identities.identity(for: $0).name }, - ignoringDrags: UserDefaultsDragLocks().bundles) + ignoringDrags: UserDefaultsDragLocks().bundles, + pending: Set(UserDefaultsArrivalsPending().bundles)) } func identity(for bundle: String) -> MenuBarAppIdentity.Resolved { identities.identity(for: bundle) } @@ -89,6 +98,17 @@ final class MenuBarAppsSettingsViewController: SettingsPaneController { static func notRunning(_ bundles: [String], running: Set) -> Set { Set(bundles.filter { $0 != MenuBarLayoutResolver.systemExtrasBundle && !running.contains($0) }) } + /// Identifier of the "When an app adds a new icon" popup: the defaults key. + static let newAppDefaultIdentifier = UserDefaults.Key.newAppDefaultSection + static let newAppDefaultTitles: [(NewAppDefault, String)] = [(.ask, "Ask Me"), (.show, "Show It"), (.hide, "Hide It")] + /// What the popup's current choice does, in a line. + static func newAppCaption(for choice: NewAppDefault) -> String { + switch choice { + case .ask: return "Ask puts a dot on the arrow and keeps the icon shown until you choose.".localized + case .show: return "Show leaves a new icon where macOS puts it. Nothing is asked.".localized + case .hide: return "Hide moves a new icon to Hidden at once. Nothing is asked.".localized + } + } static let maxListHeight: CGFloat = 360 private let store: MenuBarAppsStore @@ -104,15 +124,45 @@ final class MenuBarAppsSettingsViewController: SettingsPaneController { required init?(coder: NSCoder) { fatalError("init(coder:) is not used") } override func buildForm() { + addNewAppDefaultRow() content.orientation = .vertical content.alignment = .leading content.spacing = 6 addFullWidth(content) onRefresh { [weak self] in self?.rebuild() } NotificationCenter.default.addObserver(self, selector: #selector(refreshAll), name: .pinnedSectionsChanged, object: nil) + #if HIDDENBAR_NATIVE_VISIBILITY + NotificationCenter.default.addObserver(self, selector: #selector(refreshAll), name: .arrivalsChanged, object: nil) + #endif rebuild() } + // "When an app adds a new icon": one popup above the list. With Pinned sections + // off nothing places a new app, so the popup stays but cannot be changed. + private func addNewAppDefaultRow() { + let popup = NSPopUpButton(frame: .zero, pullsDown: false) + popup.controlSize = .small + for (choice, title) in Self.newAppDefaultTitles { + popup.addItem(withTitle: title.localized) + popup.lastItem?.tag = choice.rawValue + } + popup.identifier = NSUserInterfaceItemIdentifier(Self.newAppDefaultIdentifier) + popup.target = self + popup.action = #selector(newAppDefaultPicked(_:)) + let row = SettingsForm.row("When an app adds a new icon".localized, + caption: Self.newAppCaption(for: store.newAppDefault), control: popup) + addSection(nil, rows: [row]) + let caption = (row.subviews.first { $0 is NSStackView } as? NSStackView)?.arrangedSubviews.last as? NSTextField + onRefresh { [weak self, weak popup, weak caption] in + guard let self, let popup else { return } + popup.selectItem(withTag: self.store.newAppDefault.rawValue) + popup.isEnabled = self.store.isEnabled + caption?.stringValue = Self.newAppCaption(for: self.store.newAppDefault) + } + popup.selectItem(withTag: store.newAppDefault.rawValue) + popup.isEnabled = store.isEnabled + } + override func viewWillAppear() { super.viewWillAppear() // A collapse adds apps to the table while the window is closed. @@ -162,7 +212,11 @@ final class MenuBarAppsSettingsViewController: SettingsPaneController { private func list(_ entries: [PinnedSectionsList.Entry], notRunning: Set) -> NSView { let captions = MenuBarAppIdentity.captions(for: entries.map { ($0.bundle, $0.name, store.identity(for: $0.bundle).caption) }, notRunning: notRunning) - let group = SettingsGroupView(rows: entries.map { row($0, caption: captions[$0.bundle], canRemove: notRunning.contains($0.bundle)) }) + let group = SettingsGroupView(rows: entries.map { entry in + let canRemove = notRunning.contains(entry.bundle) + let caption = entry.isNew ? (canRemove ? "Not chosen yet. Not running now.".localized : "Not chosen yet".localized) : captions[entry.bundle] + return row(entry, caption: caption, canRemove: canRemove) + }) let fittingHeight = group.fittingSize.height let height = min(fittingHeight, Self.maxListHeight) guard fittingHeight > Self.maxListHeight else { return group } @@ -208,6 +262,7 @@ final class MenuBarAppsSettingsViewController: SettingsPaneController { let row = SettingsForm.row(entry.name, caption: caption, control: controls) if canRemove { addRemoveLink(to: row, for: entry) } + if entry.isNew { markNew(row) } row.toolTip = entry.bundle let image = store.icon(for: entry.bundle) let icon = NSImageView(image: image) @@ -229,6 +284,26 @@ final class MenuBarAppsSettingsViewController: SettingsPaneController { return row } + // An app that waits for an answer: a tinted row and a NEW tag after its name. + private func markNew(_ row: NSView) { + let tint = NewRowTint() + tint.translatesAutoresizingMaskIntoConstraints = false + row.addSubview(tint, positioned: .below, relativeTo: nil) + NSLayoutConstraint.activate([ + tint.leadingAnchor.constraint(equalTo: row.leadingAnchor), + tint.trailingAnchor.constraint(equalTo: row.trailingAnchor), + tint.topAnchor.constraint(equalTo: row.topAnchor), + tint.bottomAnchor.constraint(equalTo: row.bottomAnchor), + ]) + guard let texts = row.subviews.first(where: { $0 is NSStackView }) as? NSStackView, + let title = texts.arrangedSubviews.first else { return } + texts.removeArrangedSubview(title) + let line = NSStackView(views: [title, NewTag()]) + line.spacing = 6 + line.alignment = .centerY + texts.insertArrangedSubview(line, at: 0) + } + // Remove sits in the caption line, not the controls column, so every row's controls line up. private func addRemoveLink(to row: NSView, for entry: PinnedSectionsList.Entry) { guard let texts = row.subviews.first(where: { $0 is NSStackView }) as? NSStackView, @@ -273,6 +348,11 @@ final class MenuBarAppsSettingsViewController: SettingsPaneController { store.remove(String(raw.dropFirst(Self.removeIdentifier(for: "").count))) } + @objc private func newAppDefaultPicked(_ sender: NSPopUpButton) { + guard let choice = sender.selectedItem.flatMap({ NewAppDefault(rawValue: $0.tag) }) else { return } + store.setNewAppDefault(choice) + } + @objc private func resetAll() { store.resetAllToVisible() } @@ -282,6 +362,46 @@ final class MenuBarAppsSettingsViewController: SettingsPaneController { } } +/// The accent wash behind a row that waits for an answer. +private final class NewRowTint: NSView { + override func hitTest(_ point: NSPoint) -> NSView? { nil } + + override func draw(_ dirtyRect: NSRect) { + NSColor.controlAccentColor.withAlphaComponent(0.10).setFill() + bounds.fill() + } +} + +/// "NEW": a small accent pill. +final class NewTag: NSView { + static let identifier = NSUserInterfaceItemIdentifier("arrivalsNewTag") + private let text = "NEW".localized + private let attributes: [NSAttributedString.Key: Any] = [ + .font: NSFont.systemFont(ofSize: 9.5, weight: .bold), .foregroundColor: NSColor.white, .kern: 0.4, + ] + + init() { + super.init(frame: .zero) + identifier = Self.identifier + translatesAutoresizingMaskIntoConstraints = false + } + + required init?(coder: NSCoder) { fatalError("init(coder:) is not used") } + + override var intrinsicContentSize: NSSize { + let size = (text as NSString).size(withAttributes: attributes) + return NSSize(width: ceil(size.width) + 12, height: 15) + } + + override func draw(_ dirtyRect: NSRect) { + NSColor.controlAccentColor.setFill() + NSBezierPath(roundedRect: bounds, xRadius: 7.5, yRadius: 7.5).fill() + let size = (text as NSString).size(withAttributes: attributes) + (text as NSString).draw(at: NSPoint(x: (bounds.width - size.width) / 2, y: (bounds.height - size.height) / 2), + withAttributes: attributes) + } +} + /// A scroll view's document grows downward only when flipped. private final class FlippedView: NSView { override var isFlipped: Bool { true } @@ -293,6 +413,8 @@ struct SnapshotMenuBarAppsStore: MenuBarAppsStore { var isEnabled: Bool var table: [String: MenuBarSection] var notRunning: Set = [] + var pending: Set = [] + var newAppDefault: NewAppDefault = .show let live = LiveMenuBarAppsStore() static let states: [(String, SnapshotMenuBarAppsStore)] = [ @@ -303,12 +425,17 @@ struct SnapshotMenuBarAppsStore: MenuBarAppsStore { "com.apple.screensharing.agent": .hidden, "com.apple.SSMenuAgent": .visible, "com.hnc.Discord.helper.Renderer": .hidden, ], notRunning: ["com.example.uninstalled", "com.apple.chronod"])), + // Ask Me, with two apps that have not been answered: listed first, tagged NEW. + ("new", SnapshotMenuBarAppsStore(isEnabled: true, table: [ + "com.apple.Safari": .visible, "com.apple.Notes": .hidden, "com.apple.Music": .alwaysHidden, + "com.apple.ActivityMonitor": .hidden, "com.apple.TextEdit": .visible, "com.apple.Preview": .visible, + ], pending: ["com.apple.TextEdit", "com.apple.Preview"], newAppDefault: .ask)), ("off", SnapshotMenuBarAppsStore(isEnabled: false, table: [:])), ("empty", SnapshotMenuBarAppsStore(isEnabled: true, table: [:])), ] func entries() -> [PinnedSectionsList.Entry] { - PinnedSectionsList.entries(table: table, name: { live.identity(for: $0).name }) + PinnedSectionsList.entries(table: table, name: { live.identity(for: $0).name }, pending: pending) } func identity(for bundle: String) -> MenuBarAppIdentity.Resolved { live.identity(for: bundle) } @@ -319,5 +446,6 @@ struct SnapshotMenuBarAppsStore: MenuBarAppsStore { func resetAllToVisible() {} func remove(_ bundle: String) {} func enable() {} + func setNewAppDefault(_ choice: NewAppDefault) {} } #endif diff --git a/hidden/Features/Settings/SettingsSnapshot.swift b/hidden/Features/Settings/SettingsSnapshot.swift index dd50e9e6..d4b1667e 100644 --- a/hidden/Features/Settings/SettingsSnapshot.swift +++ b/hidden/Features/Settings/SettingsSnapshot.swift @@ -54,6 +54,9 @@ enum SettingsSnapshot { to: dir.appendingPathComponent("\(build)-menubarapps-\(state)-\(mode).png")) } MenuBarAppsPane.makeViewController = registered + #if HIDDENBAR_NATIVE_VISIBILITY + ArrivalsSnapshot.render(appearance: appearance, mode: mode, to: dir) + #endif // The preview strip per engine, with the always-hidden section on. for (os, engine) in [(27, "macos27"), (26, "macos26")] { var context = live diff --git a/hidden/Features/StatusBar/Engine/MenuBarEngineFactory.swift b/hidden/Features/StatusBar/Engine/MenuBarEngineFactory.swift index f90f84b9..a6d62f4d 100644 --- a/hidden/Features/StatusBar/Engine/MenuBarEngineFactory.swift +++ b/hidden/Features/StatusBar/Engine/MenuBarEngineFactory.swift @@ -40,7 +40,10 @@ enum MenuBarEngineFactory { ignoredDrags: { UserDefaultsDragLocks().bundles }, agentLaunches: agentLaunches) let catalog = MenuBarItemCatalog.shared - engine.onUnrestrictedRead = { layout, inventory in catalog.record(layout: layout, inventory: inventory) } + engine.onUnrestrictedRead = { layout, inventory in + ArrivalsController.shared.noteInventory(inventory) + catalog.record(layout: layout, inventory: inventory) + } catalog.observeLaunches(on: [NSWorkspace.shared.notificationCenter, agentLaunches]) return engine } diff --git a/hidden/Features/StatusBar/Layout/MenuBarLayout.swift b/hidden/Features/StatusBar/Layout/MenuBarLayout.swift index adfc1bf5..d9e07e99 100644 --- a/hidden/Features/StatusBar/Layout/MenuBarLayout.swift +++ b/hidden/Features/StatusBar/Layout/MenuBarLayout.swift @@ -222,14 +222,18 @@ enum PinnedSectionsList { let name: String let section: MenuBarSection var ignoresDrags = false + // Waiting for an answer in the arrivals inbox: listed first, tagged NEW. + var isNew = false } static func entries(table: [String: MenuBarSection], name: (String) -> String?, - ignoringDrags: Set = []) -> [Entry] { + ignoringDrags: Set = [], pending: Set = []) -> [Entry] { return table.map { bundle, section in let label = bundle == MenuBarLayoutResolver.systemExtrasBundle ? "macOS extras (Focus, Now Playing...)" : (name(bundle) ?? bundle) - return Entry(bundle: bundle, name: label, section: section, ignoresDrags: ignoringDrags.contains(bundle)) + return Entry(bundle: bundle, name: label, section: section, ignoresDrags: ignoringDrags.contains(bundle), + isNew: pending.contains(bundle)) }.sorted { + if $0.isNew != $1.isNew { return $0.isNew } let order = $0.name.localizedCaseInsensitiveCompare($1.name) return order == .orderedSame ? $0.bundle < $1.bundle : order == .orderedAscending } diff --git a/hidden/Features/StatusBar/StatusBarController.swift b/hidden/Features/StatusBar/StatusBarController.swift index feb75349..3890f0f0 100644 --- a/hidden/Features/StatusBar/StatusBarController.swift +++ b/hidden/Features/StatusBar/StatusBarController.swift @@ -77,6 +77,15 @@ class StatusBarController: MenuBarItemProvider { // True while the arrow's context menu is up. private var isShowingOwnMenu = false + #if HIDDENBAR_NATIVE_VISIBILITY + // Asks about apps that add a first icon (Ask Me), from the arrow. + private lazy var arrivalsPresenter = ArrivalsPresenter(openSettings: { + Util.showPrefWindow() + PreferencesWindowController.shared.select(.menuBarApps) + }) + private var arrivalsObserver: NSObjectProtocol? + #endif + private var hoverMonitor: Any? private var pinnedSectionsObserver: NSObjectProtocol? private var hoverDwellTimer: Timer? @@ -118,6 +127,7 @@ class StatusBarController: MenuBarItemProvider { NotificationCenter.default.addObserver(self, selector: #selector(refreshArrow), name: .stealthExpandIconToggle, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(refreshArrow), name: .arrowStyleChanged, object: nil) watchAccessibilityPermission() + startArrivals() #if DEBUG installDebugHooks() #endif @@ -259,7 +269,9 @@ class StatusBarController: MenuBarItemProvider { let shiftPressed = ExpandCollapseActionResolver.isShiftPressed(eventFlags: event?.modifierFlags, liveFlags: NSEvent.modifierFlags) switch ExpandCollapseActionResolver.action(eventType: event?.type, optionPressed: optionPressed, shiftPressed: shiftPressed) { case .toggle: + let wasCollapsed = isCollapsed self.expandCollapseIfNeeded() + if wasCollapsed { showArrivalsIfWaiting() } case .toggleWithFullBar: // Shift-click expands with the full menu bar for this expansion only; // the stored setting is untouched. Collapsing works as a plain click. @@ -466,7 +478,7 @@ 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 isPreferencesWindowVisible || menuBarEngine.defersAutoCollapse || popupGuard.defersCollapse() + return isPreferencesWindowVisible || arrivalsPromptIsShown || menuBarEngine.defersAutoCollapse || popupGuard.defersCollapse() } private func startTimerToAutoHide() { @@ -685,6 +697,15 @@ extension StatusBarController { case "reveal-sim": // What a real scroll, click or shake runs: "scroll", "scroll-up", "click" or "shake". revealController.simulate(argument ?? "") + case "arrivals-inject": + // Asks about a bundle as if a read had just found it: "". + if let argument { debugArrivalsInject(argument) } + case "arrivals-answer": + // What a prompt button runs: "=show|hide". + debugArrivalsAnswer(argument ?? "") + case "arrivals-prompt": + // Opens the prompt under the arrow, as a click on it does while something waits. + showArrivalsIfWaiting() case "dump-state": break case "dump-inventory": @@ -809,6 +830,7 @@ extension StatusBarController { state.merge(engine.debugState) { $1 } } state.merge(revealController.debugState) { $1 } + state.merge(debugArrivalsState) { $1 } do { let data = try JSONSerialization.data(withJSONObject: state, options: [.prettyPrinted, .sortedKeys]) try data.write(to: URL(fileURLWithPath: path)) @@ -818,3 +840,70 @@ extension StatusBarController { } } #endif + +//MARK: - Arrivals +// Kept apart from the rest of the controller: it is the only part of this file +// the arrivals inbox touches. +extension StatusBarController { + fileprivate func startArrivals() { + #if HIDDENBAR_NATIVE_VISIBILITY + guard MenuBarEngineFactory.usesNativeEngine() else { return } + ArrivalsController.shared.start() + arrivalsObserver = NotificationCenter.default.addObserver(forName: .arrivalsChanged, object: nil, queue: .main) { [weak self] _ in + self?.syncArrivalsDot() + } + syncArrivalsDot() + #endif + } + + fileprivate func syncArrivalsDot() { + #if HIDDENBAR_NATIVE_VISIBILITY + ArrivalsArrowDot.sync(on: btnExpandCollapse.button, visible: !ArrivalsController.shared.pending.isEmpty) + #endif + } + + fileprivate func showArrivalsIfWaiting() { + #if HIDDENBAR_NATIVE_VISIBILITY + arrivalsPresenter.present(from: btnExpandCollapse.button) + #endif + } + + fileprivate var arrivalsPromptIsShown: Bool { + #if HIDDENBAR_NATIVE_VISIBILITY + return arrivalsPresenter.isShown + #else + return false + #endif + } +} + +#if DEBUG +extension StatusBarController { + fileprivate func debugArrivalsInject(_ bundle: String) { + #if HIDDENBAR_NATIVE_VISIBILITY + ArrivalsController.shared.debugInject(bundle) + #endif + } + + fileprivate func debugArrivalsAnswer(_ argument: String) { + #if HIDDENBAR_NATIVE_VISIBILITY + let parts = argument.components(separatedBy: "=") + let answers: [String: ArrivalAnswer] = ["show": .show, "hide": .hide, "always-hide": .alwaysHide] + if parts.count == 2, let answer = answers[parts[1]] { + ArrivalsController.shared.answer(parts[0], answer) + } + #endif + } + + fileprivate var debugArrivalsState: [String: Any] { + #if HIDDENBAR_NATIVE_VISIBILITY + var state = ArrivalsController.shared.debugState + state["arrivalsPromptShown"] = arrivalsPresenter.isShown + state["arrivalsDot"] = btnExpandCollapse.button?.subviews.contains { $0 is ArrivalsArrowDot } ?? false + return state + #else + return [:] + #endif + } +} +#endif diff --git a/hidden/ar.lproj/Localizable.strings b/hidden/ar.lproj/Localizable.strings index 47f18f62..d0d94c32 100644 --- a/hidden/ar.lproj/Localizable.strings +++ b/hidden/ar.lproj/Localizable.strings @@ -158,3 +158,31 @@ Steps to view always hidden icons: "Show Everything" = "Show Everything"; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"OK" = "OK"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked."; diff --git a/hidden/de.lproj/Localizable.strings b/hidden/de.lproj/Localizable.strings index a5f04e3d..39732523 100644 --- a/hidden/de.lproj/Localizable.strings +++ b/hidden/de.lproj/Localizable.strings @@ -157,3 +157,31 @@ Steps to view always hidden icons: "Show Everything" = "Show Everything"; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"OK" = "OK"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked."; diff --git a/hidden/en.lproj/Localizable.strings b/hidden/en.lproj/Localizable.strings index 45b1508b..6f9802dc 100644 --- a/hidden/en.lproj/Localizable.strings +++ b/hidden/en.lproj/Localizable.strings @@ -196,3 +196,30 @@ Steps to view always hidden icons: "macOS moved the Hidden Bar arrow into the « button. Click « to reach it, or use the Hidden Bar hotkey. To keep the arrow in view, move some icons to the left of the arrow." = "macOS moved the Hidden Bar arrow into the « button. Click « to reach it, or use the Hidden Bar hotkey. To keep the arrow in view, move some icons to the left of the arrow."; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked."; diff --git a/hidden/fr.lproj/Localizable.strings b/hidden/fr.lproj/Localizable.strings index df7f3873..727187f2 100644 --- a/hidden/fr.lproj/Localizable.strings +++ b/hidden/fr.lproj/Localizable.strings @@ -159,3 +159,31 @@ Steps to view always hidden icons: "Show Everything" = "Show Everything"; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"OK" = "OK"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked."; diff --git a/hidden/hr.lproj/Localizable.strings b/hidden/hr.lproj/Localizable.strings index 2727e9a0..6046cd94 100644 --- a/hidden/hr.lproj/Localizable.strings +++ b/hidden/hr.lproj/Localizable.strings @@ -157,3 +157,31 @@ Steps to view always hidden icons: "Show Everything" = "Show Everything"; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"OK" = "OK"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked."; diff --git a/hidden/it.lproj/Localizable.strings b/hidden/it.lproj/Localizable.strings index f84884e4..285821d5 100644 --- a/hidden/it.lproj/Localizable.strings +++ b/hidden/it.lproj/Localizable.strings @@ -159,3 +159,31 @@ Steps to view always hidden icons: "Show Everything" = "Show Everything"; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"OK" = "OK"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked."; diff --git a/hidden/ja.lproj/Localizable.strings b/hidden/ja.lproj/Localizable.strings index 4c9ab027..af1c4037 100644 --- a/hidden/ja.lproj/Localizable.strings +++ b/hidden/ja.lproj/Localizable.strings @@ -156,3 +156,31 @@ Steps to view always hidden icons: "Show Everything" = "Show Everything"; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"OK" = "OK"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked."; diff --git a/hidden/pl.lproj/Localizable.strings b/hidden/pl.lproj/Localizable.strings index 66ee51fb..ee59f696 100644 --- a/hidden/pl.lproj/Localizable.strings +++ b/hidden/pl.lproj/Localizable.strings @@ -157,3 +157,31 @@ Steps to view always hidden icons: "Show Everything" = "Show Everything"; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"OK" = "OK"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked."; diff --git a/hidden/tr.lproj/Localizable.strings b/hidden/tr.lproj/Localizable.strings index 01f08476..935b477d 100644 --- a/hidden/tr.lproj/Localizable.strings +++ b/hidden/tr.lproj/Localizable.strings @@ -158,3 +158,31 @@ Steps to view always hidden icons: "Show Everything" = "Show Everything"; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"OK" = "OK"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked."; diff --git a/hidden/uk.lproj/Localizable.strings b/hidden/uk.lproj/Localizable.strings index 9dfd2f4a..0493587d 100644 --- a/hidden/uk.lproj/Localizable.strings +++ b/hidden/uk.lproj/Localizable.strings @@ -157,3 +157,31 @@ Steps to view always hidden icons: "Show Everything" = "Show Everything"; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"OK" = "OK"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked."; diff --git a/hidden/vi.lproj/Localizable.strings b/hidden/vi.lproj/Localizable.strings index d0af7dd2..b4eceb43 100644 --- a/hidden/vi.lproj/Localizable.strings +++ b/hidden/vi.lproj/Localizable.strings @@ -157,3 +157,31 @@ Steps to view always hidden icons: "Show Everything" = "Show Everything"; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"OK" = "OK"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked."; diff --git a/hidden/zh-Hans.lproj/Localizable.strings b/hidden/zh-Hans.lproj/Localizable.strings index 727ff2d4..581ddeb2 100644 --- a/hidden/zh-Hans.lproj/Localizable.strings +++ b/hidden/zh-Hans.lproj/Localizable.strings @@ -159,3 +159,31 @@ Steps to view always hidden icons: "Show Everything" = "Show Everything"; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"OK" = "OK"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked."; diff --git a/hidden/zh-Hant.lproj/Localizable.strings b/hidden/zh-Hant.lproj/Localizable.strings index c80f5d53..5e1d6fe0 100644 --- a/hidden/zh-Hant.lproj/Localizable.strings +++ b/hidden/zh-Hant.lproj/Localizable.strings @@ -165,3 +165,31 @@ Steps to view always hidden icons: "Show Everything" = "Show Everything"; "Also used by %@" = "Also used by %@"; "Show or hide icons" = "Show or hide icons"; +"Ask Me" = "Ask Me"; +"Show It" = "Show It"; +"Hide It" = "Hide It"; +"When an app adds a new icon" = "When an app adds a new icon"; +"Ask puts a dot on the arrow and keeps the icon shown until you choose." = "Ask puts a dot on the arrow and keeps the icon shown until you choose."; +"NEW" = "NEW"; +"Not chosen yet" = "Not chosen yet"; +"Not chosen yet. Not running now." = "Not chosen yet. Not running now."; +"New in your menu bar" = "New in your menu bar"; +"%d new apps in your menu bar" = "%d new apps in your menu bar"; +"Choose once. Hidden Bar remembers, also after the app or your Mac restarts." = "Choose once. Hidden Bar remembers, also after the app or your Mac restarts."; +"Not running now. It stays shown until you choose." = "Not running now. It stays shown until you choose."; +"Added %d icons. They show or hide together." = "Added %d icons. They show or hide together."; +"Added an icon %@" = "Added an icon %@"; +"just now" = "just now"; +"Show" = "Show"; +"Hide" = "Hide"; +"More" = "More"; +"Always hide" = "Always hide"; +"Kept" = "Kept"; +"OK" = "OK"; +"Not sure? It stays shown until you choose." = "Not sure? It stays shown until you choose."; +"Settings…" = "Settings…"; +"and %d more" = "and %d more"; +"Hide All" = "Hide All"; +"Show All" = "Show All"; +"Show leaves a new icon where macOS puts it. Nothing is asked." = "Show leaves a new icon where macOS puts it. Nothing is asked."; +"Hide moves a new icon to Hidden at once. Nothing is asked." = "Hide moves a new icon to Hidden at once. Nothing is asked.";