Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Count and export only the apps installed on this Mac

Țugui Dragoșe9c6f08ac33b
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 7ea161fa..e966c9f1 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -52510,6 +52510,112 @@
}
}
},
+ "Homebrew didn’t answer, so no app in the list is marked as installed by it. Open Homebrew in Peel to see why." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew neodpověděl, takže žádná aplikace v seznamu není označená jako nainstalovaná přes Homebrew. Otevřete v Peelu stránku Homebrew a uvidíte proč."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew hat nicht geantwortet, daher ist keine App in der Liste als von Homebrew installiert markiert. Öffne die Seite „Homebrew“ in Peel, um zu sehen, warum."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew no ha respondido, así que ninguna app de la lista aparece marcada como instalada con Homebrew. Abre Homebrew en Peel para ver por qué."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew n’a pas répondu : aucune app de la liste n’est donc marquée comme installée par Homebrew. Ouvrez la page Homebrew dans Peel pour savoir pourquoi."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew non ha risposto, quindi nessuna app dell’elenco è contrassegnata come installata da Homebrew. Apri la pagina Homebrew in Peel per vedere perché."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrewが応答しなかったため、リスト内のどのアプリも、Homebrewでインストールされたものとしてマークされません。理由を確認するには、PeelでHomebrewを開いてください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew가 응답하지 않아 목록의 어떤 앱도 Homebrew가 설치한 것으로 표시되지 않습니다. Peel에서 Homebrew 페이지를 열어 이유를 확인하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew reageerde niet, dus is geen enkele app in de lijst gemarkeerd als door Homebrew geïnstalleerd. Open de pagina 'Homebrew' in Peel om te zien waarom."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew nie odpowiedział, więc żadna aplikacja na liście nie jest oznaczona jako zainstalowana przez Homebrew. Otwórz stronę Homebrew w Peel, aby zobaczyć, dlaczego."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Homebrew não respondeu, então nenhum app da lista está marcado como instalado por ele. Abra a página Homebrew no Peel para ver o motivo."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew nu a răspuns, așa că nicio aplicație din listă nu este marcată ca instalată de acesta. Deschideți pagina Homebrew în Peel pentru a vedea de ce."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew не ответил, поэтому ни одно приложение в списке не отмечено как установленное им. Откройте страницу Homebrew в Peel, чтобы узнать причину."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew svarade inte, så ingen app i listan är märkt som installerad av Homebrew. Öppna sidan Homebrew i Peel för att se varför."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew yanıt vermedi, bu yüzden listedeki hiçbir uygulama Homebrew tarafından yüklenmiş olarak işaretlenmedi. Nedenini görmek için Peel’de Homebrew’u açın."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew не відповів, тож жодну програму в списку не позначено як інстальовану ним. Відкрийте сторінку «Homebrew» у Peel, щоб побачити, чому."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew没有回应,因此列表中没有任何App被标记为由Homebrew安装。在Peel中打开Homebrew页面即可查看原因。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew沒有回應,因此列表中沒有任何App被標記為由它安裝。請在Peel中打開「Homebrew」頁面查看原因。"
+ }
+ }
+ }
+ },
"Homebrew didn’t say what is installed" : {
"localizations" : {
"cs" : {
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index 6c5a5d61..2d6bc8ec 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -87,7 +87,7 @@ final class AppLibrary {
if updateRounds.checking.isEmpty {
heldUpdates = nil
} else if oldValue.checking.isEmpty {
- heldUpdates = Set(appsWithUpdates.map(\.id))
+ heldUpdates = Set(apps.filter(hasUpdate).map(\.id))
}
}
}
@@ -703,13 +703,21 @@ final class AppLibrary {
app.isPeelItself ? nil : updatePreferences.shownStatus(updateStatuses[app.id], for: app)
}
- var appsWithUpdates: [InstalledApp] { apps.filter(hasUpdate) }
+ /// The apps the reading of the folders found, without those shown on the list from elsewhere: what is installed,
+ /// as `peel inventory` lists it.
+ var installedApps: [InstalledApp] {
+ apps.filter { app in !revealed.contains { $0.id == app.id } }
+ }
+
+ /// The installed apps with an update waiting, which the menu bar, its notification and the list's summary count.
+ /// An app shown from elsewhere keeps its update on its row and its page.
+ var appsWithUpdates: [InstalledApp] { installedApps.filter(hasUpdate) }
/// The apps the menu bar item and its panel count. They follow `hasUpdate(_:)`, but while a round of checks runs
/// they are the ones from when the round began.
var menuBarUpdates: [InstalledApp] {
guard let heldUpdates else { return appsWithUpdates }
- return apps.filter { heldUpdates.contains($0.id) }
+ return installedApps.filter { heldUpdates.contains($0.id) }
}
var menuBarUpdateCount: Int { menuBarUpdates.count }
diff --git a/Peel/Model/InventoryExport.swift b/Peel/Model/InventoryExport.swift
index 130c8989..0ec19bd7 100644
--- a/Peel/Model/InventoryExport.swift
+++ b/Peel/Model/InventoryExport.swift
@@ -13,6 +13,14 @@ enum InventoryExport {
library.hasLoaded && !(homebrew.isInstalled && homebrew.packages == nil)
}
+ /// The packages the list marks apps with, and whether Homebrew, installed, gave none: then no app is marked as
+ /// installed by it, as `peel inventory` does, rather than by a list from before.
+ static func casks(
+ isInstalled: Bool, hasAnswered: Bool, packages: [HomebrewPackage]?
+ ) -> (casks: [HomebrewPackage], didNotAnswer: Bool) {
+ isInstalled && !hasAnswered ? ([], true) : (packages ?? [], false)
+ }
+
/// Asks the user where to save the list, writes it there, and says in an alert when it could not.
@MainActor
static func save(_ format: Inventory.Format, apps: [InstalledApp], homebrew: HomebrewLibrary) async {
@@ -40,8 +48,11 @@ enum InventoryExport {
return error.output
}
}
+ let marking = casks(
+ isInstalled: homebrew.isInstalled, hasAnswered: homebrew.hasAnswered, packages: homebrew.packages
+ )
do {
- contents = try await written(format, apps: apps, casks: homebrew.packages ?? [], brewfile: brewfile)
+ contents = try await written(format, apps: apps, casks: marking.casks, brewfile: brewfile)
} catch is Inventory.HomebrewDidNotAnswer {
return String(localized: "Homebrew didn’t answer, so Peel has nothing to write a Brewfile from. Open Homebrew in Peel to see why.")
} catch {
@@ -54,6 +65,9 @@ enum InventoryExport {
panel.canCreateDirectories = true
panel.isExtensionHidden = false
panel.message = String(localized: "Where should Peel save the list?")
+ if marking.didNotAnswer, format != .brewfile {
+ panel.message += "\n" + String(localized: "Homebrew didn’t answer, so no app in the list is marked as installed by it. Open Homebrew in Peel to see why.")
+ }
if let type = contentType(for: format) {
panel.allowedContentTypes = [type]
}
@@ -93,7 +107,7 @@ struct ExportListMenuContent: View {
var body: some View {
ForEach(Inventory.Format.offered(by: homebrew), id: \.self) { format in
Button(String(localized: format.title)) {
- Task { await InventoryExport.save(format, apps: library.apps, homebrew: homebrew) }
+ Task { await InventoryExport.save(format, apps: library.installedApps, homebrew: homebrew) }
}
}
}
diff --git a/PeelTests/AppLibraryTests.swift b/PeelTests/AppLibraryTests.swift
index f622b4fb..821b8ff0 100644
--- a/PeelTests/AppLibraryTests.swift
+++ b/PeelTests/AppLibraryTests.swift
@@ -596,6 +596,43 @@ private nonisolated final class TestClock: Sendable {
#expect(library.releaseNotes.asks("org.example.fed", version: "1.1"))
}
+ @Test func anAppShownFromElsewhereIsNeitherCountedNorExported() async throws {
+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
+ let bundle = try caskApp("Fed", in: folder, feed: "https://feed.example.com/appcast.xml")
+ defer { try? FileManager.default.removeItem(at: folder) }
+ let made = try MadeUpDefaults()
+ defer { made.forget() }
+ AppcastProtocol.body.withLock {
+ $0 = Data("""
+ <rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"><channel><item>\
+ <enclosure url="https://feed.example.com/u.zip" sparkle:version="101" sparkle:shortVersionString="1.1" />\
+ </item></channel></rss>
+ """.utf8)
+ }
+ let library = library(with: made.defaults, notesIn: folder)
+ #expect(await library.reveal([bundle]))
+ let app = try #require(library.apps.first { $0.bundleIdentifier == "org.example.fed" })
+
+ await library.checkForUpdates([app], force: true)
+
+ #expect(library.hasUpdate(app))
+ #expect(library.visibleApps(matching: "").waiting.map(\.id) == [app.id])
+ #expect(library.installedApps.isEmpty)
+ #expect(library.appsWithUpdates.isEmpty)
+ #expect(library.menuBarUpdateCount == 0)
+ }
+
+ @Test func anExportMarksNoAppAsHomebrewsWhenHomebrewDidNotAnswer() {
+ let earlier = [HomebrewPackage(name: "fed", kind: .cask, installedVersion: "1.0", appNames: ["Fed.app"])]
+
+ let silent = InventoryExport.casks(isInstalled: true, hasAnswered: false, packages: earlier)
+ let answered = InventoryExport.casks(isInstalled: true, hasAnswered: true, packages: earlier)
+ let none = InventoryExport.casks(isInstalled: false, hasAnswered: false, packages: nil)
+ #expect(silent.casks.isEmpty && silent.didNotAnswer)
+ #expect(answered.casks == earlier && !answered.didNotAnswer)
+ #expect(none.casks.isEmpty && !none.didNotAnswer)
+ }
+
@Test func twoCopiesOfAnAppAtTwoBuildsKeepAnAnswerEach() async throws {
let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
defer { try? FileManager.default.removeItem(at: folder) }