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.

Home reads the helper's and login item's status off the main thread

Țugui Dragoșbfc51bd35573
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift b/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift
index 18324480..82a60e7a 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift
@@ -50,6 +50,12 @@ public enum PrivilegedHelper {
}
}
+ /// `status`, read away from the caller's actor: `SMAppService` asks `smd` over XPC, which takes milliseconds.
+ @concurrent
+ public static func currentStatus() async -> Status {
+ status
+ }
+
public static func register() throws {
try service.register()
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HelperStandingTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HelperStandingTests.swift
index f73d267a..2dc71446 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/HelperStandingTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/HelperStandingTests.swift
@@ -4,6 +4,18 @@ import Testing
struct HelperStandingTests {
private let statuses: [PrivilegedHelper.Status] = [.notRegistered, .requiresApproval, .enabled, .unavailable]
+ @MainActor @Test func readsTheStatusAwayFromTheMainActor() async {
+ final class Turn {
+ var taken = false
+ }
+ let turn = Turn()
+ Task { @MainActor in turn.taken = true }
+
+ _ = await PrivilegedHelper.currentStatus()
+
+ #expect(turn.taken)
+ }
+
/// 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() {
diff --git a/Peel/Model/HelperModel.swift b/Peel/Model/HelperModel.swift
index 2a5fa6be..e43c782b 100644
--- a/Peel/Model/HelperModel.swift
+++ b/Peel/Model/HelperModel.swift
@@ -43,7 +43,7 @@ final class HelperModel {
}
func checkConnection() async {
- refresh()
+ status = await PrivilegedHelper.currentStatus()
isResponding = status == .enabled ? await PrivilegedHelper.isResponding() : nil
isRegisteredByAnotherCopy = status == .notRegistered ? await PrivilegedHelper.isRegisteredByAnyCopy() : false
}
diff --git a/Peel/Model/HomeModel.swift b/Peel/Model/HomeModel.swift
index b7c4db2f..4f6db6db 100644
--- a/Peel/Model/HomeModel.swift
+++ b/Peel/Model/HomeModel.swift
@@ -158,13 +158,14 @@ final class HomeModel {
let fullDisk = await access
needsRelaunchForFullDiskAccess = fullDisk == .missing && hasOpenedFullDiskAccessSettings
let appBundles = await bundles
+ let opensAtLogin = await Self.opensAtLogin()
states = [
.fullDiskAccess: state(for: fullDisk),
.helper: helperState,
.appManagement: state(for: appManagementSeenThisLaunch ?? (appBundles == .unknown ? appManagement : appBundles)),
.notifications: notificationStatus == .authorized ? .on : .off,
.finderExtension: isFinderExtensionEnabled ? .on : .off,
- .openAtLogin: SMAppService.mainApp.status == .enabled ? .on : .off,
+ .openAtLogin: opensAtLogin ? .on : .off,
.commandLine: CommandLineTool.isOnThePath(embedded: Bundle.main.bundleURL.appending(path: "Contents/Helpers/peel")) ? .on : .off,
]
hasChecked = true
@@ -255,6 +256,12 @@ final class HomeModel {
FIFinderSyncController.isExtensionEnabled
}
+ /// Off the main thread: `SMAppService` asks `smd` over XPC.
+ @concurrent
+ private static func opensAtLogin() async -> Bool {
+ SMAppService.mainApp.status == .enabled
+ }
+
private static func finderExtensionRunsFromAnotherCopy() async -> Bool {
guard let own = Bundle.main.builtInPlugInsURL.flatMap({ Bundle(url: $0.appending(path: "PeelFinder.appex")) }),
let identifier = own.bundleIdentifier