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.

Let a background item loaded from a file elsewhere be stopped

Țugui Dragoșb4623103d5bf
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index dbbae0f5..38b17430 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -167445,6 +167445,112 @@
}
}
},
+ "Takes it out of launchd. Its file stays where it is, and it runs again only if something loads it again." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Odebere úlohu z launchd. Její soubor zůstane, kde je, a úloha znovu poběží, jen pokud ji něco znovu načte."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Entfernt es aus launchd. Seine Datei bleibt, wo sie ist, und es läuft erst wieder, wenn etwas es erneut lädt."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Lo quita de launchd. Su archivo se queda donde está, y solo vuelve a ejecutarse si algo lo vuelve a cargar."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Retire cet élément de launchd. Son fichier reste là où il est, et l’élément ne s’exécute de nouveau que si quelque chose le recharge."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Lo toglie da launchd. Il suo file resta dov’è, e torna in esecuzione solo se qualcosa lo carica di nuovo."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "launchdから取り除きます。ファイルはそのまま残り、何かが再び読み込んだ場合にのみ、再び実行されます。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "launchd에서 이 항목을 제거합니다. 파일은 그대로 남으며, 무언가가 다시 로드해야만 다시 실행됩니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Haalt het uit launchd. Het bestand ervan blijft staan waar het staat, en het wordt pas weer uitgevoerd als iets het opnieuw laadt."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Usuwa tę rzecz z launchd. Jej plik pozostaje na miejscu, a ona sama uruchomi się ponownie tylko wtedy, gdy coś znowu ją wczyta."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Retira o item do launchd. O arquivo dele fica onde está, e ele só volta a ser executado se algo o carregar novamente."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Îl scoate din launchd. Fișierul său rămâne unde se află și rulează din nou doar dacă ceva îl încarcă din nou."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Убирает его из launchd. Его файл остается на месте, и он снова запустится, только если что-то снова его загрузит."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tar bort det ur launchd. Filen ligger kvar där den är, och det körs igen bara om något läser in det igen."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Onu launchd’den çıkarır. Dosyası olduğu yerde kalır ve ancak bir şey onu yeniden yüklerse yeniden çalışır."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Вилучає його з launchd. Його файл лишається на місці, і елемент знову запуститься, лише якщо щось знову його завантажить."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "将此任务从launchd中移除。它的文件会留在原处,只有当某个程序再次载入它时,它才会再次运行。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "將它從launchd中移除。它的檔案會留在原處,只有在有東西再次載入它時,它才會再次執行。"
+ }
+ }
+ }
+ },
"Tells you when your apps have new updates. With “Watch the Trash” on in Settings, it also tells you when you move an app to the Trash yourself, so you can clear what it left behind. With “Warn when the disk is almost full” on, it tells you that too." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift
index bcae2791..1f600638 100644
--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift
+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift
@@ -114,6 +114,10 @@ public struct BackgroundItem: Sendable, Hashable, Identifiable {
&& (requiresPrivileges ? !PrivilegedPathPolicy.isValidLabel(label) : !isReadWholeByLaunchctl)
}
+ /// True for a job Peel can only take out of launchd, which nothing loads again by itself: one loaded from a file
+ /// elsewhere, still there or gone. Disabled, it would leave the list with nothing to enable it from.
+ public var canOnlyBeStopped: Bool { canBeControlled && source == .otherFile }
+
/// True when Peel may disable the job: not one ServiceManagement manages, and one whose row Enable stays on.
public var mayBeDisabled: Bool { canBeControlled && !isManagedByServiceManagement && staysListedWhenDisabled }
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
index 9d15a909..47313fbe 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemActionsTests.swift
@@ -171,6 +171,20 @@ struct BackgroundItemActionsTests {
#expect(!daemon("com.apple.example").hasAnUnusableLabel)
}
+ @Test func aJobLoadedFromAFileElsewhereCanOnlyBeStopped() {
+ func agent(_ label: String, _ source: BackgroundItem.Source) -> BackgroundItem {
+ BackgroundItem(
+ label: label, kind: .agent, source: source, plistURL: nil, program: "/usr/local/bin/agent",
+ runsAtLoad: true, keepsAlive: true, ownerBundleIdentifier: nil, ownerName: nil, ownerURL: nil,
+ isOrphan: false, state: .running(pid: 4_242), isDisabled: false
+ )
+ }
+
+ #expect(agent("org.example.elsewhere", .otherFile).canOnlyBeStopped)
+ #expect(!agent("org.example.declared", .userLibrary).canOnlyBeStopped)
+ #expect(!agent("org.example.elsewhere/x", .otherFile).canOnlyBeStopped)
+ }
+
@Test func anAgentWhoseNameReachesAnotherJobIsLeftAlone() {
func agent(_ label: String) -> BackgroundItem {
BackgroundItem(
diff --git a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
index 1a96ebd3..1f794aac 100644
--- a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
+++ b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
@@ -354,17 +354,14 @@ 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 macOS can't load, and a job loaded from a file elsewhere don't have. Disabled, that last one would leave
- /// the list at the next logout or restart with nothing left to Enable it from. A job whose file is gone has only
- /// Stop. A job Peel may not disable has only Enable, while launchd keeps it disabled.
+ /// Start, Stop, Enable, and Disable, which a job Peel may not control, a job whose state Peel could not read, and a
+ /// file macOS can't load 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.source != .otherFile || item.isFileGone,
- !item.isUnreadable
- else {
+ guard item.canBeControlled, item.state != .unknown, !item.isUnreadable else {
return false
}
- if item.isFileGone { return true }
+ if item.canOnlyBeStopped { return true }
if #available(macOS 27, *), item.isLeftByAGoneApp { return true }
return !item.isSeenOnlyWhileLoaded || item.isDisabled || item.mayBeDisabled
}
@@ -390,10 +387,11 @@ struct BackgroundItemDetailView: View {
private var ownControls: some View {
Group {
// Stopping takes the job out of launchd, and nothing else removes one whose file or app is gone.
- if item.isFileGone {
+ if item.canOnlyBeStopped {
Button("Stop", systemImage: "stop.fill") {
Task { await backgroundItems.perform(.stop, on: item) }
}
+ .help(item.isFileGone ? Text(verbatim: "") : Text("Takes it out of launchd. Its file stays where it is, and it runs again only if something loads it again."))
} else if #available(macOS 27, *), item.isLeftByAGoneApp {
Button("Remove", systemImage: "xmark.circle") {
Task { await backgroundItems.perform(.stop, on: item) }