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.

Stop asking for the helper on a job's page that offers it nothing to do

Țugui Dragoșc4f0956403ae
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift
index c8f0acc8..39c2001d 100644
--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift
+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift
@@ -140,4 +140,22 @@ public struct BackgroundItem: Sendable, Hashable, Identifiable {
public var canMoveToTrash: Bool {
!isSeenOnlyWhileLoaded && plistURL != nil && !usesALabelOfMacOS && !isExcluded
}
+
+ /// Start, Stop, Enable, and Disable, which a job Peel may not control, a job whose state Peel could not read, a
+ /// file named by itself since its label couldn't be read, and a file whose label launchd runs from another file
+ /// don't have. A job loaded from a file elsewhere has only Stop. A job Peel may not disable has only Enable, while
+ /// launchd keeps it disabled.
+ public var offersControls: Bool {
+ guard canBeControlled, state != .unknown, !isNamedByItsFile, !anotherFileIsLoaded else { return false }
+ if canOnlyBeStopped { return true }
+ if #available(macOS 27, *), isLeftByAGoneApp { return true }
+ return !isSeenOnlyWhileLoaded || isDisabled || mayBeDisabled
+ }
+
+ /// Whether the helper would let Peel do more with the job than it can without it: a control the page offers, or the
+ /// move of its file.
+ public var waitsForTheHelper: Bool {
+ guard !isPeelsHelper, !isSystemExtension else { return false }
+ return requiresPrivileges && offersControls || removalRequiresPrivileges && canMoveToTrash
+ }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
index fdb6407b..98b68b7c 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
@@ -5,6 +5,47 @@ import PeelPrivileged
import Testing
struct BackgroundItemActionsTests {
+ @Test func theHelperIsAskedForOnlyWhenThePageCanUseIt() {
+ func daemon(
+ source: BackgroundItem.Source = .systemLibrary,
+ plist: URL? = URL(filePath: "/Library/LaunchDaemons/org.example.job.plist"),
+ isDisabled: Bool = false
+ ) -> BackgroundItem {
+ BackgroundItem(
+ label: "org.example.job", kind: .daemon, source: source, plistURL: plist, program: nil, runsAtLoad: nil,
+ keepsAlive: nil, ownerBundleIdentifier: nil, ownerName: nil, ownerURL: nil, isOrphan: false,
+ state: .loaded, isDisabled: isDisabled
+ )
+ }
+ #expect(daemon().waitsForTheHelper)
+
+ var registered = daemon(source: .app, plist: nil)
+ registered.isManagedByServiceManagement = true
+ #expect(!registered.waitsForTheHelper)
+
+ var turnedOff = daemon(source: .app, plist: nil, isDisabled: true)
+ turnedOff.isManagedByServiceManagement = true
+ #expect(turnedOff.waitsForTheHelper)
+
+ var excluded = daemon()
+ excluded.isExcluded = true
+ #expect(!excluded.waitsForTheHelper)
+
+ var unknown = daemon()
+ unknown.state = .unknown
+ #expect(unknown.waitsForTheHelper)
+
+ var fileOnly = BackgroundItem(
+ label: "org.example.agent", kind: .agent, source: .systemLibrary,
+ plistURL: URL(filePath: "/Library/LaunchAgents/org.example.agent.plist"), program: nil, runsAtLoad: nil,
+ keepsAlive: nil, ownerBundleIdentifier: nil, ownerName: nil, ownerURL: nil, isOrphan: false,
+ state: .loaded, isDisabled: false
+ )
+ #expect(fileOnly.waitsForTheHelper)
+ fileOnly.isExcluded = true
+ #expect(!fileOnly.waitsForTheHelper)
+ }
+
private func item(state: BackgroundItem.State, plist: URL?) -> BackgroundItem {
BackgroundItem(
label: "com.example.agent", kind: .agent, source: .userLibrary, plistURL: plist, program: nil,
diff --git a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
index ec27834e..6f428e92 100644
--- a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
+++ b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
@@ -246,7 +246,9 @@ struct BackgroundItemDetailView: View {
if needsHelper {
Section {
- HelperRequiredBanner(need: item.requiresPrivileges ? .changingThisJob : .moving(1))
+ HelperRequiredBanner(
+ need: item.requiresPrivileges && item.offersControls ? .changingThisJob : .moving(1)
+ )
}
}
@@ -292,13 +294,7 @@ struct BackgroundItemDetailView: View {
}
}
- /// Whether this item needs administrator access while the helper can't act. Never true for Peel's own helper,
- /// a job under one of macOS's labels, or a system extension: none offers an action, so the helper would change
- /// nothing.
- private var needsHelper: Bool {
- !item.isPeelsHelper && !item.usesALabelOfMacOS && !item.isSystemExtension
- && (item.requiresPrivileges || item.removalRequiresPrivileges) && !helper.canAct
- }
+ private var needsHelper: Bool { item.waitsForTheHelper && !helper.canAct }
private func answer(_ fact: Bool?) -> Text {
switch fact {
@@ -401,18 +397,7 @@ struct BackgroundItemDetailView: View {
.contentTransition(.opacity)
}
- /// Start, Stop, Enable, and Disable, which a job Peel may not control, a job whose state Peel could not read, a
- /// file named by itself since its label couldn't be read, and a file whose label launchd runs from another file
- /// don't have. A job loaded from a file elsewhere has only Stop. A job Peel may not disable has only Enable, while
- /// launchd keeps it disabled.
- private var hasOwnControls: Bool {
- guard item.canBeControlled, item.state != .unknown, !item.isNamedByItsFile, !item.anotherFileIsLoaded else {
- return false
- }
- if item.canOnlyBeStopped { return true }
- if #available(macOS 27, *), item.isLeftByAGoneApp { return true }
- return !item.isSeenOnlyWhileLoaded || item.isDisabled || item.mayBeDisabled
- }
+ private var hasOwnControls: Bool { item.offersControls }
private var controls: some View {
let hasFileControls = finderURL != nil || item.canMoveToTrash