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
Peel keeps watching the Trash after ~/.Trash is deleted
Țugui Dragoș315d4f6b5a55
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex 95c33aed..8f86926e 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -89472,6 +89472,112 @@}}},+ "Peel isn’t watching the Trash right now. It tries again each time you come back to Peel." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel právě teď koš nesleduje. Zkusí to znovu pokaždé, když se do Peelu vrátíte."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel beobachtet den Papierkorb derzeit nicht und versucht es jedes Mal erneut, wenn du zu Peel zurückkehrst."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel no está vigilando la papelera ahora mismo. Lo intenta de nuevo cada vez que vuelves a Peel."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel ne surveille pas la corbeille pour l’instant. Il réessaie chaque fois que vous revenez à Peel."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Al momento Peel non sta monitorando il Cestino. Ci riprova ogni volta che torni su Peel."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peelは現在、ゴミ箱を監視していません。Peelに戻るたびに再試行します。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel이 지금은 휴지통을 지켜보고 있지 않습니다. Peel로 돌아올 때마다 다시 시도합니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel houdt de prullenmand op dit moment niet in de gaten. Dit wordt opnieuw geprobeerd telkens wanneer je naar Peel terugkeert."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel nie obserwuje teraz Kosza. Próbuje ponownie za każdym razem, gdy wracasz do Peel."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O Peel não está monitorando o Lixo agora. Ele tenta novamente sempre que você volta ao Peel."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel nu urmărește momentan Coșul. Încearcă din nou de fiecare dată când reveniți la Peel."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel сейчас не следит за Корзиной. Он пробует снова каждый раз, когда Вы возвращаетесь в Peel."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel bevakar inte papperskorgen just nu. Appen försöker igen varje gång du går tillbaka till Peel."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel şu anda Çöp Sepeti’ni izlemiyor. Peel’e her geri döndüğünüzde yeniden dener."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel зараз не стежить за Смітником. Вона пробує знову щоразу, коли ви повертаєтеся до Peel."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel目前未在监视废纸篓。每次你回到Peel时,它都会再试一次。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Peel目前沒有監看「垃圾桶」。每次你回到Peel時,它都會再試一次。"+ }+ }+ }+ },"Peel kept the old file and continued with what it could still read." : {"localizations" : {"cs" : {diff --git a/Peel/Model/TrashMonitor.swift b/Peel/Model/TrashMonitor.swiftindex 9525fada..aa98c993 100644--- a/Peel/Model/TrashMonitor.swift+++ b/Peel/Model/TrashMonitor.swift@@ -26,7 +26,9 @@ final class TrashMonitor {func start() {guard home == nil else { return }let trash = URL.homeDirectory.appending(path: ".Trash", directoryHint: .isDirectory)- let watch = TrashWatch(trash: trash, waitsForTheTrash: false) { [weak self] in self?.onApplicationTrashed?($0) }+ // Finder makes the home's Trash again only when something is next thrown away, so while it is missing the+ // home folder is watched for it.+ let watch = TrashWatch(trash: trash, waitsIn: .homeDirectory) { [weak self] in self?.onApplicationTrashed?($0) }switch watch.start() {case .watching:home = watch@@ -76,7 +78,8 @@ final class TrashMonitor {// The list of apps changing, as it does when one leaves its folder, is when to look again.watch.lookForTheTrash()} else {- let watch = TrashWatch(trash: trash, waitsForTheTrash: true) { [weak self] in+ let volume = trash.deletingLastPathComponent().deletingLastPathComponent()+ let watch = TrashWatch(trash: trash, waitsIn: volume) { [weak self] inself?.onApplicationTrashed?($0)}_ = watch.start()@@ -86,8 +89,9 @@ final class TrashMonitor {}}-/// One Trash folder, watched for apps arriving. A disk's Trash appears only once something there first goes to-/// the Trash, so until then the top of the disk is watched, where `.Trashes` appears.+/// One Trash folder, watched for apps arriving. A Trash can be missing: a disk's appears only once something there+/// first goes to the Trash, and the home's is made again only then after it is deleted. Until it is there, the folder+/// it appears in is watched: the top of the disk, where `.Trashes` appears, or the home folder.@MainActorprivate final class TrashWatch {enum Start {@@ -98,7 +102,7 @@ private final class TrashWatch {}let trash: URL- private let waitsForTheTrash: Bool+ private let waitingPlace: URLprivate let onArrived: (URL) -> Void/// Told what came of starting again after the folder watched went away.var onRestart: ((Start) -> Void)?@@ -112,9 +116,9 @@ private final class TrashWatch {var isActive: Bool { source != nil }- init(trash: URL, waitsForTheTrash: Bool, onArrived: @escaping (URL) -> Void) {+ init(trash: URL, waitsIn waitingPlace: URL, onArrived: @escaping (URL) -> Void) {self.trash = trash- self.waitsForTheTrash = waitsForTheTrash+ self.waitingPlace = waitingPlaceself.onArrived = onArrived}@@ -123,7 +127,7 @@ private final class TrashWatch {guard source == nil else { return .watching }let descriptor = open(trash.path(percentEncoded: false), O_EVTONLY)let failure = errno- if descriptor < 0, failure == ENOENT, waitsForTheTrash {+ if descriptor < 0, failure == ENOENT {return waitForTheTrash()}guard descriptor >= 0, let applications = Self.names(in: trash) else {@@ -150,12 +154,11 @@ private final class TrashWatch {func lookForTheTrash() {guard isWaitingForTheTrash else { return }stop()- _ = start(appeared: true)+ onRestart?(start(appeared: true))}private func waitForTheTrash() -> Start {- let volume = trash.deletingLastPathComponent().deletingLastPathComponent()- let descriptor = open(volume.path(percentEncoded: false), O_EVTONLY)+ let descriptor = open(waitingPlace.path(percentEncoded: false), O_EVTONLY)guard descriptor >= 0 else { return .unavailable }watch(descriptor)isWaitingForTheTrash = truediff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swiftindex 97c1cb68..26a80eb1 100644--- a/Peel/PeelApp.swift+++ b/Peel/PeelApp.swift@@ -176,7 +176,8 @@ struct PeelApp: App {await library.checkSigningTeams()}}- if watchesTrash, trashMonitor.status == .needsFullDiskAccess {+ // A watch that could not start, for want of Full Disk Access or for any other reason, is tried again.+ if watchesTrash, trashMonitor.status != .watching {trashMonitor.start()}}diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swiftindex e2760381..7ab4b65a 100644--- a/Peel/Views/Settings/SettingsView.swift+++ b/Peel/Views/Settings/SettingsView.swift@@ -206,6 +206,8 @@ private struct GeneralSettingsView: View {home.openFullDiskAccessSettings()}}+ } else if watchesTrash, trashMonitor.status == .off {+ WarningLabel(title: Text("Peel isn’t watching the Trash right now. It tries again each time you come back to Peel."))}toggle("Warn when the disk is almost full", isOn: $warnsWhenDiskIsNearlyFull,"When less than a tenth of the disk your home folder is on is available, Peel sends a notification that opens Space. It checks only while it is running.")