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
Tell of each waiting update once, whoever found it
Țugui Dragoșbfb0bb0aee7b
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/AnnouncedUpdates.swift b/Packages/PeelCore/Sources/PeelCore/Updates/AnnouncedUpdates.swiftnew file mode 100644index 00000000..b7f08b16--- /dev/null+++ b/Packages/PeelCore/Sources/PeelCore/Updates/AnnouncedUpdates.swift@@ -0,0 +1,24 @@+/// The version of each app's waiting update Peel has told the person of, by the app's `reference`, so each update is+/// told of once, whoever found it: a round of checks or a reading of Homebrew.+public struct AnnouncedUpdates: Equatable, Sendable {+ public private(set) var versions: [String: String]++ public init(versions: [String: String] = [:]) {+ self.versions = versions+ }++ /// The apps in `waiting` whose update `version` hasn't been told of, which then count as told. None while a round+ /// of checks runs, so an update is told of once every round that may find it has ended.+ public mutating func takeNew(+ _ waiting: [InstalledApp], version: (InstalledApp) -> String?, whileChecking isChecking: Bool+ ) -> [InstalledApp] {+ guard !isChecking else { return [] }+ let new = waiting.compactMap { app in+ version(app).flatMap { versions[app.reference] == $0 ? nil : (app, $0) }+ }+ for (app, version) in new {+ versions[app.reference] = version+ }+ return new.map(\.0)+ }+}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AnnouncedUpdatesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AnnouncedUpdatesTests.swiftnew file mode 100644index 00000000..727663bb--- /dev/null+++ b/Packages/PeelCore/Tests/PeelCoreTests/AnnouncedUpdatesTests.swift@@ -0,0 +1,27 @@+import Foundation+@testable import PeelCore+import Testing++struct AnnouncedUpdatesTests {+ private let editor = InstalledApp(+ url: URL(filePath: "/Applications/Editor.app"), bundleIdentifier: "org.example.editor", name: "Editor"+ )+ private let viewer = InstalledApp(+ url: URL(filePath: "/Applications/Viewer.app"), bundleIdentifier: "org.example.viewer", name: "Viewer"+ )++ @Test func tellsOfEachUpdateOnceWhoeverFoundIt() {+ var versions = ["org.example.editor": "2.0", "org.example.viewer": "5.0"]+ var told = AnnouncedUpdates()++ #expect(told.takeNew([editor], version: { versions[$0.reference] }, whileChecking: true).isEmpty)+ #expect(told.takeNew([editor], version: { versions[$0.reference] }, whileChecking: false) == [editor])+ #expect(told.takeNew([editor, viewer], version: { versions[$0.reference] }, whileChecking: false) == [viewer])+ #expect(told.takeNew([editor, viewer], version: { versions[$0.reference] }, whileChecking: false).isEmpty)++ versions["org.example.editor"] = "2.1"+ let relaunched = AnnouncedUpdates(versions: told.versions)+ var again = relaunched+ #expect(again.takeNew([editor, viewer], version: { versions[$0.reference] }, whileChecking: false) == [editor])+ }+}diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swiftindex 0bfa7507..31543e28 100644--- a/Peel/Model/AppLibrary.swift+++ b/Peel/Model/AppLibrary.swift@@ -151,6 +151,7 @@ final class AppLibrary {var isFiltering: Bool { !sources.isEmpty || selectedDeveloper != nil || showsOnlyUnused }private var memory: UpdateMemories+ @ObservationIgnored private var announced: AnnouncedUpdates/// What is new in each waiting update, read at launch, so a page shows it with no connection too.private(set) var releaseNotes = ReleaseNotesMemory()private let releaseNotesStore: ReleaseNotesStore@@ -178,6 +179,9 @@ final class AppLibrary {self.releaseNotesStore = releaseNotesStoreignoredApps = Set(defaults.stringArray(forKey: SettingsKey.ignoredUpdateApps) ?? [])skippedVersions = defaults.dictionary(forKey: SettingsKey.skippedUpdateVersions) as? [String: String] ?? [:]+ announced = AnnouncedUpdates(+ versions: defaults.dictionary(forKey: SettingsKey.announcedUpdates) as? [String: String] ?? [:]+ )memory = UpdateMemoryStore.load(from: defaults)}@@ -378,6 +382,10 @@ final class AppLibrary {lastUpdateChecks[app.id] = checked}}+ // Before Peel noted what it told of, the updates found earlier were told of as they were found.+ if defaults.object(forKey: SettingsKey.announcedUpdates) == nil {+ _ = updatesToAnnounce()+ }}/// Measures the apps with no size yet. Each bundle needs a walk of every file, so sizes arrive after the list.@@ -751,6 +759,18 @@ final class AppLibrary {var menuBarUpdateCount: Int { menuBarUpdates.count }+ /// The installed apps whose waiting update no notification has named, which then count as named+ /// (`AnnouncedUpdates`), kept across launches.+ func updatesToAnnounce() -> [InstalledApp] {+ let new = announced.takeNew(+ appsWithUpdates, version: { updateStatuses[$0.id]?.version }, whileChecking: !appsCheckingForUpdates.isEmpty+ )+ if !new.isEmpty || defaults.object(forKey: SettingsKey.announcedUpdates) == nil {+ defaults.set(announced.versions, forKey: SettingsKey.announcedUpdates)+ }+ return new+ }+var updateSource: UpdateSource {UpdateSource(rawValue: defaults.string(forKey: SettingsKey.updateSource) ?? "") ?? .automatic}diff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swiftindex 1f9d1950..310913ba 100644--- a/Peel/PeelApp.swift+++ b/Peel/PeelApp.swift@@ -130,6 +130,23 @@ struct PeelApp: App {}}+ /// Brings every new reading of Homebrew to Applications, whoever started it: the Homebrew page's Update Homebrew+ /// too, after which Homebrew's own mark no longer changes.+ private func followHomebrew() async {+ for await _ in Observations({ (homebrew.revision, homebrew.evidenceRevision) }) {+ library.loadHomebrewCasks(homebrew.caskEvidence, knowsItsOwnApps: homebrew.knowsItsOwnApps)+ }+ }++ /// Tells of the updates no notification has named yet, once no round of checks runs, whoever found them.+ private func followUpdates() async {+ for await _ in Observations({ (library.updatesRevision, library.revision, library.appsCheckingForUpdates) }) {+ let found = library.updatesToAnnounce()+ guard let first = found.first else { continue }+ notifications.notify(updatesAvailable: found.count, firstName: first.name, firstApp: first.url)+ }+ }+/// Tells the Trash watch where the listed apps are, so it watches the Trash of each other disk they are on.private func followAppsForTheTrash() async {for await _ in Observations({ library.revision }) {@@ -179,7 +196,7 @@ struct PeelApp: App {// A newly installed app has never been checked, so it is due. The round checks only the apps that// are due.if checksForAppUpdates {- await checkForUpdates()+ await library.checkForUpdates(library.apps)}}@@ -249,7 +266,7 @@ struct PeelApp: App {try? await Task.sleep(for: .seconds(Self.updateCheckInterval), tolerance: .seconds(60))guard !Task.isCancelled, checksForAppUpdates else { continue }await followHomebrewsChecks()- await checkForUpdates()+ await library.checkForUpdates(library.apps)}}@@ -303,7 +320,7 @@ struct PeelApp: App {Navigator.shared.openWindow = openWindowbackground.start([followFolders, followAppsForTheTrash, askWhenDue, followFindings, followActivations, watchFreeSpace,- followHelper,+ followHelper, followHomebrew, followUpdates,])textEditing.start()sheetInFront.start()@@ -345,19 +362,11 @@ struct PeelApp: App {library.loadHomebrewCasks(homebrew.caskEvidence, knowsItsOwnApps: homebrew.knowsItsOwnApps)await Marks.interval("Signing teams") { await library.checkSigningTeams() }if checksForAppUpdates {- await Marks.interval("Update checks") { await checkForUpdates() }+ await Marks.interval("Update checks") { await library.checkForUpdates(library.apps) }}await homeChecked}- /// Checks the apps that are due, and posts one notification when updates appear that were not waiting before.- private func checkForUpdates() async {- let before = Set(library.appsWithUpdates.map(\.id))- await library.checkForUpdates(library.apps)- let found = library.appsWithUpdates.filter { !before.contains($0.id) }- guard !found.isEmpty else { return }- notifications.notify(updatesAvailable: found.count, firstName: found[0].name, firstApp: found[0].url)- }/// Whether the menu bar item shows. `MenuBarExtra` writes it back at every scene update, and each write to an/// `AppStorage` makes every `AppStorage` in the app read again, so a write of the value it holds is left out.diff --git a/Peel/Views/AppList.swift b/Peel/Views/AppList.swiftindex 00d4656c..10910fda 100644--- a/Peel/Views/AppList.swift+++ b/Peel/Views/AppList.swift@@ -4,7 +4,6 @@ import SwiftUIstruct AppList: View {@Environment(AppLibrary.self) private var library- @Environment(HomebrewLibrary.self) private var homebrew@Environment(ExclusionsStore.self) private var exclusions@State private var isRescanning = falselet searchText: String@@ -103,9 +102,6 @@ struct AppList: View {.task(id: library.revision) {await library.loadSizes()}- .task(id: homebrew.revision) {- library.loadHomebrewCasks(homebrew.caskEvidence, knowsItsOwnApps: homebrew.knowsItsOwnApps)- }}private func row(for app: InstalledApp, isExcluded: Bool) -> some View {diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swiftindex 430724db..a38383ec 100644--- a/Peel/Views/Settings/SettingsView.swift+++ b/Peel/Views/Settings/SettingsView.swift@@ -145,6 +145,7 @@ enum SettingsKey {static let ignoredUpdateApps = UpdatePreferences.Key.ignoredAppsstatic let skippedUpdateVersions = UpdatePreferences.Key.skippedVersionsstatic let updateMemory = "updateMemory"+ static let announcedUpdates = "updates.announced"/// Nil once the link leads to this copy's tool, and while something that may not be Peel's is where it goes.static func commandLineInstallCommand(