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 about an agent in the user domain whenever its sessions name Background
Țugui Dragoșd9bea3607f23
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swiftindex b99e1219..8b633c6e 100644--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift@@ -52,8 +52,8 @@ public struct BackgroundItem: Sendable, Hashable, Identifiable {public var isNamedByItsFile = false/// What in the job's command is worth a second look, if anything.public var unusualCommand: UnusualCommand?- /// True for an agent its file limits to the Background session, which launchd keeps in the user domain rather- /// than the GUI one: started, stopped and asked about there.+ /// True for an agent that loads in the Background session, which launchd keeps in the user domain rather than+ /// the GUI one: started, stopped and asked about there.public var loadsInTheBackgroundSession = false/// True while an app's job runs from inside a Trash: its app was moved there, and macOS starts it from there at/// each login until the Trash is emptied.diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swiftindex e64cbda0..f029fe97 100644--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift@@ -341,7 +341,7 @@ public enum BackgroundItems {isOwnerConfirmed: owner?.isConfirmed ?? false,unusualCommand: UnusualCommand(arguments: job.arguments))- item.loadsInTheBackgroundSession = kind == .agent && job.loadsOnlyInTheBackground+ item.loadsInTheBackgroundSession = kind == .agent && job.loadsInTheBackgrounditems.append(item)}}@@ -529,8 +529,9 @@ struct JobDefinition {let isDisabled: Bool/// The plist's `AssociatedBundleIdentifiers`. Whoever wrote the plist chose them, so they are a claim, not proof.let associated: [String]- /// True when `LimitLoadToSessionType`, a string or an array (`man launchd.plist`), names only Background.- let loadsOnlyInTheBackground: Bool+ /// True when `LimitLoadToSessionType`, a string or an array (`man launchd.plist`), names Background: launchd+ /// keeps such an agent in the user's own domain, whatever other sessions it names.+ let loadsInTheBackground: Boollet watchPaths: [String]init?(contentsOf url: URL) {@@ -555,7 +556,7 @@ struct JobDefinition {associated = (named as? String).map { [$0] } ?? (named as? [Any])?.compactMap { $0 as? String } ?? []let sessions = plist["LimitLoadToSessionType"]let types = (sessions as? String).map { [$0] } ?? (sessions as? [Any])?.compactMap { $0 as? String } ?? []- loadsOnlyInTheBackground = types == ["Background"]+ loadsInTheBackground = types.contains("Background")watchPaths = (plist["WatchPaths"] as? [Any])?.compactMap { $0 as? String } ?? []}}diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swiftindex 09867fd9..f498fe2b 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift@@ -33,7 +33,7 @@ enum LaunchdCleanup {}}- /// A daemon's domain is the system's; an agent's is the GUI one, or the user's own for one that loads only in the+ /// A daemon's domain is the system's; an agent's is the GUI one, or the user's own for one that loads in the/// Background session (`man launchctl`: the two "still have discrete sets of services").static func domain(isDaemon: Bool, background: Bool) -> String {isDaemon ? "system" : background ? "user/\(getuid())" : "gui/\(getuid())"@@ -147,7 +147,7 @@ enum LaunchdCleanup {else { return nil }return Job(label: label, isDaemon: daemons.contains(parent), plist: url,- loadsInTheBackgroundSession: JobDefinition(plist)?.loadsOnlyInTheBackground == true+ loadsInTheBackgroundSession: JobDefinition(plist)?.loadsInTheBackground == true)}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swiftindex 1019a1d3..297ba113 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift@@ -20,10 +20,11 @@ struct BackgroundItemActionsTests {#expect(BackgroundItemActions.target(of: item(state: .loaded, plist: nil)) == "gui/\(uid)/com.example.agent")#expect(BackgroundItemActions.target(of: background) == "user/\(uid)/com.example.agent")- #expect(try #require(JobDefinition(["Label": "a", "LimitLoadToSessionType": "Background"])).loadsOnlyInTheBackground)- #expect(try #require(JobDefinition(["Label": "a", "LimitLoadToSessionType": ["Background"]])).loadsOnlyInTheBackground)- #expect(try !#require(JobDefinition(["Label": "a", "LimitLoadToSessionType": ["Aqua", "Background"]])).loadsOnlyInTheBackground)- #expect(try !#require(JobDefinition(["Label": "a"])).loadsOnlyInTheBackground)+ #expect(try #require(JobDefinition(["Label": "a", "LimitLoadToSessionType": "Background"])).loadsInTheBackground)+ #expect(try #require(JobDefinition(["Label": "a", "LimitLoadToSessionType": ["Background"]])).loadsInTheBackground)+ #expect(try #require(JobDefinition(["Label": "a", "LimitLoadToSessionType": ["Aqua", "Background"]])).loadsInTheBackground)+ #expect(try !#require(JobDefinition(["Label": "a", "LimitLoadToSessionType": ["Aqua", "LoginWindow"]])).loadsInTheBackground)+ #expect(try !#require(JobDefinition(["Label": "a"])).loadsInTheBackground)}@Test func knowsAJobItsGoneAppLeftLoaded() {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swiftindex 1fb0b325..f988bf5b 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift@@ -72,13 +72,20 @@ struct RemovalHygieneTests {format: .xml, options: 0)let background = try directory.file("home/Library/LaunchAgents/org.example.background.plist", contents: contents)+ let both = try directory.file(+ "home/Library/LaunchAgents/org.example.both.plist",+ contents: PropertyListSerialization.data(+ fromPropertyList: ["Label": "org.example.both", "LimitLoadToSessionType": ["Aqua", "Background"]],+ format: .xml, options: 0+ )+ )let window = try launchdPlist("home/Library/LaunchAgents/org.example.window.plist", label: "org.example.window", in: directory)- let jobs = LaunchdCleanup.jobs(for: [background, window], environment: environment)+ let jobs = LaunchdCleanup.jobs(for: [background, both, window], environment: environment)- #expect(jobs.map(\.domain) == ["user/\(getuid())", "gui/\(getuid())"])+ #expect(jobs.map(\.domain) == ["user/\(getuid())", "user/\(getuid())", "gui/\(getuid())"])}@Test func stopsAMovedFilesJobOnlyWhenLaunchdLoadedItFromThatFile() throws {