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
Settings no longer offers the helper to a standard account
Țugui Dragoș4e66d62afa93
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift b/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swiftindex 3f3d5a44..99a617a5 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift@@ -13,6 +13,29 @@ public enum PrivilegedHelper {case unavailable}+ /// Whether the helper can act for this account, and if not, why.+ public enum Standing: Sendable, Equatable {+ case ready+ case notInstalled+ case waitingForApproval+ case notThisAccount+ case notAnswering++ /// A standard account comes first: the helper serves administrators only, so its registration says nothing+ /// that account could act on.+ public init(status: Status, isAvailableToThisAccount: Bool, isResponding: Bool?) {+ guard isAvailableToThisAccount else {+ self = .notThisAccount+ return+ }+ self = switch status {+ case .enabled: isResponding == false ? .notAnswering : .ready+ case .requiresApproval: .waitingForApproval+ case .notRegistered, .unavailable: .notInstalled+ }+ }+ }+private static var service: SMAppService {.daemon(plistName: HelperIdentity.launchdPlistName)}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HelperStandingTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HelperStandingTests.swiftnew file mode 100644index 00000000..f73d267a--- /dev/null+++ b/Packages/PeelCore/Tests/PeelCoreTests/HelperStandingTests.swift@@ -0,0 +1,31 @@+@testable import PeelCore+import Testing++struct HelperStandingTests {+ private let statuses: [PrivilegedHelper.Status] = [.notRegistered, .requiresApproval, .enabled, .unavailable]++ /// The helper serves administrators only, so a standard account is never offered to install, approve or repair+ /// it, whatever its registration says.+ @Test func aStandardAccountNeedsAnAdministratorWhateverTheRegistration() {+ for status in statuses {+ for isResponding in [true, false, nil] as [Bool?] {+ let standing = PrivilegedHelper.Standing(+ status: status, isAvailableToThisAccount: false, isResponding: isResponding+ )+ #expect(standing == .notThisAccount)+ }+ }+ }++ @Test func anAdministratorSeesWhatTheRegistrationSays() {+ func standing(_ status: PrivilegedHelper.Status, _ isResponding: Bool?) -> PrivilegedHelper.Standing {+ PrivilegedHelper.Standing(status: status, isAvailableToThisAccount: true, isResponding: isResponding)+ }+ #expect(standing(.enabled, true) == .ready)+ #expect(standing(.enabled, nil) == .ready)+ #expect(standing(.enabled, false) == .notAnswering)+ #expect(standing(.requiresApproval, nil) == .waitingForApproval)+ #expect(standing(.notRegistered, nil) == .notInstalled)+ #expect(standing(.unavailable, nil) == .notInstalled)+ }+}diff --git a/Peel/Model/HelperModel.swift b/Peel/Model/HelperModel.swiftindex 7cefb75d..2a5fa6be 100644--- a/Peel/Model/HelperModel.swift+++ b/Peel/Model/HelperModel.swift@@ -18,38 +18,21 @@ final class HelperModel {/// Whether the helper can move items: it is registered, this account may use it, and it has not failed to/// answer. Otherwise the items that need it stay locked.var canAct: Bool {- status == .enabled && isAvailableToThisAccount && isResponding != false+ standing == .ready}var isEnabled: Bool {status == .enabled}- /// Whether the helper can act, and if not, why. Shown in the banner over a list that holds items needing it.- enum Standing {- case ready- case notInstalled- case waitingForApproval- case notThisAccount- case notAnswering- }-- var standing: Standing {- if !isAvailableToThisAccount { return .notThisAccount }- return switch status {- case .enabled: isResponding == false ? .notAnswering : .ready- case .requiresApproval: .waitingForApproval- case .notRegistered, .unavailable: .notInstalled- }+ var standing: PrivilegedHelper.Standing {+ PrivilegedHelper.Standing(+ status: status, isAvailableToThisAccount: isAvailableToThisAccount, isResponding: isResponding+ )}let isAvailableToThisAccount = PrivilegedHelper.isAvailableToThisAccount- /// Registered, but not answering as the helper this version of Peel works with.- var isStale: Bool {- status == .enabled && isResponding == false && isAvailableToThisAccount- }-/// True when a Peel helper is registered, but not by this copy of Peel. Registration belongs to a bundle,/// 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.diff --git a/Peel/Model/HomeModel.swift b/Peel/Model/HomeModel.swiftindex a45460ea..7937a813 100644--- a/Peel/Model/HomeModel.swift+++ b/Peel/Model/HomeModel.swift@@ -86,9 +86,8 @@ final class HomeModel {private var isReadingModelName = falseprivate(set) var greeting = Greeting.at(.now)private(set) var states: [Permission: State] = [:]- private(set) var helperStatus: PrivilegedHelper.Status = .notRegistered+ private(set) var helperStanding = PrivilegedHelper.Standing.notInstalledprivate(set) var isHelperResponding: Bool?- private(set) var isHelperAvailable = trueprivate(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,@@ -149,10 +148,9 @@ final class HomeModel {async let bundles = AppManagement.state()await helper.checkConnection()- helperStatus = helper.status+ helperStanding = helper.standingisHelperResponding = helper.isRespondingisHelperFromAnotherCopy = helper.isRegisteredByAnotherCopy- isHelperAvailable = helper.isAvailableToThisAccountnotificationStatus = await UNUserNotificationCenter.current().notificationSettings().authorizationStatuslet isFinderExtensionEnabled = await Self.isFinderExtensionEnabled()isFinderExtensionFromAnotherCopy = isFinderExtensionEnabled ? false : await Self.finderExtensionRunsFromAnotherCopy()@@ -283,11 +281,11 @@ 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 {- guard isHelperAvailable else { return .notThisAccount }- return switch helperStatus {- case .enabled: isHelperResponding == false ? .missing : .on- case .requiresApproval: .pending- case .notRegistered, .unavailable: .missing+ switch helperStanding {+ case .ready: .on+ case .waitingForApproval: .pending+ case .notInstalled, .notAnswering: .missing+ case .notThisAccount: .notThisAccount}}diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swiftindex a0536d25..cfc65b3f 100644--- a/Peel/Views/Settings/SettingsView.swift+++ b/Peel/Views/Settings/SettingsView.swift@@ -486,13 +486,13 @@ private struct HelperSettingsView: View {}Section {- switch helper.status {- case .notRegistered, .unavailable:+ switch helper.standing {+ case .notInstalled:Button("Install Helper", systemImage: "lock.shield") {helper.install()}.centeredInRow()- case .requiresApproval:+ case .waitingForApproval:Text("Allow Peel in System Settings under Login Items & Extensions.").font(.callout)// Opens System Settings instead of registering again, which returns an error in this state@@ -501,26 +501,25 @@ private struct HelperSettingsView: View {PrivilegedHelper.openLoginItemsSettings()}.centeredInRow()- case .enabled:- if !helper.isAvailableToThisAccount {- Text("Only an administrator can use the helper. Log in as an administrator to remove items that need one.")- .font(.callout)- } else if helper.isStale {- // `isStale` covers several causes, and they share this message: an older or newer- // helper, a signature that doesn't match, or a helper that didn't start.- Text("Peel’s helper isn’t answering. Repairing it installs the one this version of Peel works with.")- .font(.callout)- Button("Repair Helper", systemImage: "arrow.clockwise") {- Task { await helper.repair() }- }- .disabled(helper.isChanging)- .centeredInRow()+ case .notThisAccount:+ Text("Only an administrator can use the helper. Log in as an administrator to remove items that need one.")+ .font(.callout)+ if helper.isEnabled {+ uninstallButton}- Button("Uninstall Helper", systemImage: "trash", role: .destructive) {- Task { await helper.uninstall() }+ case .notAnswering:+ // Several causes share this message: an older or newer helper, a signature that doesn't+ // match, or a helper that didn't start.+ Text("Peel’s helper isn’t answering. Repairing it installs the one this version of Peel works with.")+ .font(.callout)+ Button("Repair Helper", systemImage: "arrow.clockwise") {+ Task { await helper.repair() }}.disabled(helper.isChanging).centeredInRow()+ uninstallButton+ case .ready:+ uninstallButton}}.listRowBackground(Color.clear)@@ -536,18 +535,26 @@ private struct HelperSettingsView: View {}}+ private var uninstallButton: some View {+ Button("Uninstall Helper", systemImage: "trash", role: .destructive) {+ Task { await helper.uninstall() }+ }+ .disabled(helper.isChanging)+ .centeredInRow()+ }+@ViewBuilderprivate var statusBadge: some View {- switch helper.status {- case .enabled where !helper.isAvailableToThisAccount:+ switch helper.standing {+ case .notThisAccount:state("Needs an administrator", "person.crop.circle.badge.exclamationmark", .orange)- case .enabled where helper.isResponding == false:+ case .notAnswering:state("Not answering", "exclamationmark.triangle", .orange)- case .enabled:+ case .ready:state("Installed", "checkmark.circle", .green)- case .requiresApproval:+ case .waitingForApproval:state("Needs approval, or was turned off", "clock", .orange)- case .notRegistered, .unavailable:+ case .notInstalled:state("Not installed", "minus.circle", .secondary)}}