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
Leave stopped a job System Settings keeps from running, on Put Back too
Țugui Dragoș62026e65211c
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex cbb7dd03..dcdb4335 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -447,7 +447,8 @@ macOS asks the user to approve it once. It talks to the app over XPC.Start, Stop, Enable, and Disable go to `launchctl`, a daemon's through the helper, never under a label macOS uses forits own jobs (`SystemDaemons`, `SystemAgents`), and a job ServiceManagement manages is turned off only in SystemSettings. A job file System Settings keeps from running (`LoginItemsStatus`, from- `SMAppService.statusForLegacyPlist(at:)`, read with each scan and asked again before a start) is only ever stopped.+ `SMAppService.statusForLegacyPlist(at:)`, read with each scan and asked again before a start) is only ever stopped,+ and neither a removal nor Put Back starts it again (`LaunchdCleanup.Job.isKeptOffBySystemSettings`).Move to Trash takes the job's file, and the job is stopped once the file has moved.- **Extensions.** `AppExtensions.scan` reads `pluginkit -m -v` and `systemextensionsctl list`. Each ends by counting itsrows, so a listing read short of its count is no answer, and the page says which kind is missing. macOS's owndiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7161156f..c3f44c3f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -874,8 +874,8 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.- Stop, Unload, and Remove wait for the job's process to end, so a job slow to quit no longer reads as still runningafter launchd let it go.- A job turned off in System Settings > General > Login Items & Extensions, or waiting for approval there, is no- longer loaded, run, restarted, or disabled from here, which went over that choice: it can only be stopped, and its- page says why.+ longer loaded, run, restarted, or disabled from here, nor started again when its file comes back from History, which+ went over that choice: it can only be stopped, and its page says why.- A Login Items & Extensions status too long to sit beside its label goes under it from the left, rather than brokenat the right.diff --git a/GUIDE.md b/GUIDE.mdindex e4bdb5f7..47fddb59 100644--- a/GUIDE.md+++ b/GUIDE.md@@ -293,10 +293,10 @@ and how many items the others hold.and an item whose app is in the Trash says that macOS starts it from there each time you log in, until you emptythe Trash. A job an app gave launchd itself, such as an update's installer, says so. One turned off in SystemSettings > General > Login Items & Extensions, or waiting for approval there, is only ever stopped here, never- started. Edit… beside an agent's file in your own `~/Library/LaunchAgents` opens the file as text: Save moves the- file as it was to the Trash, writes yours in its place, and loads the job again if it was loaded, and putting the- old file back from History moves your edit to the Trash first. Apps set to open at login are in System Settings >- General > Login Items & Extensions, not here.+ started, not even when its file comes back from History. Edit… beside an agent's file in your own+ `~/Library/LaunchAgents` opens the file as text: Save moves the file as it was to the Trash, writes yours in its+ place, and loads the job again if it was loaded, and putting the old file back from History moves your edit to the+ Trash first. Apps set to open at login are in System Settings > General > Login Items & Extensions, not here.- **Extensions:** app extensions and system extensions, the app each one came with and whether it is still installed,the choice made for each one, or that macOS decides when nobody chose, which keeps a Finder extension off, and whereit is turned on or off: System Settings for most, Safari > Settings > Extensions for a Safari extension, which Safaridiff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/LoginItemsStatus.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/LoginItemsStatus.swiftindex 3b8ae36f..2037d68a 100644--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/LoginItemsStatus.swift+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/LoginItemsStatus.swift@@ -22,6 +22,11 @@ public enum LoginItemsStatus: Sendable, Hashable {guard let plist = item.plistURL, item.source == .userLibrary || item.source == .systemLibrary else {return nil}+ return of(plist: plist)+ }++ /// For a job file in a folder launchd reads by itself.+ static func of(plist: URL) -> LoginItemsStatus {if let standIn { return standIn(plist) }return switch SMAppService.statusForLegacyPlist(at: plist) {case .enabled: .alloweddiff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swiftindex f498fe2b..00e9e93c 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHygiene.swift@@ -10,6 +10,10 @@ enum LaunchdCleanup {var loadsInTheBackgroundSession = falsevar domain: String { LaunchdCleanup.domain(isDaemon: isDaemon, background: loadsInTheBackgroundSession) }++ /// Peel starts such a job again neither after a move nor on Put Back, as the Background Items page never+ /// starts it: that would go over the person's choice in System Settings.+ var isKeptOffBySystemSettings: Bool { !LoginItemsStatus.of(plist: plist).letsItRun }}/// A job launchd runs now whose program sits inside an app: one of the app's own background programs. `plist` isdiff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swiftindex 2ec9525d..0c830e54 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift@@ -726,7 +726,7 @@ public struct TrashService: Sendable {/// Starts again each of `jobs` launchd reads from a file that did not move: stopped so their app could move, they/// must not stay stopped while their file stays in place.private func startAgain(_ jobs: [LaunchdCleanup.Running], unlessMoved moved: Set<URL>) async {- for job in jobs.compactMap(\.job) where !moved.contains(job.plist) {+ for job in jobs.compactMap(\.job) where !moved.contains(job.plist) && !job.isKeptOffBySystemSettings {await startJob(job, true)}}@@ -919,7 +919,7 @@ public struct TrashService: Sendable {// file now back in place declares it.if let label = item.stoppedJob,let job = LaunchdCleanup.jobs(for: [item.originalURL], environment: environment).first,- job.label == label {+ job.label == label, !job.isKeptOffBySystemSettings {await startJob(job, canUseHelper)}return (nil, movedAside)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swiftindex c9c367de..160d3d98 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift@@ -241,6 +241,25 @@ struct TrashServiceTests {#expect(await launchd.started == [job.label])}+ @Test func leavesStoppedAJobSystemSettingsKeepsFromRunningWhenTheAppStays() async throws {+ let directory = try TemporaryDirectory()+ let (app, agent, plist, job) = try appRunningItsAgent(in: directory)+ defer { agent.terminate() }+ let launchd = Launchd(endsTheProcess: false)+ let service = try service(in: directory, launchd: launchd, agent: agent, running: [job])++ let result = await LoginItemsStatus.$standIn.withValue({ _ in .turnedOff }) {+ await service.trash(+ apps: [app], thenFiles: { stayed in stayed.isEmpty ? [plist] : [] }, usingHelperFor: [],+ lettingTheirProgramsRun: []+ )+ }++ #expect(result.failures.map(\.url) == [app])+ #expect(await launchd.stopped == [job.label])+ #expect(await launchd.started.isEmpty)+ }+@Test func resetsThePrivacyOfAnAppOnlyItsOwnBackgroundProgramKeepsInPlace() async throws {let directory = try TemporaryDirectory()let (app, agent, _, job) = try appRunningItsAgent(in: directory)@@ -443,6 +462,36 @@ struct TrashServiceTests {#expect(running.isThere && idle.isThere)}+ @Test func puttingBackTheFileOfAJobSystemSettingsKeepsOffLeavesItStopped() async throws {+ let directory = try TemporaryDirectory()+ let trash = try directory.directory("home/.Trash")+ let running = try launchdPlist("home/Library/LaunchAgents/org.example.running.plist", in: directory)+ let started = Mutex<[String]>([])+ let service = TrashService(+ environment: SearchEnvironment(+ homeDirectory: directory.url.appending(path: "home"),+ rootDirectory: directory.url.appending(path: "root")+ ),+ stopJobs: { jobs, _ in jobs },+ startJob: { job, _ in started.withLock { $0.append(job.label) } },+ moveToTrash: { url in+ let destination = trash.appending(path: url.lastPathComponent)+ try FileManager.default.moveItem(at: url, to: destination)+ return destination+ }+ )+ let item = try #require(await service.trash([running]).trashed.first)+ #expect(item.stoppedJob == "org.example.running")++ let failure = await LoginItemsStatus.$standIn.withValue({ _ in .turnedOff }) {+ await service.restore(item)+ }++ #expect(failure == nil)+ #expect(running.isThere)+ #expect(started.withLock { $0 }.isEmpty, "a job System Settings keeps from running was started")+ }+@Test func aJobIsStartedAgainOnlyAsTheFilePutBackDeclaresIt() async throws {let directory = try TemporaryDirectory()let trash = try directory.directory("home/.Trash")