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.

Every reading of the apps takes its turn and checks what changed

Țugui Dragoș9f8977dcfecc
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index 85ef1536..5bb004a9 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -173,15 +173,21 @@ final class AppLibrary {
shown.count > 1
}
+ /// The first reading of the folders, at launch. A reading the folder watch starts meanwhile takes its place
+ /// and lists the apps itself.
func load() async {
isLoading = true
lastRead = .now
- let found = await AppCatalog.installedApps()
- adopt(found)
+ let found = await scanRun.run { await AppCatalog.installedApps() }
+ if let found {
+ adopt(found)
+ }
recall()
isLoading = false
hasLoaded = true
- await AppMemory().remember(found)
+ if let found {
+ await AppMemory().remember(found)
+ }
}
/// Calls `refresh()` unless the folders were read in the last 30 seconds. For Peel coming forward:
@@ -229,6 +235,14 @@ final class AppLibrary {
return changed
}
+ /// Checks again what a reading found at another build: whether it has an update and who signs it, since what
+ /// Peel learned was about the old build.
+ func checkAgain(_ changed: [InstalledApp]) async {
+ guard !changed.isEmpty else { return }
+ await checkForUpdates(changed, force: true)
+ await checkSigningTeams()
+ }
+
/// Takes a new reading of the folders and returns the apps whose build changed. Drops whatever was cached
/// about an app that is gone or a build that was replaced, so an app removed and installed again never
/// shows the old copy's size or update status. Both `load()` and `refresh()` come through here.
diff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swift
index 78e6c54f..435ebeae 100644
--- a/Peel/PeelApp.swift
+++ b/Peel/PeelApp.swift
@@ -138,13 +138,7 @@ struct PeelApp: App {
// A bundle that changed on disk is a different build, and what was cached about it describes the old
// one. Those apps are checked again at once, whoever updated them: Peel, the Homebrew page, or
// `brew upgrade` in Terminal.
- if checksForAppUpdates, !changed.isEmpty {
- await library.checkForUpdates(changed, force: true)
- }
- // A new build may be signed by a different team.
- if !changed.isEmpty {
- await library.checkSigningTeams()
- }
+ await library.checkAgain(changed)
// A newly installed app has never been checked, so it is due. The round checks only the apps that
// are due.
if checksForAppUpdates {
@@ -169,13 +163,7 @@ struct PeelApp: App {
Task {
// Whichever read finds a changed bundle checks it again. When two reads overlap, only the newer
// one reports what changed, and it may be this one rather than the folder watcher's.
- let changed = await library.refreshUnlessRecent()
- if checksForAppUpdates, !changed.isEmpty {
- await library.checkForUpdates(changed, force: true)
- }
- if !changed.isEmpty {
- await library.checkSigningTeams()
- }
+ await library.checkAgain(await library.refreshUnlessRecent())
}
// A watch that could not start, for want of Full Disk Access or for any other reason, is tried again.
if watchesTrash, trashMonitor.status != .watching {
diff --git a/Peel/Views/AppDetailView.swift b/Peel/Views/AppDetailView.swift
index e4f7c1ee..3c49bc14 100644
--- a/Peel/Views/AppDetailView.swift
+++ b/Peel/Views/AppDetailView.swift
@@ -444,7 +444,7 @@ struct AppDetailView: View {
}
if result.trashed.contains(where: { $0.originalURL == plan.app.url }) {
- await library.load()
+ await library.checkAgain(await library.refresh())
} else {
await plan.refresh(installedApps: library.apps, canUseHelper: helper.canAct, casks: homebrew.caskEvidence, receipts: homebrew.receipts)
}
diff --git a/Peel/Views/AppList.swift b/Peel/Views/AppList.swift
index 56f75fb4..2e19969d 100644
--- a/Peel/Views/AppList.swift
+++ b/Peel/Views/AppList.swift
@@ -74,10 +74,7 @@ struct AppList: View {
ToolbarItem {
// The folder watcher reads the apps on its own; this is for someone who has just installed one.
RescanButton(isRunning: $isRescanning, isDisabled: library.isLoading, scan: library.scanRun) {
- let changed = await library.refresh()
- guard !changed.isEmpty else { return }
- await library.checkForUpdates(changed, force: true)
- await library.checkSigningTeams()
+ await library.checkAgain(await library.refresh())
}
}
}
diff --git a/Peel/Views/MultipleAppsView.swift b/Peel/Views/MultipleAppsView.swift
index 1a6ddcb2..228250d6 100644
--- a/Peel/Views/MultipleAppsView.swift
+++ b/Peel/Views/MultipleAppsView.swift
@@ -314,7 +314,7 @@ struct MultipleAppsView: View {
// would fail for each one.
let bundles = Set(plan.apps.map(\.url))
if result.trashed.contains(where: { bundles.contains($0.originalURL) }) {
- await library.load()
+ await library.checkAgain(await library.refresh())
} else {
await plan.refresh(installedApps: library.apps, canUseHelper: helper.canAct, casks: homebrew.caskEvidence, receipts: homebrew.receipts)
}