Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Finding the running copy of Peel among the apps is no longer a search
Țugui Dragoș1e28464b9151
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/InstalledApp.swift b/Packages/PeelCore/Sources/PeelCore/Apps/InstalledApp.swiftindex 612971f4..579d4e0b 100644--- a/Packages/PeelCore/Sources/PeelCore/Apps/InstalledApp.swift+++ b/Packages/PeelCore/Sources/PeelCore/Apps/InstalledApp.swift@@ -31,6 +31,8 @@ public struct InstalledApp: Sendable, Hashable, Identifiable {/// are unregistered first. Also true for the bundle the running code sits inside, such as the Peel that/// embeds the `peel` tool, whatever its name or identifier.public let isPeelItself: Bool+ /// Whether this is the very bundle the running code was started from: the copy of Peel that is running.+ public let isTheRunningCopy: Boolpublic init(url: URL,@@ -70,7 +72,9 @@ public struct InstalledApp: Sendable, Hashable, Identifiable {self.isUseRecorded = isUseRecordedself.dateAdded = dateAddedself.updateFeed = updateFeed- isPeelItself = Self.isPeel(bundleIdentifier, at: url)+ let path = PathPattern.comparablePath(of: url)+ isPeelItself = Self.isPeel(bundleIdentifier, at: path)+ isTheRunningCopy = path == Self.runningBundle}public var id: URL { url }@@ -112,11 +116,11 @@ public struct InstalledApp: Sendable, Hashable, Identifiable {private static let runningBundle = PathPattern.comparablePath(of: Bundle.main.bundleURL)- private static func isPeel(_ bundleIdentifier: String, at url: URL) -> Bool {+ private static func isPeel(_ bundleIdentifier: String, at path: String) -> Bool {let own = HelperIdentity.appIdentifier.lowercased()let identifier = bundleIdentifier.lowercased()if identifier == own || identifier.hasPrefix(own + ".") { return true }- return PathComponents.isPath(runningBundle, inside: PathPattern.comparablePath(of: url))+ return PathComponents.isPath(runningBundle, inside: path)}/// The name Finder shows, which follows the user's language when the app translates it, and the bundle's filediff --git a/Packages/PeelCore/Tests/PeelCoreTests/InstalledAppTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/InstalledAppTests.swiftindex 8187bcce..6ea063f6 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/InstalledAppTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/InstalledAppTests.swift@@ -20,4 +20,14 @@ struct InstalledAppTests {#expect(around.isPeelItself)}++ @Test func theRunningCopyIsTheAppTheCodeRunsFrom() {+ let running = InstalledApp(url: Bundle.main.bundleURL, bundleIdentifier: "org.example.running", name: "Running")+ let around = InstalledApp(url: Bundle.main.bundleURL.deletingLastPathComponent(), bundleIdentifier: "org.example.around", name: "Around")+ let other = InstalledApp(url: URL(filePath: "/Applications/Editor.app"), bundleIdentifier: "org.example.editor", name: "Editor")++ #expect(running.isTheRunningCopy)+ #expect(!around.isTheRunningCopy)+ #expect(!other.isTheRunningCopy)+ }}diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swiftindex 22876ac0..dfc831d5 100644--- a/Peel/Model/AppLibrary.swift+++ b/Peel/Model/AppLibrary.swift@@ -572,9 +572,8 @@ final class AppLibrary {}var newerPeel: PeelUpdate? {- let running = PathPattern.comparablePath(of: Bundle.main.bundleURL)guard- let peel = apps.first(where: { PathPattern.comparablePath(of: $0.url) == running }),+ let peel = apps.first(where: \.isTheRunningCopy),let status = updateStatuses[peel.id], let version = status.displayVersionelse { return nil }let command = status.source == .homebrew ? cask(for: peel).map { "brew upgrade --cask \($0.name)" } : nildiff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swiftindex bf87877f..2d9dd56a 100644--- a/Peel/Views/Settings/SettingsView.swift+++ b/Peel/Views/Settings/SettingsView.swift@@ -475,8 +475,7 @@ extension GeneralSettingsView {/// The cask Homebrew installed this copy of Peel from, found by the rule the Applications list follows.fileprivate var ownCask: HomebrewPackage? {- let own = PathPattern.comparablePath(of: Bundle.main.bundleURL)- guard let app = library.apps.first(where: { PathPattern.comparablePath(of: $0.url) == own }) else { return nil }+ guard let app = library.apps.first(where: \.isTheRunningCopy) else { return nil }return CaskEvidence.installedCask(for: app, in: (homebrew.packages ?? []).filter { $0.kind == .cask })}}