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.

Show Home's rows without waiting for the helper's answer

Țugui Dragoșaa1bdf7c5c98
diff --git a/Peel/Model/HomeModel.swift b/Peel/Model/HomeModel.swift
index 14ef1c8e..18bfb207 100644
--- a/Peel/Model/HomeModel.swift
+++ b/Peel/Model/HomeModel.swift
@@ -70,6 +70,8 @@ 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.
+ case checking
var isMissing: Bool { self == .missing }
}
@@ -98,7 +100,8 @@ final class HomeModel {
private(set) var needsRelaunchForFullDiskAccess = false
/// Peel could not open a fresh copy of itself, so it stayed.
var couldNotRelaunch = false
- /// False until the first check finishes. Until then no state is shown, so the panel never flashes a wrong one.
+ /// False until the first check finishes. Until then no state is shown, so the panel never flashes a wrong one. The
+ /// helper's row is checked apart and says so until its own answer.
private(set) var hasChecked = false
private var hasOpenedFullDiskAccessSettings = false
@@ -123,6 +126,10 @@ final class HomeModel {
states[permission] ?? .pending
}
+ var isStillChecking: Bool {
+ states.values.contains(.checking)
+ }
+
/// 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.
@@ -145,11 +152,8 @@ final class HomeModel {
}
}
async let access = FullDiskAccess.state()
+ async let helperChecked: Void = helper.checkConnection()
- await helper.checkConnection()
- helperStanding = helper.standing
- isHelperResponding = helper.isResponding
- isHelperFromAnotherCopy = helper.isRegisteredByAnotherCopy
notificationStatus = await UNUserNotificationCenter.current().notificationSettings().authorizationStatus
let isFinderExtensionEnabled = await Self.isFinderExtensionEnabled()
isFinderExtensionFromAnotherCopy =
@@ -160,7 +164,7 @@ final class HomeModel {
let opensAtLogin = await Self.opensAtLogin()
states = [
.fullDiskAccess: state(for: fullDisk),
- .helper: helperState,
+ .helper: states[.helper] ?? .checking,
.appManagement: state(for: appManagementSeenThisLaunch ?? appManagement),
.notifications: notificationStatus == .authorized ? .on : .off,
.finderExtension: isFinderExtensionEnabled ? .on : .off,
@@ -169,6 +173,12 @@ final class HomeModel {
]
hasChecked = true
+ await 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 {
self.device = await device.withStorageRead().named(modelName)
diff --git a/Peel/Views/Home/HomePermissionsView.swift b/Peel/Views/Home/HomePermissionsView.swift
index 8d95f088..7bd6ca5f 100644
--- a/Peel/Views/Home/HomePermissionsView.swift
+++ b/Peel/Views/Home/HomePermissionsView.swift
@@ -265,10 +265,14 @@ struct HomePermissionsContent: View {
.foregroundStyle(Album.orange)
.frame(width: 26, height: 26)
VStack(alignment: .leading, spacing: 1) {
- Text(home.hasChecked ? "You’re all set" : "Checking what Peel can reach")
+ Text(home.hasChecked && !home.isStillChecking ? "You’re all set" : "Checking what Peel can reach")
.font(.system(size: 12.5, weight: .bold, design: .rounded))
.foregroundStyle(Album.ink)
- Text(home.hasChecked ? "Peel can see everything it needs to." : "Asking macOS what is allowed.")
+ Text(
+ home.hasChecked && !home.isStillChecking
+ ? "Peel can see everything it needs to."
+ : "Asking macOS what is allowed."
+ )
.font(.subheadline)
.foregroundStyle(.secondary)
}
@@ -319,6 +323,7 @@ fileprivate extension HomeModel {
func status(of permission: Permission) -> LocalizedStringResource {
guard hasChecked else { return "Checking…" }
return switch (permission, state(of: permission)) {
+ case (_, .checking): "Checking…"
case (.helper, .missing):
if isHelperResponding == false {
"Not answering"
@@ -348,7 +353,7 @@ fileprivate extension HomeModel {
case .fullDiskAccess: return state == .on ? nil : "Open System Settings"
case .helper:
switch state {
- case .on, .notThisAccount: return nil
+ case .on, .notThisAccount, .checking: return nil
case .pending: return "Open System Settings"
case .missing, .off: return isHelperResponding == false ? "Repair" : "Install"
}