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
Say on Extensions when a system extension's app is gone
Țugui Dragoșf3f3cd4986c9
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex aea1e622..e9ec679d 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -5694,6 +5694,112 @@}}},+ "%@, no longer installed" : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, už nenainstalováno"+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, nicht mehr installiert"+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, ya no está instalada"+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, qui n’est plus installé"+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, non più installata"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@(インストールされていません)"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, 더 이상 설치되어 있지 않음"+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, niet meer geïnstalleerd"+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, już niezainstalowana"+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, não está mais instalado"+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, nu mai este instalată"+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, больше не установлено"+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, inte längre installerad"+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, artık yüklü değil"+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@, більше не інстальовано"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@,已不再安装"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@(已不再安裝)"+ }+ }+ }+ },"%@, update available: %@" : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCore/Extensions/AppExtensions.swift b/Packages/PeelCore/Sources/PeelCore/Extensions/AppExtensions.swiftindex b43cceef..e611664c 100644--- a/Packages/PeelCore/Sources/PeelCore/Extensions/AppExtensions.swift+++ b/Packages/PeelCore/Sources/PeelCore/Extensions/AppExtensions.swift@@ -26,6 +26,7 @@ public struct AppExtension: Sendable, Hashable, Identifiable {teamIdentifier: String?,reportedState: String?,installedFor: String? = nil,+ goneApp: String? = nil,category: String? = nil) {self.id = id ?? identifier@@ -39,6 +40,7 @@ public struct AppExtension: Sendable, Hashable, Identifiable {self.teamIdentifier = teamIdentifierself.reportedState = reportedStateself.installedFor = installedFor+ self.goneApp = goneAppself.category = category}@@ -90,6 +92,8 @@ public struct AppExtension: Sendable, Hashable, Identifiable {/// For a system extension, the path of the app macOS's record says it was installed for: the app it is held/// for, or once that app has moved, the app it was installed from.public let installedFor: String?+ /// `installedFor`, when nothing is at that place anymore (`AppExtensions.goneApp(installedFor:)`).+ public let goneApp: String?/// The category `systemextensionsctl` lists a system extension under; nil for an app extension.public let category: String?/// Tells rows apart in a list. The identifier alone can't: while an app updates a system extension, macOS@@ -130,6 +134,19 @@ extension AppExtension {guard #available(macOS 27, *) else { return false }return kind == .systemExtension && category == "com.apple.system_extension.network_extension"}++ /// The name of the app it came with, also once that app is gone.+ public var appName: String? {+ owner ?? goneApp.map { URL(filePath: $0).deletingPathExtension().lastPathComponent }+ }++ /// Why Peel leaves a system extension where it is, as Orphaned Files says it: macOS removes it at the next+ /// restart, System Settings deletes it, or only moving its app removes it. Nil for an app extension.+ public var leftAlone: HoldBack? {+ guard kind == .systemExtension else { return nil }+ if election == .beingRemoved { return .systemExtensionGoingAtRestart }+ return systemSettingsDeletesIt ? .deletableSystemExtension : .systemExtension+ }}public struct CarriedSystemExtensions: Sendable, Hashable {@@ -360,7 +377,9 @@ public enum AppExtensions {/// Returns the system extensions, or nil when `systemextensionsctl` gave no answer Peel can read: its first/// line counts the rows that follow, and a listing read short of it is not understood.- static func systemExtensions(run: Runner) async -> [AppExtension]? {+ static func systemExtensions(+ run: Runner, records: @autoclosure () -> [SystemExtensionRecord] = systemExtensionRecords()+ ) async -> [AppExtension]? {guard let output = await run("/usr/bin/systemextensionsctl", ["list"]) else { return nil }let lines = output.split(whereSeparator: \.isNewline)// Each category is a line of its own, `--- <category> (...)`, above the rows macOS lists under it.@@ -373,9 +392,10 @@ public enum AppExtensions {return parseSystemExtension(String(line)).map { ($0, category) }}guard count(in: lines, /^(\d+) extension\(s\)$/) == rows.count else { return nil }- let records = systemExtensionRecords()+ let records = records()return rows.map { row, category inlet record = record(for: row.identifier, version: row.version, among: records)+ let installedFor = record.flatMap(installedFor)return AppExtension(// During an update, one identifier is listed twice, once for the old version and once for the new.id: [row.identifier, row.version].compactMap(\.self).joined(separator: " "),@@ -388,7 +408,8 @@ public enum AppExtensions {election: election(forSystemExtensionState: row.state),teamIdentifier: row.teamIdentifier,reportedState: row.state,- installedFor: record.flatMap(installedFor),+ installedFor: installedFor,+ goneApp: goneApp(installedFor: installedFor),category: category)}@@ -463,6 +484,10 @@ public enum AppExtensions {return "/" + names[...app].joined(separator: "/")}+ static func goneApp(installedFor: String?) -> String? {+ installedFor.flatMap { URL(filePath: $0).isMissing ? $0 : nil }+ }+/// The record of the extension `systemextensionsctl` listed: the one of its version, or the only one of its/// identifier. During an update an identifier has a record per version, and the other version's copy is not/// this one: no path is better than a wrong one.diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swiftindex 52f0b734..f8845e82 100644--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift@@ -147,11 +147,11 @@ public struct OrphanScanner: Sendable {PathComponents.isPath(PathPattern.comparablePath(of: item.url), inside: staged)}let extensions = found.contains { isStaged($0.item) } ? await systemExtensions() ?? [] : []- let goingAtRestart = Set(- extensions.filter { $0.election == .beingRemoved }.compactMap(\.url).map(PathPattern.comparablePath(of:))- )- let deletable = Set(- extensions.filter(\.systemSettingsDeletesIt).compactMap(\.url).map(PathPattern.comparablePath(of:))+ let leftAlone = Dictionary(+ extensions.compactMap { copy in+ copy.url.flatMap { url in copy.leftAlone.map { (PathPattern.comparablePath(of: url), $0) } }+ },+ uniquingKeysWith: { first, _ in first })let installedFor = Dictionary(extensions.compactMap { copy in@@ -173,9 +173,8 @@ public struct OrphanScanner: Sendable {var item = entry.itemif isStaged(item) {let path = PathPattern.comparablePath(of: item.url)- item.heldBack = goingAtRestart.contains(path) ? .systemExtensionGoingAtRestart- : deletable.contains(path) ? .deletableSystemExtension : .systemExtension- item.installedFor = installedFor[path].flatMap { URL(filePath: $0).isMissing ? $0 : nil }+ item.heldBack = leftAlone[path] ?? .systemExtension+ item.installedFor = AppExtensions.goneApp(installedFor: installedFor[path])return (entry.identifier, item)}if SignInPlugIns.isOne(item.url, root: environment.rootDirectory) {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppExtensionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppExtensionsTests.swiftindex 0a4585a1..8fb59023 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/AppExtensionsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppExtensionsTests.swift@@ -192,6 +192,41 @@ struct AppExtensionsTests {#expect(records.last?.staged == nil)}+ @Test func saysWhenASystemExtensionsAppIsGone() async throws {+ let directory = try TemporaryDirectory()+ let installed = try directory.directory("Applications/Example.app").path(percentEncoded: false)+ let gone = directory.url.appending(path: "Applications/Gone.app").path(percentEncoded: false)+ let listing = """+ 2 extension(s)+ --- com.apple.system_extension.network_extension (Go to 'System Settings > General > Login Items & Extensions > Network Extensions' to modify these system extension(s))+ enabled\tactive\tteamID\tbundleID (version)\tname\t[state]+ *\t*\tTC3Q7MAJXF\torg.example.filter (1.0/1)\tExample Filter\t[activated enabled]+ \t\tTC3Q7MAJXF\torg.example.gone (1.0/1)\tGone Filter\t[activated waiting for user]+ """+ let records = [+ AppExtensions.SystemExtensionRecord(+ identifier: "org.example.filter", version: "1.0/1", staged: nil, container: installed, origin: nil+ ),+ AppExtensions.SystemExtensionRecord(+ identifier: "org.example.gone", version: "1.0/1", staged: nil, container: gone, origin: nil+ ),+ ]+ let leaving = AppExtension(+ identifier: "org.example.leaving", name: "Leaving", kind: .systemExtension, point: nil, owner: nil, url: nil,+ election: .beingRemoved, teamIdentifier: nil, reportedState: nil+ )++ let found = try #require(await AppExtensions.systemExtensions(run: { _, _ in listing }, records: records))+ let filter = try #require(found.first { $0.identifier == "org.example.filter" })+ let left = try #require(found.first { $0.identifier == "org.example.gone" })++ #expect(filter.goneApp == nil)+ #expect(left.goneApp == gone)+ #expect(left.appName == "Gone")+ #expect(left.leftAlone == .systemExtension)+ #expect(leaving.leftAlone == .systemExtensionGoingAtRestart)+ }+@Test func knowsTheAppAnExtensionWasInstalledForOnceFinderMovedIt() {let record = { (container: String?, origin: String?) inAppExtensions.SystemExtensionRecord(diff --git a/Peel/Views/Extensions/ExtensionDetailView.swift b/Peel/Views/Extensions/ExtensionDetailView.swiftindex 956ac8ac..6c2bb4db 100644--- a/Peel/Views/Extensions/ExtensionDetailView.swift+++ b/Peel/Views/Extensions/ExtensionDetailView.swift@@ -25,8 +25,16 @@ struct ExtensionDetailView: View {.help(Text(verbatim: point))}}- if let owner = item.owner {- LabeledContent("Comes with") { Text(verbatim: owner) }+ if let owner = item.appName {+ LabeledContent("Comes with") {+ VStack(alignment: .trailing, spacing: 1) {+ Text(verbatim: owner)+ if item.goneApp != nil {+ Text("No longer installed")+ .font(.caption)+ }+ }+ }}if let team = item.teamIdentifier {LabeledContent("Signed by") {@@ -162,6 +170,8 @@ struct ExtensionDetailView: View {}private var systemExtensionExplanation: LocalizedStringResource {+ // With its app gone, the advice for an installed app leads nowhere: Orphaned Files' words say what does.+ if item.goneApp != nil, let reason = item.leftAlone { return reason.explanation }if #available(macOS 27, *) {return item.systemSettingsDeletesIt? "macOS keeps its own copy of this, apart from the app. Moving the app to the Trash in Finder asks macOS to remove it, and so does choosing Delete Extension from the More button beside it in System Settings > General > Login Items & Extensions > Network Extensions. So Peel leaves that app to Finder."diff --git a/Peel/Views/Extensions/ExtensionList.swift b/Peel/Views/Extensions/ExtensionList.swiftindex b53069a2..369226cd 100644--- a/Peel/Views/Extensions/ExtensionList.swift+++ b/Peel/Views/Extensions/ExtensionList.swift@@ -95,7 +95,10 @@ private struct ExtensionRow: View {Text(verbatim: item.name).lineLimit(1)} details: {- if let owner = item.owner {+ if item.goneApp != nil, let name = item.appName {+ Text("\(name), no longer installed")+ .lineLimit(1)+ } else if let owner = item.owner {Text(verbatim: owner).lineLimit(1)} else if let point = item.pointName {