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
Ask System Settings about a background item only where it can answer
Țugui Dragoș4df7bf9af098
diff --git a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swiftindex 4d9e421d..a9fcd82d 100644--- a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift+++ b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift@@ -295,12 +295,15 @@ struct BackgroundItemDetailView: View {backgroundItems.runningActionItemIDs.contains(item.id) || backgroundItems.isScanning}- /// Returns the job's status in System Settings (Login Items & Extensions), or nil when it has no plist file.- /// Per `SMAppService.h`, `.requiresApproval` also means the user turned the job off, so the text says both.- /// Off the main thread: `SMAppService` asks Background Task Management over XPC.+ /// Returns the job's status in System Settings (Login Items & Extensions), or nil when it has no plist file in a+ /// folder launchd reads, the only ones `SMAppService.h` gives a status for. Per that header, `.requiresApproval`+ /// also means the user turned the job off, so the text says both. Off the main thread: `SMAppService` asks+ /// Background Task Management over XPC.@concurrent- private static func legacyStatus(of item: BackgroundItem) async -> LocalizedStringResource? {- guard let plistURL = item.plistURL else { return nil }+ static func legacyStatus(of item: BackgroundItem) async -> LocalizedStringResource? {+ guard let plistURL = item.plistURL, item.source == .userLibrary || item.source == .systemLibrary else {+ return nil+ }return switch SMAppService.statusForLegacyPlist(at: plistURL) {case .enabled: "Allowed"case .requiresApproval: "Needs approval, or was turned off"diff --git a/PeelTests/BackgroundItemLoginItemsTests.swift b/PeelTests/BackgroundItemLoginItemsTests.swiftnew file mode 100644index 00000000..f4979dc4--- /dev/null+++ b/PeelTests/BackgroundItemLoginItemsTests.swift@@ -0,0 +1,24 @@+import Foundation+@testable import Peel+@testable import PeelCore+import Testing++struct BackgroundItemLoginItemsTests {+ private func job(_ source: BackgroundItem.Source, at path: String) -> BackgroundItem {+ BackgroundItem(+ label: "org.example.agent", kind: .agent, source: source, plistURL: URL(filePath: path),+ program: "/usr/local/bin/agent", runsAtLoad: true, keepsAlive: false, ownerBundleIdentifier: nil,+ ownerName: nil, ownerURL: nil, isOrphan: false, state: .notLoaded, isDisabled: false+ )+ }++ @Test func asksSystemSettingsOnlyAboutAFileInTheFoldersItReads() async {+ let agents = URL.homeDirectory.appending(path: "Library/LaunchAgents/org.example.agent.plist")++ let elsewhere = await BackgroundItemDetailView.legacyStatus(of: job(.otherFile, at: "/Users/Shared/org.example.agent.plist"))+ let documented = await BackgroundItemDetailView.legacyStatus(of: job(.userLibrary, at: agents.path))++ #expect(elsewhere == nil)+ #expect(documented != nil)+ }+}