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
Show the helper on Home as Peel knows it, not as Home last read it
Țugui Dragoș5a19ea64c4bc
diff --git a/Peel/HomeSnapshot.swift b/Peel/HomeSnapshot.swiftindex 8bc4882b..633ba298 100644--- a/Peel/HomeSnapshot.swift+++ b/Peel/HomeSnapshot.swift@@ -12,12 +12,12 @@ enum HomeSnapshot {static func runIfRequested() async {guard let directory else { return }- let home = HomeModel()let helper = HelperModel()+ let home = HomeModel(helper: helper)let stats = LifetimeStats()let found = FoundLastTimeStore()let homebrew = HomebrewLibrary()- await home.refresh(helper: helper)+ await home.refresh()await ExclusionsStore.shared.load()let window = Color(nsColor: .windowBackgroundColor)for scheme in [ColorScheme.light, .dark] {diff --git a/Peel/Model/HelperModel.swift b/Peel/Model/HelperModel.swiftindex f81f79eb..63c67bde 100644--- a/Peel/Model/HelperModel.swift+++ b/Peel/Model/HelperModel.swift@@ -37,6 +37,7 @@ final class HelperModel {/// so a second copy (in a build folder, or a download beside the one in Applications) reads "not installed"/// while the first copy's helper is there. This lets it say why.private(set) var isRegisteredByAnotherCopy = false+ private(set) var hasChecked = falsefunc refresh() {status = PrivilegedHelper.status@@ -55,6 +56,7 @@ final class HelperModel {self.status = statusself.isResponding = isRespondingself.isRegisteredByAnotherCopy = isRegisteredByAnotherCopy+ hasChecked = true}/// Registers the helper, and opens Login Items settings when it needs the user's approval. Perdiff --git a/Peel/Model/HomeModel.swift b/Peel/Model/HomeModel.swiftindex 18bfb207..bc1d9d39 100644--- a/Peel/Model/HomeModel.swift+++ b/Peel/Model/HomeModel.swift@@ -70,7 +70,7 @@ final class HomeModel {case pending/// Only an administrator account can use it, so this account has nothing to set up here.case notThisAccount- /// The helper's row until the helper's first answer, which can take the whole of its wait.+ /// The helper's row until the helper is first checked, which can take the whole of the check's wait.case checkingvar isMissing: Bool { self == .missing }@@ -79,17 +79,14 @@ final class HomeModel {private static let appManagementKey = "appManagementState"private static let modelNameKey = "modelName."+ let helper: HelperModelprivate(set) var device: DeviceInfo?- /// A helper is registered, but by another copy of Peel, and this copy cannot talk to it.- private(set) var isHelperFromAnotherCopy = false/// The Finder extension is on, but macOS runs the one inside another copy of Peel, so this copy reads it as off.private(set) var isFinderExtensionFromAnotherCopy = falseprivate let refreshes = OneRunAtATime()private var isReadingModelName = falseprivate(set) var greeting = Greeting.at(.now)- private(set) var states: [Permission: State] = [:]- private(set) var helperStanding = PrivilegedHelper.Standing.notInstalled- private(set) var isHelperResponding: Bool?+ private var found: [Permission: State] = [:]private(set) var notificationStatus: UNAuthorizationStatus = .notDeterminedprivate(set) var appManagement: AccessState = .unknown/// The App Management state a removal revealed since Peel opened. That answer came from macOS itself,@@ -105,10 +102,20 @@ final class HomeModel {private(set) var hasChecked = falseprivate var hasOpenedFullDiskAccessSettings = false- init() {+ init(helper: HelperModel) {+ self.helper = helperappManagement = AccessState(stored: UserDefaults.standard.string(forKey: Self.appManagementKey))}+ /// What each row shows. The helper's row is the helper model's, as it changes, from Home's first read on.+ var states: [Permission: State] {+ var states = found+ if hasChecked {+ states[.helper] = helperState+ }+ return states+ }+var missingRequired: [Permission] {Permission.allCases.filter { $0.isRequired && state(of: $0).isMissing }}@@ -132,15 +139,15 @@ final class HomeModel {/// Reads again what Home shows: the Mac's details and the state of every permission. One call runs at a/// time, since two overlapping calls would both find nothing read yet, and a call made meanwhile, such as the- /// one after the helper is installed, runs once more when it ends.- func refresh(helper: HelperModel) async {- await refreshes.run { await read(helper: helper) }+ /// one when Peel comes forward, runs once more when it ends.+ func refresh() async {+ await refreshes.run { await read() }// The model's marketing name is the only slow part (a `system_profiler` process), so it is read outside// the runs, which it would otherwise hold up.await readModelName()}- private func read(helper: HelperModel) async {+ private func read() async {greeting = .at(.now)// The card needs none of the checks below, so it is read first and arrives with the window.let isFirstRead = device == nil@@ -162,9 +169,8 @@ final class HomeModel {let fullDisk = await accessneedsRelaunchForFullDiskAccess = fullDisk == .missing && hasOpenedFullDiskAccessSettingslet opensAtLogin = await Self.opensAtLogin()- states = [+ found = [.fullDiskAccess: state(for: fullDisk),- .helper: states[.helper] ?? .checking,.appManagement: state(for: appManagementSeenThisLaunch ?? appManagement),.notifications: notificationStatus == .authorized ? .on : .off,.finderExtension: isFinderExtensionEnabled ? .on : .off,@@ -174,10 +180,6 @@ final class HomeModel {hasChecked = trueawait helperChecked- helperStanding = helper.standing- isHelperResponding = helper.isResponding- isHelperFromAnotherCopy = helper.isRegisteredByAnotherCopy- states[.helper] = helperState// Free space is read every time, since it is how the user sees that a cleanup worked.if !isFirstRead, let device {@@ -213,7 +215,7 @@ final class HomeModel {guard state != appManagement else { return }appManagement = stateUserDefaults.standard.set(state.stored, forKey: Self.appManagementKey)- states[.appManagement] = self.state(for: state)+ found[.appManagement] = self.state(for: state)}func openFullDiskAccessSettings() {@@ -227,7 +229,7 @@ final class HomeModel {appManagementSeenThisLaunch = nilappManagement = .unknownUserDefaults.standard.removeObject(forKey: Self.appManagementKey)- states[.appManagement] = state(for: .unknown)+ found[.appManagement] = state(for: .unknown)NSWorkspace.shared.open(AppManagement.settingsURL)}@@ -251,7 +253,7 @@ final class HomeModel {}_ = try? await UNUserNotificationCenter.current().requestAuthorization(options: [.alert])notificationStatus = await UNUserNotificationCenter.current().notificationSettings().authorizationStatus- states[.notifications] = notificationStatus == .authorized ? .on : .off+ found[.notifications] = notificationStatus == .authorized ? .on : .off}func openFinderExtensionSettings() {@@ -296,7 +298,8 @@ final class HomeModel {/// The helper serves administrator accounts only, so on a standard account it is not missing: there is/// nothing for this account to install.private var helperState: State {- switch helperStanding {+ guard helper.hasChecked else { return .checking }+ return switch helper.standing {case .ready: .oncase .waitingForApproval: .pendingcase .notInstalled, .notAnswering: .missingdiff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swiftindex 6b1e931c..7822461f 100644--- a/Peel/PeelApp.swift+++ b/Peel/PeelApp.swift@@ -52,9 +52,9 @@ struct PeelApp: App {@State private var fileSearch: FileSearchLibrary@State private var plugins = PluginLibrary()@State private var homebrew = HomebrewLibrary()- @State private var helper = HelperModel()+ @State private var helper: HelperModel@State private var updater = PeelUpdater()- @State private var home = HomeModel()+ @State private var home: HomeModel@State private var history: RemovalHistoryStore@State private var outcome: RemovalOutcome@State private var intel = IntelLibrary()@@ -75,6 +75,9 @@ struct PeelApp: App {let notifications = PeelNotifications()notifications.activate()_notifications = State(initialValue: notifications)+ let helper = HelperModel()+ _helper = State(initialValue: helper)+ _home = State(initialValue: HomeModel(helper: helper))let (library, history, outcome) = (AppLibrary(), RemovalHistoryStore(), RemovalOutcome())let (orphans, space, developer, projects) = (@@ -181,7 +184,7 @@ struct PeelApp: App {homebrew.checkInstalled()// Home's checks run again whatever page is showing: permissions change in System Settings, and the// badge on Home in the sidebar shows a missing one. They read the helper's status again too.- Task { await home.refresh(helper: helper) }+ Task { await home.refresh() }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.@@ -291,7 +294,7 @@ struct PeelApp: App {async let apps: Void = Marks.interval("Applications") { await library.load() }// Home's checks run at launch, whichever page opens first. They ask the helper whether it can act,// which every page reads to lock the rows that need it.- await Marks.interval("Home checks") { await home.refresh(helper: helper) }+ await Marks.interval("Home checks") { await home.refresh() }await exclusionsReadtrashMonitor.onApplicationTrashed = { [notifications] url innotifications.notify(applicationTrashed: url)diff --git a/Peel/Views/Home/HomePermissionsView.swift b/Peel/Views/Home/HomePermissionsView.swiftindex 7bd6ca5f..99a194a0 100644--- a/Peel/Views/Home/HomePermissionsView.swift+++ b/Peel/Views/Home/HomePermissionsView.swift@@ -225,7 +225,7 @@ struct HomePermissionsContent: View {}} else if home.needsAttention {let notice = MissingPermissionsNotice(- helper: home.helperStanding,+ helper: helper.standing,othersMissing: home.missingRequired.contains { $0 != .helper })let toSetUp = home.missingRequired.filter { notice == .setUp || $0 != .helper }@@ -297,19 +297,13 @@ struct HomePermissionsContent: View {switch permission {case .helper:// Registering a helper that is already registered returns an error (`SMAppService.h`), so one- // that is registered but does not answer is repaired instead. The row is checked again afterwards.+ // that is registered but does not answer is repaired instead.if state == .pending {home.openLoginItemsSettings()- } else if home.isHelperResponding == false {- Task {- await helper.repair()- await home.refresh(helper: helper)- }+ } else if helper.standing == .notAnswering {+ Task { await helper.repair() }} else {- Task {- await helper.install()- await home.refresh(helper: helper)- }+ Task { await helper.install() }}case .notifications: Task { await home.requestNotifications() }case .fullDiskAccess, .appManagement, .finderExtension, .openAtLogin: reveal(permission)@@ -325,9 +319,9 @@ fileprivate extension HomeModel {return switch (permission, state(of: permission)) {case (_, .checking): "Checking…"case (.helper, .missing):- if isHelperResponding == false {+ if helper.standing == .notAnswering {"Not answering"- } else if isHelperFromAnotherCopy {+ } else if helper.isRegisteredByAnotherCopy {// The helper belongs to the bundle that registered it, and that is not this one."Installed by another copy of Peel"} else {@@ -355,7 +349,7 @@ fileprivate extension HomeModel {switch state {case .on, .notThisAccount, .checking: return nilcase .pending: return "Open System Settings"- case .missing, .off: return isHelperResponding == false ? "Repair" : "Install"+ case .missing, .off: return helper.standing == .notAnswering ? "Repair" : "Install"}case .appManagement: return state == .on ? nil : "Open System Settings"// The optional rows open System Settings from their name, so they need no button. Notifications hasdiff --git a/Peel/Views/Home/HomeView.swift b/Peel/Views/Home/HomeView.swiftindex 5646864d..2eb1b3cd 100644--- a/Peel/Views/Home/HomeView.swift+++ b/Peel/Views/Home/HomeView.swift@@ -3,7 +3,6 @@ import SwiftUIstruct HomeView: View {@Environment(HomeModel.self) private var home- @Environment(HelperModel.self) private var helper@State private var isRescanning = false/// The narrowest width that fits both halves side by side: the left half (360) and the narrowest width the/// permissions read well at (480, which `HomeSnapshot` also renders).@@ -39,7 +38,7 @@ struct HomeView: View {.toolbar {ToolbarItem {RescanButton(isRunning: $isRescanning) {- await home.refresh(helper: helper)+ await home.refresh()}}}