From 3b6ff6d2327148f9c5d0b842ffda3c1a6294feff Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Sun, 15 Nov 2026 19:53:03 +0700 Subject: [PATCH 1/2] fix: remove three dead ends when switching from the App Store build The flow review of the App Store to direct switch found three places where the direct build stops with no message: - An App Store copy that is running (often a login item) made the direct build's single-instance guard quit silently, so none of the switch offers ran. The direct build now asks "Hidden Bar from the App Store is running. Quit it and switch to this version?". Quit and Switch terminates it (then forces it after 5 s) and launching continues; Cancel quits as before. Another direct copy still wins silently. A copy counts as the App Store build when its bundle has _MASReceipt/receipt or a Mac App Store signature. - "Not now" to the Trash offer left the App Store copy in /Applications, and the move offer never showed. The move offer no longer depends on it; it also waits for the Trash to finish, so a trashed copy frees /Applications. - When /Applications is not writable, or holds the App Store copy the user kept, the move goes to ~/Applications (created when missing). When neither folder can take it, an alert says plainly what to do. The decisions are pure functions (OtherRunningCopy.decide, MoveToApplications.plan) with unit tests that fail under the old rules. Debug builds get a -debugAnswerAlerts hook so a harness can answer the alerts without pointer or key input. --- HiddenTests/AppStoreMigrationTests.swift | 105 ++++++- hidden/AppDelegate.swift | 5 + .../AppStoreMigration/AppStoreMigration.swift | 274 ++++++++++++++++-- hidden/en.lproj/Localizable.strings | 9 + 4 files changed, 356 insertions(+), 37 deletions(-) diff --git a/HiddenTests/AppStoreMigrationTests.swift b/HiddenTests/AppStoreMigrationTests.swift index 7256f87b..e1d86720 100644 --- a/HiddenTests/AppStoreMigrationTests.swift +++ b/HiddenTests/AppStoreMigrationTests.swift @@ -195,18 +195,101 @@ final class AppStoreMigrationTests: XCTestCase { "/Applications/Hidden Bar.app") } - func testMoveOfferRules() { - let home = URL(fileURLWithPath: "/Users/x") - let downloads = URL(fileURLWithPath: "/Users/x/Downloads/Hidden Bar.app") - func offer(_ url: URL = downloads, answered: Bool = false, masAtDestination: Bool = false, writable: Bool = true) -> Bool { - MoveToApplications.shouldOffer(runningBundle: url, home: home, alreadyAnswered: answered, - destinationIsAppStoreCopy: masAtDestination, applicationsWritable: writable) + // Fake answers: the plan reads no disk, so writability and App Store copies are parameters. + private func plan(_ running: String = "/Users/x/Downloads/Hidden Bar.app", answered: Bool = false, + writable: Bool = true, masInApplications: Bool = false, + userUsable: Bool = true, masInUserApplications: Bool = false) -> MoveToApplications.Plan { + MoveToApplications.plan(runningBundle: URL(fileURLWithPath: running), home: URL(fileURLWithPath: "/Users/x"), + alreadyAnswered: answered, applicationsWritable: writable, + applicationsHoldsAppStoreCopy: masInApplications, + userApplicationsUsable: userUsable, userApplicationsHoldsAppStoreCopy: masInUserApplications) + } + + func testMoveGoesToApplicationsWhenItCan() { + XCTAssertEqual(plan(), .moveToApplications(URL(fileURLWithPath: "/Applications/Hidden Bar.app"))) + XCTAssertEqual(plan("/Applications/Hidden Bar.app"), MoveToApplications.Plan.none) + XCTAssertEqual(plan("/Users/x/Applications/Hidden Bar.app"), MoveToApplications.Plan.none) + XCTAssertEqual(plan(answered: true), MoveToApplications.Plan.none, "offered once") + } + + /// Dead end: "Not now" to the Trash left the App Store copy in /Applications + /// and the move offer never showed. + func testKeptAppStoreCopyInApplicationsSendsTheMoveToUserApplications() { + XCTAssertEqual(plan(masInApplications: true), + .moveToUserApplicationsAppStoreCopyKept(URL(fileURLWithPath: "/Users/x/Applications/Hidden Bar.app"))) + } + + /// Dead end: a standard account cannot write /Applications. + func testUnwritableApplicationsSendsTheMoveToUserApplications() { + XCTAssertEqual(plan(writable: false), + .moveToUserApplicationsNotWritable(URL(fileURLWithPath: "/Users/x/Applications/Hidden Bar.app"))) + XCTAssertEqual(plan(writable: false, masInApplications: true), + .moveToUserApplicationsNotWritable(URL(fileURLWithPath: "/Users/x/Applications/Hidden Bar.app"))) + } + + func testNoUsableFolderExplainsInsteadOfStayingSilent() { + XCTAssertEqual(plan(writable: false, userUsable: false), .explain) + XCTAssertEqual(plan(masInApplications: true, masInUserApplications: true), .explain) + XCTAssertEqual(plan(answered: true, writable: false, userUsable: false), MoveToApplications.Plan.none) + } + + /// The move check reads the real folders: a fake home and a fake /Applications. + func testMovePlanReadsFoldersAndKeptAppStoreCopy() throws { + let downloads = try makeBundle("Downloads/Hidden Bar.app", bundleID: bundleID, appStore: false) + let system = root.appendingPathComponent("SystemApplications") + try FileManager.default.createDirectory(at: system, withIntermediateDirectories: true) + func migration() -> AppStoreMigration { + AppStoreMigration(environment: .init(home: root, bundleURL: downloads, bundleIdentifier: bundleID, + defaults: defaults, registeredDefaults: registered, + systemApplications: system)) } - XCTAssertTrue(offer()) - XCTAssertFalse(offer(URL(fileURLWithPath: "/Applications/Hidden Bar.app"))) - XCTAssertFalse(offer(answered: true), "offered once") - XCTAssertFalse(offer(masAtDestination: true), "the Trash offer handles the App Store copy first") - XCTAssertFalse(offer(writable: false)) + XCTAssertEqual(migration().movePlan, .moveToApplications(system.appendingPathComponent("Hidden Bar.app"))) + + _ = try makeBundle("SystemApplications/Hidden Bar.app", bundleID: bundleID, appStore: true) + XCTAssertEqual(migration().movePlan, + .moveToUserApplicationsAppStoreCopyKept(root.appendingPathComponent("Applications/Hidden Bar.app")), + "~/Applications is missing but creatable") + + // The Trash answer does not matter. + MigrationOfferLedger(defaults: defaults).recordAnswer(MigrationOfferLedger.trashKey) + XCTAssertEqual(migration().movePlan, + .moveToUserApplicationsAppStoreCopyKept(root.appendingPathComponent("Applications/Hidden Bar.app"))) + } + + // MARK: another copy already running + + private let downloadsApp = URL(fileURLWithPath: "/Users/x/Downloads/Hidden Bar.app") + + private func instance(_ pid: pid_t, _ path: String, appStore: Bool) -> OtherRunningCopy.Instance { + .init(pid: pid, bundleURL: URL(fileURLWithPath: path), isAppStoreBuild: appStore) + } + + /// Dead end: the App Store copy runs at login and the direct build quit silently. + func testRunningAppStoreCopyIsOfferedAQuit() { + let others = [instance(41, "/Applications/Hidden Bar.app", appStore: true)] + XCTAssertEqual(OtherRunningCopy.decide(others: others, runningBundle: downloadsApp), .offerToReplaceAppStoreCopy(41)) + } + + func testRunningDirectCopyStillWinsSilently() { + XCTAssertEqual(OtherRunningCopy.decide(others: [instance(42, "/Applications/Hidden Bar.app", appStore: false)], + runningBundle: downloadsApp), .quitInFavorOf(42)) + XCTAssertEqual(OtherRunningCopy.decide(others: [instance(41, "/Applications/Hidden Bar.app", appStore: true), + instance(42, "/Users/x/Applications/Hidden Bar.app", appStore: false)], + runningBundle: downloadsApp), .quitInFavorOf(42), + "a direct copy is already running; nothing to switch") + XCTAssertEqual(OtherRunningCopy.decide(others: [], runningBundle: downloadsApp), .launch) + } + + func testDebugRulesOnlyCountTheSamePathUnlessForced() { + let installed = instance(42, "/Applications/Hidden Bar.app", appStore: false) + let appStore = instance(41, "/Applications/Hidden Bar.app", appStore: true) + let relaunch = instance(43, downloadsApp.path, appStore: false) + XCTAssertEqual(OtherRunningCopy.decide(others: [installed, appStore], runningBundle: downloadsApp, + countsOtherPaths: false, countsAppStoreCopies: false), .launch) + XCTAssertEqual(OtherRunningCopy.decide(others: [installed, appStore], runningBundle: downloadsApp, + countsOtherPaths: false, countsAppStoreCopies: true), .offerToReplaceAppStoreCopy(41)) + XCTAssertEqual(OtherRunningCopy.decide(others: [appStore, relaunch], runningBundle: downloadsApp, + countsOtherPaths: false, countsAppStoreCopies: true), .quitInFavorOf(43)) } } diff --git a/hidden/AppDelegate.swift b/hidden/AppDelegate.swift index 295c5c2d..0f82fe5d 100644 --- a/hidden/AppDelegate.swift +++ b/hidden/AppDelegate.swift @@ -63,6 +63,10 @@ class AppDelegate: NSObject, NSApplicationDelegate{ /// If another instance with the same bundle ID is already running, activate it /// and terminate this one instead. private func ensureSingleInstance() -> Bool { + #if HIDDENBAR_NATIVE_VISIBILITY + // The direct build asks before quitting an App Store copy that is running. + return AppStoreMigration.shared.resolveOtherRunningCopy() + #else let current = ProcessInfo.processInfo.processIdentifier let existing = NSWorkspace.shared.runningApplications.first { guard $0.bundleIdentifier == Bundle.main.bundleIdentifier, @@ -79,6 +83,7 @@ class AppDelegate: NSObject, NSApplicationDelegate{ existing.activate(options: [.activateAllWindows]) NSApp.terminate(nil) return false + #endif } func openPreferencesIfNeeded() { diff --git a/hidden/Features/AppStoreMigration/AppStoreMigration.swift b/hidden/Features/AppStoreMigration/AppStoreMigration.swift index 924d082f..62f96ea4 100644 --- a/hidden/Features/AppStoreMigration/AppStoreMigration.swift +++ b/hidden/Features/AppStoreMigration/AppStoreMigration.swift @@ -12,7 +12,10 @@ import AppKit // reads ~/Library/Preferences. On launch the direct build offers, once each: // 1. import the App Store build's settings (known keys only), // 2. move a leftover App Store copy to the Trash, -// 3. move itself into /Applications. +// 3. move itself into /Applications, or ~/Applications when /Applications is +// not writable or holds the App Store copy the user kept. +// Before those, an App Store copy that is already running is offered a quit +// instead of this build quitting silently. // Nothing happens without the user's click. The App Store build compiles none of // this: App Review 2.4.5(iv) forbids it from fetching or installing other apps. #if HIDDENBAR_NATIVE_VISIBILITY @@ -137,10 +140,74 @@ enum AppStoreCopyFinder { && isAppStoreBuild(url, fileManager: fileManager) } } + + /// Signed by the Mac App Store (leaf certificate carries Apple's MAS + /// marker). Catches an App Store copy whose receipt is missing. + static func hasAppStoreSignature(_ bundleURL: URL) -> Bool { + var code: SecStaticCode? + var requirement: SecRequirement? + guard SecStaticCodeCreateWithPath(bundleURL as CFURL, [], &code) == errSecSuccess, let code, + SecRequirementCreateWithString("anchor apple generic and certificate leaf[field.1.2.840.113635.100.6.1.9] exists" as CFString, + [], &requirement) == errSecSuccess, let requirement else { return false } + return SecStaticCodeCheckValidity(code, SecCSFlags(rawValue: kSecCSBasicValidateOnly), requirement) == errSecSuccess + } +} + +/// What to do at launch when another copy with this bundle id is running. +/// The App Store copy often starts at login; quitting silently in front of it +/// made the downloaded build look broken. +enum OtherRunningCopy { + struct Instance { + let pid: pid_t + let bundleURL: URL? + let isAppStoreBuild: Bool + } + + enum Decision: Equatable { + case launch + /// Another direct copy: bring it forward and quit, as before. + case quitInFavorOf(pid_t) + /// The App Store copy: ask before quitting it and taking over. + case offerToReplaceAppStoreCopy(pid_t) + } + + /// `others` are running apps with this bundle id, this process excluded. + /// Debug builds pass `countsOtherPaths: false` so a dev build runs next to + /// the installed copy, and `countsAppStoreCopies` to test the offer. + static func decide(others: [Instance], runningBundle: URL, + countsOtherPaths: Bool = true, countsAppStoreCopies: Bool = true) -> Decision { + let running = runningBundle.resolvingSymlinksInPath().standardizedFileURL.path + func isSamePath(_ instance: Instance) -> Bool { + instance.bundleURL?.resolvingSymlinksInPath().standardizedFileURL.path == running + } + let counted = others.filter { instance in + if isSamePath(instance) { return true } + return instance.isAppStoreBuild ? countsAppStoreCopies : countsOtherPaths + } + if let direct = counted.first(where: { !$0.isAppStoreBuild || isSamePath($0) }) { + return .quitInFavorOf(direct.pid) + } + if let appStore = counted.first { + return .offerToReplaceAppStoreCopy(appStore.pid) + } + return .launch + } } -/// Whether to offer moving the running copy into /Applications. +/// Where to move the running copy so macOS 27 knows it by bundle id. enum MoveToApplications { + enum Plan: Equatable { + case none + /// Move into /Applications. + case moveToApplications(URL) + /// /Applications is not writable for this account: use ~/Applications. + case moveToUserApplicationsNotWritable(URL) + /// The App Store copy the user kept holds /Applications/Hidden Bar.app. + case moveToUserApplicationsAppStoreCopyKept(URL) + /// Neither folder can take it: say plainly what to do. + case explain + } + static func isInApplicationsFolder(_ bundleURL: URL, home: URL) -> Bool { let path = bundleURL.resolvingSymlinksInPath().standardizedFileURL.path let roots = ["/Applications/", home.appendingPathComponent("Applications").standardizedFileURL.path + "/"] @@ -152,16 +219,30 @@ enum MoveToApplications { bundleURL.path.contains("/AppTranslocation/") } - static func destination(for bundleURL: URL) -> URL { - URL(fileURLWithPath: "/Applications").appendingPathComponent(bundleURL.lastPathComponent) + static func destination(for bundleURL: URL, in folder: URL = URL(fileURLWithPath: "/Applications")) -> URL { + folder.appendingPathComponent(bundleURL.lastPathComponent) } - static func shouldOffer(runningBundle: URL, home: URL, alreadyAnswered: Bool, - destinationIsAppStoreCopy: Bool, applicationsWritable: Bool) -> Bool { - guard !alreadyAnswered, applicationsWritable else { return false } - // The App Store copy sits where we would go; the Trash offer comes first. - guard !destinationIsAppStoreCopy else { return false } - return !isInApplicationsFolder(runningBundle, home: home) + static func userApplications(home: URL) -> URL { + home.appendingPathComponent("Applications") + } + + /// Independent of the Trash answer: an App Store copy left in + /// /Applications sends the move to ~/Applications instead of skipping it. + static func plan(runningBundle: URL, home: URL, alreadyAnswered: Bool, + applicationsWritable: Bool, applicationsHoldsAppStoreCopy: Bool, + userApplicationsUsable: Bool, userApplicationsHoldsAppStoreCopy: Bool, + systemApplications: URL = URL(fileURLWithPath: "/Applications")) -> Plan { + guard !alreadyAnswered, !isInApplicationsFolder(runningBundle, home: home) else { return .none } + if applicationsWritable && !applicationsHoldsAppStoreCopy { + return .moveToApplications(destination(for: runningBundle, in: systemApplications)) + } + if userApplicationsUsable && !userApplicationsHoldsAppStoreCopy { + let target = destination(for: runningBundle, in: userApplications(home: home)) + return applicationsWritable ? .moveToUserApplicationsAppStoreCopyKept(target) + : .moveToUserApplicationsNotWritable(target) + } + return .explain } } @@ -175,6 +256,7 @@ final class AppStoreMigration { var defaults: UserDefaults var registeredDefaults: [String: Any] var fileManager: FileManager = .default + var systemApplications = URL(fileURLWithPath: "/Applications") } static let shared = AppStoreMigration(environment: Environment( @@ -204,9 +286,84 @@ final class AppStoreMigration { guard Self.isEnabled else { return } DispatchQueue.main.async { [self] in if offerImportIfNeeded() { afterImport() } - offerTrashIfNeeded() - offerMoveIfNeeded() + // The move check waits for the Trash, so a copy just trashed from + // /Applications frees that slot instead of pushing us elsewhere. + offerTrashIfNeeded { [self] in offerMoveIfNeeded() } + } + } + + // MARK: Another copy already running + + /// Called before anything else at launch. Returns false when this process + /// is quitting in favor of the copy already running. + func resolveOtherRunningCopy() -> Bool { + let current = ProcessInfo.processInfo.processIdentifier + let apps = NSWorkspace.shared.runningApplications.filter { + $0.bundleIdentifier == environment.bundleIdentifier && $0.processIdentifier != current + } + let others = apps.map { app in + OtherRunningCopy.Instance( + pid: app.processIdentifier, bundleURL: app.bundleURL, + isAppStoreBuild: app.bundleURL.map { + AppStoreCopyFinder.isAppStoreBuild($0, fileManager: environment.fileManager) + || AppStoreCopyFinder.hasAppStoreSignature($0) + } ?? false) + } + #if DEBUG + let decision = OtherRunningCopy.decide(others: others, runningBundle: environment.bundleURL, + countsOtherPaths: false, countsAppStoreCopies: Self.isEnabled) + #else + let decision = OtherRunningCopy.decide(others: others, runningBundle: environment.bundleURL) + #endif + NSLog("AppStoreMigration: other running copy decision \(decision)") + + switch decision { + case .launch: + return true + case .quitInFavorOf(let pid): + quit(inFavorOf: apps.first { $0.processIdentifier == pid }) + return false + case .offerToReplaceAppStoreCopy(let pid): + let appStoreCopy = apps.first { $0.processIdentifier == pid } + let alert = NSAlert() + alert.alertStyle = .informational + alert.messageText = "Hidden Bar from the App Store is running. Quit it and switch to this version?".localized + alert.informativeText = "Only one Hidden Bar can run at a time. The App Store version stays installed until you choose otherwise.".localized + alert.addButton(withTitle: "Quit and Switch".localized) + alert.addButton(withTitle: "Cancel".localized) + guard run(alert) == .alertFirstButtonReturn, let appStoreCopy else { + quit(inFavorOf: appStoreCopy) + return false + } + guard Self.terminate(appStoreCopy) else { + NSLog("AppStoreMigration: the App Store copy did not quit") + quit(inFavorOf: appStoreCopy) + return false + } + return true + } + } + + private func quit(inFavorOf app: NSRunningApplication?) { + app?.activate(options: [.activateAllWindows]) + NSApp.terminate(nil) + } + + /// Asks the app to quit, then forces it; true once it has exited. + private static func terminate(_ app: NSRunningApplication) -> Bool { + func wait(_ seconds: TimeInterval) { + let deadline = Date().addingTimeInterval(seconds) + while !app.isTerminated && Date() < deadline { + RunLoop.current.run(until: Date().addingTimeInterval(0.1)) + } } + app.terminate() + wait(5) + if !app.isTerminated { + app.forceTerminate() + wait(2) + } + return app.isTerminated } // MARK: Import @@ -262,10 +419,11 @@ final class AppStoreMigration { fileManager: environment.fileManager) } - func offerTrashIfNeeded() { - guard !ledger.isAnswered(MigrationOfferLedger.trashKey) else { return } + /// `then` runs once the offer is answered and any Trash move has finished. + func offerTrashIfNeeded(then next: @escaping () -> Void = {}) { + guard !ledger.isAnswered(MigrationOfferLedger.trashKey) else { return next() } let copies = appStoreCopies - guard !copies.isEmpty else { return } + guard !copies.isEmpty else { return next() } let alert = NSAlert() alert.alertStyle = .informational @@ -280,40 +438,78 @@ final class AppStoreMigration { ledger.recordAnswer(MigrationOfferLedger.trashKey) NSWorkspace.shared.recycle(copies) { _, error in if let error { NSLog("AppStoreMigration: recycle failed: \(error.localizedDescription)") } + DispatchQueue.main.async(execute: next) } case .alertSecondButtonReturn: ledger.recordAnswer(MigrationOfferLedger.trashKey) + next() default: - break + next() } } // MARK: Move into /Applications - func offerMoveIfNeeded() { - let running = environment.bundleURL - let destination = MoveToApplications.destination(for: running) + var movePlan: MoveToApplications.Plan { let fm = environment.fileManager - guard MoveToApplications.shouldOffer( + let running = environment.bundleURL + let userFolder = MoveToApplications.userApplications(home: environment.home) + var isFolder: ObjCBool = false + let userFolderExists = fm.fileExists(atPath: userFolder.path, isDirectory: &isFolder) + return MoveToApplications.plan( runningBundle: running, home: environment.home, alreadyAnswered: ledger.isAnswered(MigrationOfferLedger.moveKey), - destinationIsAppStoreCopy: AppStoreCopyFinder.isAppStoreBuild(destination, fileManager: fm), - applicationsWritable: fm.isWritableFile(atPath: "/Applications")) else { return } + applicationsWritable: fm.isWritableFile(atPath: environment.systemApplications.path), + applicationsHoldsAppStoreCopy: AppStoreCopyFinder.isAppStoreBuild( + MoveToApplications.destination(for: running, in: environment.systemApplications), fileManager: fm), + userApplicationsUsable: userFolderExists ? isFolder.boolValue && fm.isWritableFile(atPath: userFolder.path) + : fm.isWritableFile(atPath: environment.home.path), + userApplicationsHoldsAppStoreCopy: AppStoreCopyFinder.isAppStoreBuild( + MoveToApplications.destination(for: running, in: userFolder), fileManager: fm), + systemApplications: environment.systemApplications) + } + + func offerMoveIfNeeded() { + let fm = environment.fileManager + let destination: URL + let info: String + switch movePlan { + case .none: + return + case .explain: + let alert = NSAlert() + alert.alertStyle = .warning + alert.messageText = "Hidden Bar can't hide icons from this folder".localized + alert.informativeText = "macOS only lets Hidden Bar hide icons when it runs from an Applications folder, and neither /Applications nor the Applications folder in your home folder can take it. Quit Hidden Bar, drag it into /Applications (an administrator may need to do this), then open it from there.".localized + alert.addButton(withTitle: "OK".localized) + run(alert) + ledger.recordAnswer(MigrationOfferLedger.moveKey) + return + case .moveToApplications(let url): + destination = url + info = fm.fileExists(atPath: url.path) + ? "Hidden Bar is running from outside Applications. The copy already in Applications goes to the Trash, then Hidden Bar relaunches from there.".localized + : "Hidden Bar is running from outside Applications. Move it there so it keeps working after you empty Downloads, then relaunch.".localized + case .moveToUserApplicationsNotWritable(let url): + destination = url + info = "Hidden Bar is running from outside Applications, and this account can't write to /Applications. It moves to the Applications folder in your home folder instead, then relaunches from there.".localized + case .moveToUserApplicationsAppStoreCopyKept(let url): + destination = url + info = "Hidden Bar is running from outside Applications, and the App Store copy stays in /Applications. This version moves to the Applications folder in your home folder instead, then relaunches from there.".localized + } let alert = NSAlert() alert.alertStyle = .informational alert.messageText = "Move Hidden Bar to the Applications folder?".localized - alert.informativeText = fm.fileExists(atPath: destination.path) - ? "Hidden Bar is running from outside Applications. The copy already in Applications goes to the Trash, then Hidden Bar relaunches from there.".localized - : "Hidden Bar is running from outside Applications. Move it there so it keeps working after you empty Downloads, then relaunch.".localized + alert.informativeText = info alert.addButton(withTitle: "Move to Applications".localized) alert.addButton(withTitle: "Not now".localized) switch run(alert) { case .alertFirstButtonReturn: ledger.recordAnswer(MigrationOfferLedger.moveKey) - moveAndRelaunch(from: running, to: destination) + moveAndRelaunch(from: environment.bundleURL, to: destination) case .alertSecondButtonReturn: ledger.recordAnswer(MigrationOfferLedger.moveKey) default: @@ -324,6 +520,7 @@ final class AppStoreMigration { private func moveAndRelaunch(from source: URL, to destination: URL) { let fm = environment.fileManager do { + try fm.createDirectory(at: destination.deletingLastPathComponent(), withIntermediateDirectories: true) if fm.fileExists(atPath: destination.path) { try fm.trashItem(at: destination, resultingItemURL: nil) } @@ -359,8 +556,33 @@ final class AppStoreMigration { @discardableResult private func run(_ alert: NSAlert) -> NSApplication.ModalResponse { NSApp.activate(ignoringOtherApps: true) + #if DEBUG + Self.scheduleDebugAnswer() + #endif return alert.runModal() } + + #if DEBUG + /// Test hook: launch with `-debugAnswerAlerts "first,second,abort"` and each + /// alert gets the next answer after 3 seconds (time for a screenshot); once + /// the list runs out, alerts are aborted, which records nothing. + private static var debugAnswers: [String]? = UserDefaults.standard.string(forKey: "debugAnswerAlerts")? + .split(separator: ",").map(String.init) + + private static func scheduleDebugAnswer() { + guard debugAnswers != nil else { return } + let answer = debugAnswers?.isEmpty == false ? debugAnswers!.removeFirst() : "abort" + let timer = Timer(timeInterval: 3, repeats: false) { _ in + NSLog("AppStoreMigration: debug answer \(answer)") + switch answer { + case "first": NSApp.stopModal(withCode: .alertFirstButtonReturn) + case "second": NSApp.stopModal(withCode: .alertSecondButtonReturn) + default: NSApp.abortModal() + } + } + RunLoop.main.add(timer, forMode: .modalPanel) + } + #endif } #endif diff --git a/hidden/en.lproj/Localizable.strings b/hidden/en.lproj/Localizable.strings index 1b30e45e..6d70bd47 100644 --- a/hidden/en.lproj/Localizable.strings +++ b/hidden/en.lproj/Localizable.strings @@ -30,6 +30,15 @@ "Hidden Bar is running from outside Applications. The copy already in Applications goes to the Trash, then Hidden Bar relaunches from there." = "Hidden Bar is running from outside Applications. The copy already in Applications goes to the Trash, then Hidden Bar relaunches from there."; "Hidden Bar is running from outside Applications. Move it there so it keeps working after you empty Downloads, then relaunch." = "Hidden Bar is running from outside Applications. Move it there so it keeps working after you empty Downloads, then relaunch."; "Move to Applications" = "Move to Applications"; +"Hidden Bar from the App Store is running. Quit it and switch to this version?" = "Hidden Bar from the App Store is running. Quit it and switch to this version?"; +"Only one Hidden Bar can run at a time. The App Store version stays installed until you choose otherwise." = "Only one Hidden Bar can run at a time. The App Store version stays installed until you choose otherwise."; +"Quit and Switch" = "Quit and Switch"; +"Cancel" = "Cancel"; +"Hidden Bar can't hide icons from this folder" = "Hidden Bar can't hide icons from this folder"; +"macOS only lets Hidden Bar hide icons when it runs from an Applications folder, and neither /Applications nor the Applications folder in your home folder can take it. Quit Hidden Bar, drag it into /Applications (an administrator may need to do this), then open it from there." = "macOS only lets Hidden Bar hide icons when it runs from an Applications folder, and neither /Applications nor the Applications folder in your home folder can take it. Quit Hidden Bar, drag it into /Applications (an administrator may need to do this), then open it from there."; +"OK" = "OK"; +"Hidden Bar is running from outside Applications, and this account can't write to /Applications. It moves to the Applications folder in your home folder instead, then relaunches from there." = "Hidden Bar is running from outside Applications, and this account can't write to /Applications. It moves to the Applications folder in your home folder instead, then relaunches from there."; +"Hidden Bar is running from outside Applications, and the App Store copy stays in /Applications. This version moves to the Applications folder in your home folder instead, then relaunches from there." = "Hidden Bar is running from outside Applications, and the App Store copy stays in /Applications. This version moves to the Applications folder in your home folder instead, then relaunches from there."; "Set Shortcut" = "Set Shortcut"; "Show Notch Items" = "Show Notch Items"; "Notch Overflow" = "Notch Overflow"; From 822f7c9e6f75655aa3d90e7a0af143da4d81d16c Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Sun, 15 Nov 2026 20:12:00 +0700 Subject: [PATCH 2/2] fix: count only /Applications as a working install location On macOS 27, a Debug-Direct build run from ~/Applications lost its arrow on collapse, the same as a build run from a build folder. Tested with the hooks harness, install-location check on: arrow EMPTY, held=True, placed far left like an app the system does not know. So ~/Applications is not a fix: - The move offer no longer targets ~/Applications. When /Applications is not writable, or holds the App Store copy the user kept, a one-time alert says what to do. - NativeVisibilityEngine.isInApplicationsFolder checks /Applications only, so a copy in ~/Applications fails open instead of losing its arrow. - The other-copy check reads the bundle from the executable path: with two bundles under one id, NSRunningApplication.bundleURL can name the other copy. - -debugAnswerAlerts now names alerts (switch=first,...); every alert not named is aborted, so a harness answer can never move or trash an app. --- HiddenTests/AppStoreMigrationTests.swift | 58 +++----- .../AppStoreMigration/AppStoreMigration.swift | 135 ++++++++---------- .../Engine/NativeVisibilityEngine.swift | 5 +- hidden/en.lproj/Localizable.strings | 7 +- 4 files changed, 90 insertions(+), 115 deletions(-) diff --git a/HiddenTests/AppStoreMigrationTests.swift b/HiddenTests/AppStoreMigrationTests.swift index e1d86720..987b726f 100644 --- a/HiddenTests/AppStoreMigrationTests.swift +++ b/HiddenTests/AppStoreMigrationTests.swift @@ -184,57 +184,46 @@ final class AppStoreMigrationTests: XCTestCase { // MARK: move into /Applications func testApplicationsFolderDetection() { - let home = URL(fileURLWithPath: "/Users/x") - XCTAssertTrue(MoveToApplications.isInApplicationsFolder(URL(fileURLWithPath: "/Applications/Hidden Bar.app"), home: home)) - XCTAssertTrue(MoveToApplications.isInApplicationsFolder(URL(fileURLWithPath: "/Applications/Utilities/Hidden Bar.app"), home: home)) - XCTAssertTrue(MoveToApplications.isInApplicationsFolder(URL(fileURLWithPath: "/Users/x/Applications/Hidden Bar.app"), home: home)) - XCTAssertFalse(MoveToApplications.isInApplicationsFolder(URL(fileURLWithPath: "/Users/x/Downloads/Hidden Bar.app"), home: home)) - XCTAssertFalse(MoveToApplications.isInApplicationsFolder(URL(fileURLWithPath: "/ApplicationsOld/Hidden Bar.app"), home: home)) + XCTAssertTrue(MoveToApplications.isInApplicationsFolder(URL(fileURLWithPath: "/Applications/Hidden Bar.app"))) + XCTAssertTrue(MoveToApplications.isInApplicationsFolder(URL(fileURLWithPath: "/Applications/Utilities/Hidden Bar.app"))) + XCTAssertFalse(MoveToApplications.isInApplicationsFolder(URL(fileURLWithPath: "/Users/x/Applications/Hidden Bar.app")), + "macOS 27 hides the arrow of a copy in ~/Applications") + XCTAssertFalse(MoveToApplications.isInApplicationsFolder(URL(fileURLWithPath: "/Users/x/Downloads/Hidden Bar.app"))) + XCTAssertFalse(MoveToApplications.isInApplicationsFolder(URL(fileURLWithPath: "/ApplicationsOld/Hidden Bar.app"))) XCTAssertTrue(MoveToApplications.isTranslocated(URL(fileURLWithPath: "/private/var/folders/ab/T/AppTranslocation/1234/d/Hidden Bar.app"))) XCTAssertEqual(MoveToApplications.destination(for: URL(fileURLWithPath: "/Users/x/Downloads/Hidden Bar.app")).path, "/Applications/Hidden Bar.app") } - // Fake answers: the plan reads no disk, so writability and App Store copies are parameters. + // Fake answers: the plan reads no disk, so writability and the App Store copy are parameters. private func plan(_ running: String = "/Users/x/Downloads/Hidden Bar.app", answered: Bool = false, - writable: Bool = true, masInApplications: Bool = false, - userUsable: Bool = true, masInUserApplications: Bool = false) -> MoveToApplications.Plan { - MoveToApplications.plan(runningBundle: URL(fileURLWithPath: running), home: URL(fileURLWithPath: "/Users/x"), - alreadyAnswered: answered, applicationsWritable: writable, - applicationsHoldsAppStoreCopy: masInApplications, - userApplicationsUsable: userUsable, userApplicationsHoldsAppStoreCopy: masInUserApplications) + writable: Bool = true, masInApplications: Bool = false) -> MoveToApplications.Plan { + MoveToApplications.plan(runningBundle: URL(fileURLWithPath: running), alreadyAnswered: answered, + applicationsWritable: writable, applicationsHoldsAppStoreCopy: masInApplications) } func testMoveGoesToApplicationsWhenItCan() { XCTAssertEqual(plan(), .moveToApplications(URL(fileURLWithPath: "/Applications/Hidden Bar.app"))) + XCTAssertEqual(plan("/Users/x/Applications/Hidden Bar.app"), .moveToApplications(URL(fileURLWithPath: "/Applications/Hidden Bar.app"))) XCTAssertEqual(plan("/Applications/Hidden Bar.app"), MoveToApplications.Plan.none) - XCTAssertEqual(plan("/Users/x/Applications/Hidden Bar.app"), MoveToApplications.Plan.none) XCTAssertEqual(plan(answered: true), MoveToApplications.Plan.none, "offered once") } /// Dead end: "Not now" to the Trash left the App Store copy in /Applications - /// and the move offer never showed. - func testKeptAppStoreCopyInApplicationsSendsTheMoveToUserApplications() { - XCTAssertEqual(plan(masInApplications: true), - .moveToUserApplicationsAppStoreCopyKept(URL(fileURLWithPath: "/Users/x/Applications/Hidden Bar.app"))) + /// and the move offer never showed, nor anything else. + func testKeptAppStoreCopyInApplicationsExplainsWhatToDo() { + XCTAssertEqual(plan(masInApplications: true), .explainAppStoreCopyKept) + XCTAssertEqual(plan(answered: true, masInApplications: true), MoveToApplications.Plan.none) } /// Dead end: a standard account cannot write /Applications. - func testUnwritableApplicationsSendsTheMoveToUserApplications() { - XCTAssertEqual(plan(writable: false), - .moveToUserApplicationsNotWritable(URL(fileURLWithPath: "/Users/x/Applications/Hidden Bar.app"))) - XCTAssertEqual(plan(writable: false, masInApplications: true), - .moveToUserApplicationsNotWritable(URL(fileURLWithPath: "/Users/x/Applications/Hidden Bar.app"))) - } - - func testNoUsableFolderExplainsInsteadOfStayingSilent() { - XCTAssertEqual(plan(writable: false, userUsable: false), .explain) - XCTAssertEqual(plan(masInApplications: true, masInUserApplications: true), .explain) - XCTAssertEqual(plan(answered: true, writable: false, userUsable: false), MoveToApplications.Plan.none) + func testUnwritableApplicationsExplainsWhatToDo() { + XCTAssertEqual(plan(writable: false), .explainNotWritable) + XCTAssertEqual(plan(writable: false, masInApplications: true), .explainNotWritable) } - /// The move check reads the real folders: a fake home and a fake /Applications. - func testMovePlanReadsFoldersAndKeptAppStoreCopy() throws { + /// The move check reads the real folder: a fake /Applications on disk. + func testMovePlanReadsTheFolderAndTheKeptAppStoreCopy() throws { let downloads = try makeBundle("Downloads/Hidden Bar.app", bundleID: bundleID, appStore: false) let system = root.appendingPathComponent("SystemApplications") try FileManager.default.createDirectory(at: system, withIntermediateDirectories: true) @@ -246,14 +235,11 @@ final class AppStoreMigrationTests: XCTestCase { XCTAssertEqual(migration().movePlan, .moveToApplications(system.appendingPathComponent("Hidden Bar.app"))) _ = try makeBundle("SystemApplications/Hidden Bar.app", bundleID: bundleID, appStore: true) - XCTAssertEqual(migration().movePlan, - .moveToUserApplicationsAppStoreCopyKept(root.appendingPathComponent("Applications/Hidden Bar.app")), - "~/Applications is missing but creatable") + XCTAssertEqual(migration().movePlan, .explainAppStoreCopyKept) // The Trash answer does not matter. MigrationOfferLedger(defaults: defaults).recordAnswer(MigrationOfferLedger.trashKey) - XCTAssertEqual(migration().movePlan, - .moveToUserApplicationsAppStoreCopyKept(root.appendingPathComponent("Applications/Hidden Bar.app"))) + XCTAssertEqual(migration().movePlan, .explainAppStoreCopyKept) } // MARK: another copy already running diff --git a/hidden/Features/AppStoreMigration/AppStoreMigration.swift b/hidden/Features/AppStoreMigration/AppStoreMigration.swift index 62f96ea4..f36d6080 100644 --- a/hidden/Features/AppStoreMigration/AppStoreMigration.swift +++ b/hidden/Features/AppStoreMigration/AppStoreMigration.swift @@ -12,7 +12,7 @@ import AppKit // reads ~/Library/Preferences. On launch the direct build offers, once each: // 1. import the App Store build's settings (known keys only), // 2. move a leftover App Store copy to the Trash, -// 3. move itself into /Applications, or ~/Applications when /Applications is +// 3. move itself into /Applications, or say what to do when /Applications is // not writable or holds the App Store copy the user kept. // Before those, an App Store copy that is already running is offered a quit // instead of this build quitting silently. @@ -194,24 +194,21 @@ enum OtherRunningCopy { } } -/// Where to move the running copy so macOS 27 knows it by bundle id. +/// Where to move the running copy so macOS 27 knows it by bundle id. Only +/// /Applications counts: run from ~/Applications, macOS 27 still hides the +/// arrow on collapse, like any folder outside /Applications. enum MoveToApplications { enum Plan: Equatable { case none - /// Move into /Applications. case moveToApplications(URL) - /// /Applications is not writable for this account: use ~/Applications. - case moveToUserApplicationsNotWritable(URL) /// The App Store copy the user kept holds /Applications/Hidden Bar.app. - case moveToUserApplicationsAppStoreCopyKept(URL) - /// Neither folder can take it: say plainly what to do. - case explain + case explainAppStoreCopyKept + /// This account cannot write to /Applications. + case explainNotWritable } - static func isInApplicationsFolder(_ bundleURL: URL, home: URL) -> Bool { - let path = bundleURL.resolvingSymlinksInPath().standardizedFileURL.path - let roots = ["/Applications/", home.appendingPathComponent("Applications").standardizedFileURL.path + "/"] - return roots.contains { path.hasPrefix($0) } + static func isInApplicationsFolder(_ bundleURL: URL) -> Bool { + bundleURL.resolvingSymlinksInPath().standardizedFileURL.path.hasPrefix("/Applications/") } /// Gatekeeper runs a quarantined app from a read-only random path. @@ -223,26 +220,15 @@ enum MoveToApplications { folder.appendingPathComponent(bundleURL.lastPathComponent) } - static func userApplications(home: URL) -> URL { - home.appendingPathComponent("Applications") - } - - /// Independent of the Trash answer: an App Store copy left in - /// /Applications sends the move to ~/Applications instead of skipping it. - static func plan(runningBundle: URL, home: URL, alreadyAnswered: Bool, + /// Independent of the Trash answer: when /Applications cannot take this + /// copy, say what to do instead of skipping the offer in silence. + static func plan(runningBundle: URL, alreadyAnswered: Bool, applicationsWritable: Bool, applicationsHoldsAppStoreCopy: Bool, - userApplicationsUsable: Bool, userApplicationsHoldsAppStoreCopy: Bool, systemApplications: URL = URL(fileURLWithPath: "/Applications")) -> Plan { - guard !alreadyAnswered, !isInApplicationsFolder(runningBundle, home: home) else { return .none } - if applicationsWritable && !applicationsHoldsAppStoreCopy { - return .moveToApplications(destination(for: runningBundle, in: systemApplications)) - } - if userApplicationsUsable && !userApplicationsHoldsAppStoreCopy { - let target = destination(for: runningBundle, in: userApplications(home: home)) - return applicationsWritable ? .moveToUserApplicationsAppStoreCopyKept(target) - : .moveToUserApplicationsNotWritable(target) - } - return .explain + guard !alreadyAnswered, !isInApplicationsFolder(runningBundle) else { return .none } + guard applicationsWritable else { return .explainNotWritable } + guard !applicationsHoldsAppStoreCopy else { return .explainAppStoreCopyKept } + return .moveToApplications(destination(for: runningBundle, in: systemApplications)) } } @@ -302,9 +288,14 @@ final class AppStoreMigration { $0.bundleIdentifier == environment.bundleIdentifier && $0.processIdentifier != current } let others = apps.map { app in - OtherRunningCopy.Instance( - pid: app.processIdentifier, bundleURL: app.bundleURL, - isAppStoreBuild: app.bundleURL.map { + // Two bundles with one id can confuse Launch Services, so bundleURL + // may name the other copy; the executable path is the process's own. + let bundle = app.executableURL.map { + $0.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent() + } ?? app.bundleURL + return OtherRunningCopy.Instance( + pid: app.processIdentifier, bundleURL: bundle, + isAppStoreBuild: bundle.map { AppStoreCopyFinder.isAppStoreBuild($0, fileManager: environment.fileManager) || AppStoreCopyFinder.hasAppStoreSignature($0) } ?? false) @@ -331,7 +322,7 @@ final class AppStoreMigration { alert.informativeText = "Only one Hidden Bar can run at a time. The App Store version stays installed until you choose otherwise.".localized alert.addButton(withTitle: "Quit and Switch".localized) alert.addButton(withTitle: "Cancel".localized) - guard run(alert) == .alertFirstButtonReturn, let appStoreCopy else { + guard run(alert, id: "switch") == .alertFirstButtonReturn, let appStoreCopy else { quit(inFavorOf: appStoreCopy) return false } @@ -394,7 +385,7 @@ final class AppStoreMigration { alert.addButton(withTitle: "Import".localized) alert.addButton(withTitle: "Not now".localized) - switch run(alert) { + switch run(alert, id: "import") { case .alertFirstButtonReturn: ledger.recordAnswer(MigrationOfferLedger.importKey) AppStoreSettingsImport.apply(container, to: environment.defaults) @@ -433,7 +424,7 @@ final class AppStoreMigration { alert.addButton(withTitle: "Move to Trash".localized) alert.addButton(withTitle: "Not now".localized) - switch run(alert) { + switch run(alert, id: "trash") { case .alertFirstButtonReturn: ledger.recordAnswer(MigrationOfferLedger.trashKey) NSWorkspace.shared.recycle(copies) { _, error in @@ -453,20 +444,12 @@ final class AppStoreMigration { var movePlan: MoveToApplications.Plan { let fm = environment.fileManager let running = environment.bundleURL - let userFolder = MoveToApplications.userApplications(home: environment.home) - var isFolder: ObjCBool = false - let userFolderExists = fm.fileExists(atPath: userFolder.path, isDirectory: &isFolder) return MoveToApplications.plan( runningBundle: running, - home: environment.home, alreadyAnswered: ledger.isAnswered(MigrationOfferLedger.moveKey), applicationsWritable: fm.isWritableFile(atPath: environment.systemApplications.path), applicationsHoldsAppStoreCopy: AppStoreCopyFinder.isAppStoreBuild( MoveToApplications.destination(for: running, in: environment.systemApplications), fileManager: fm), - userApplicationsUsable: userFolderExists ? isFolder.boolValue && fm.isWritableFile(atPath: userFolder.path) - : fm.isWritableFile(atPath: environment.home.path), - userApplicationsHoldsAppStoreCopy: AppStoreCopyFinder.isAppStoreBuild( - MoveToApplications.destination(for: running, in: userFolder), fileManager: fm), systemApplications: environment.systemApplications) } @@ -477,26 +460,17 @@ final class AppStoreMigration { switch movePlan { case .none: return - case .explain: - let alert = NSAlert() - alert.alertStyle = .warning - alert.messageText = "Hidden Bar can't hide icons from this folder".localized - alert.informativeText = "macOS only lets Hidden Bar hide icons when it runs from an Applications folder, and neither /Applications nor the Applications folder in your home folder can take it. Quit Hidden Bar, drag it into /Applications (an administrator may need to do this), then open it from there.".localized - alert.addButton(withTitle: "OK".localized) - run(alert) - ledger.recordAnswer(MigrationOfferLedger.moveKey) + case .explainAppStoreCopyKept: + explainMove("The App Store copy is in /Applications. Quit Hidden Bar, move /Applications/Hidden Bar.app to the Trash, drag this copy into Applications, then open it from there.".localized) + return + case .explainNotWritable: + explainMove("This account can't add apps to /Applications. Ask an administrator to drag Hidden Bar into /Applications, then open it from there.".localized) return case .moveToApplications(let url): destination = url info = fm.fileExists(atPath: url.path) ? "Hidden Bar is running from outside Applications. The copy already in Applications goes to the Trash, then Hidden Bar relaunches from there.".localized : "Hidden Bar is running from outside Applications. Move it there so it keeps working after you empty Downloads, then relaunch.".localized - case .moveToUserApplicationsNotWritable(let url): - destination = url - info = "Hidden Bar is running from outside Applications, and this account can't write to /Applications. It moves to the Applications folder in your home folder instead, then relaunches from there.".localized - case .moveToUserApplicationsAppStoreCopyKept(let url): - destination = url - info = "Hidden Bar is running from outside Applications, and the App Store copy stays in /Applications. This version moves to the Applications folder in your home folder instead, then relaunches from there.".localized } let alert = NSAlert() @@ -506,7 +480,7 @@ final class AppStoreMigration { alert.addButton(withTitle: "Move to Applications".localized) alert.addButton(withTitle: "Not now".localized) - switch run(alert) { + switch run(alert, id: "move") { case .alertFirstButtonReturn: ledger.recordAnswer(MigrationOfferLedger.moveKey) moveAndRelaunch(from: environment.bundleURL, to: destination) @@ -517,17 +491,27 @@ final class AppStoreMigration { } } + /// Shown once: macOS 27 hides nothing for a copy outside /Applications. + private func explainMove(_ steps: String) { + let alert = NSAlert() + alert.alertStyle = .warning + alert.messageText = "Hidden Bar can hide icons only from /Applications".localized + alert.informativeText = steps + alert.addButton(withTitle: "OK".localized) + run(alert, id: "explain") + ledger.recordAnswer(MigrationOfferLedger.moveKey) + } + private func moveAndRelaunch(from source: URL, to destination: URL) { let fm = environment.fileManager do { - try fm.createDirectory(at: destination.deletingLastPathComponent(), withIntermediateDirectories: true) if fm.fileExists(atPath: destination.path) { try fm.trashItem(at: destination, resultingItemURL: nil) } try fm.copyItem(at: source, to: destination) } catch { let failure = NSAlert(error: error) - run(failure) + run(failure, id: "error") return } // A translocated copy is a read-only view of the original; leave the @@ -554,26 +538,31 @@ final class AppStoreMigration { } @discardableResult - private func run(_ alert: NSAlert) -> NSApplication.ModalResponse { + private func run(_ alert: NSAlert, id: String) -> NSApplication.ModalResponse { NSApp.activate(ignoringOtherApps: true) #if DEBUG - Self.scheduleDebugAnswer() + Self.scheduleDebugAnswer(for: id) #endif return alert.runModal() } #if DEBUG - /// Test hook: launch with `-debugAnswerAlerts "first,second,abort"` and each - /// alert gets the next answer after 3 seconds (time for a screenshot); once - /// the list runs out, alerts are aborted, which records nothing. - private static var debugAnswers: [String]? = UserDefaults.standard.string(forKey: "debugAnswerAlerts")? - .split(separator: ",").map(String.init) - - private static func scheduleDebugAnswer() { - guard debugAnswers != nil else { return } - let answer = debugAnswers?.isEmpty == false ? debugAnswers!.removeFirst() : "abort" + /// Test hook: launch with `-debugAnswerAlerts "switch=first,move=second"`. + /// Each named alert (switch, import, trash, move, explain, error) gets that + /// answer after 3 seconds, time for a screenshot; any alert not named is + /// aborted, which records nothing and moves nothing. + private static let debugAnswers: [String: String]? = UserDefaults.standard.string(forKey: "debugAnswerAlerts").map { + Dictionary($0.split(separator: ",").compactMap { pair -> (String, String)? in + let parts = pair.split(separator: "=", maxSplits: 1).map(String.init) + return parts.count == 2 ? (parts[0], parts[1]) : nil + }, uniquingKeysWith: { _, last in last }) + } + + private static func scheduleDebugAnswer(for id: String) { + guard let debugAnswers else { return } + let answer = debugAnswers[id] ?? "abort" let timer = Timer(timeInterval: 3, repeats: false) { _ in - NSLog("AppStoreMigration: debug answer \(answer)") + NSLog("AppStoreMigration: debug answer \(id)=\(answer)") switch answer { case "first": NSApp.stopModal(withCode: .alertFirstButtonReturn) case "second": NSApp.stopModal(withCode: .alertSecondButtonReturn) diff --git a/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift b/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift index 3a721381..92368d33 100644 --- a/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift +++ b/hidden/Features/StatusBar/Engine/NativeVisibilityEngine.swift @@ -246,10 +246,11 @@ final class NativeVisibilityEngine: MenuBarEngine { } // Where macOS 27 knows an app by its bundle id: /Applications (and folders - // in it, such as Setapp's) or ~/Applications. Symlinks are resolved first. + // in it, such as Setapp's). Not ~/Applications: run from there, the arrow + // still disappears on collapse. Symlinks are resolved first. static func isInApplicationsFolder(_ bundleURL: URL, applicationFolders: [URL] = FileManager.default.urls(for: .applicationDirectory, - in: [.localDomainMask, .userDomainMask])) -> Bool { + in: .localDomainMask)) -> Bool { let path = bundleURL.resolvingSymlinksInPath().standardizedFileURL.path return applicationFolders.contains { folder in path.hasPrefix(folder.resolvingSymlinksInPath().standardizedFileURL.path + "/") diff --git a/hidden/en.lproj/Localizable.strings b/hidden/en.lproj/Localizable.strings index 6d70bd47..4416dbc2 100644 --- a/hidden/en.lproj/Localizable.strings +++ b/hidden/en.lproj/Localizable.strings @@ -34,11 +34,10 @@ "Only one Hidden Bar can run at a time. The App Store version stays installed until you choose otherwise." = "Only one Hidden Bar can run at a time. The App Store version stays installed until you choose otherwise."; "Quit and Switch" = "Quit and Switch"; "Cancel" = "Cancel"; -"Hidden Bar can't hide icons from this folder" = "Hidden Bar can't hide icons from this folder"; -"macOS only lets Hidden Bar hide icons when it runs from an Applications folder, and neither /Applications nor the Applications folder in your home folder can take it. Quit Hidden Bar, drag it into /Applications (an administrator may need to do this), then open it from there." = "macOS only lets Hidden Bar hide icons when it runs from an Applications folder, and neither /Applications nor the Applications folder in your home folder can take it. Quit Hidden Bar, drag it into /Applications (an administrator may need to do this), then open it from there."; "OK" = "OK"; -"Hidden Bar is running from outside Applications, and this account can't write to /Applications. It moves to the Applications folder in your home folder instead, then relaunches from there." = "Hidden Bar is running from outside Applications, and this account can't write to /Applications. It moves to the Applications folder in your home folder instead, then relaunches from there."; -"Hidden Bar is running from outside Applications, and the App Store copy stays in /Applications. This version moves to the Applications folder in your home folder instead, then relaunches from there." = "Hidden Bar is running from outside Applications, and the App Store copy stays in /Applications. This version moves to the Applications folder in your home folder instead, then relaunches from there."; +"Hidden Bar can hide icons only from /Applications" = "Hidden Bar can hide icons only from /Applications"; +"The App Store copy is in /Applications. Quit Hidden Bar, move /Applications/Hidden Bar.app to the Trash, drag this copy into Applications, then open it from there." = "The App Store copy is in /Applications. Quit Hidden Bar, move /Applications/Hidden Bar.app to the Trash, drag this copy into Applications, then open it from there."; +"This account can't add apps to /Applications. Ask an administrator to drag Hidden Bar into /Applications, then open it from there." = "This account can't add apps to /Applications. Ask an administrator to drag Hidden Bar into /Applications, then open it from there."; "Set Shortcut" = "Set Shortcut"; "Show Notch Items" = "Show Notch Items"; "Notch Overflow" = "Notch Overflow";