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.

Tell why a file in use keeps its iCloud download, and mark the desktop picture

Țugui Dragoș017ba8438eb8
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index a74a54f6..33f22f8d 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -9021,6 +9021,112 @@
}
}
},
+ "A program is using it, as the desktop picture is used, so macOS couldn’t remove its download. Try again once nothing uses it." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tento soubor používá nějaký program, stejně jako se používá tapeta, takže systém macOS nemohl odstranit jeho staženou kopii. Zkuste to znovu, až ho nebude nic používat."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ein Programm verwendet diese Datei, so wie das Hintergrundbild verwendet wird, daher konnte macOS ihren Download nicht entfernen. Versuche es erneut, sobald nichts sie mehr verwendet."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Un programa lo está usando, como ocurre con el fondo de pantalla, así que macOS no ha podido eliminar su descarga. Vuelve a intentarlo cuando nada lo esté usando."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Un programme l’utilise, comme c’est le cas du fond d’écran, si bien que macOS n’a pas pu retirer son téléchargement. Réessayez une fois que plus rien ne l’utilise."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Un programma lo sta usando, come succede con lo sfondo della scrivania, quindi macOS non è riuscito a rimuoverne il download. Riprova quando non lo usa più nulla."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "デスクトップの壁紙と同じように、プログラムがこのファイルを使用中のため、macOSはダウンロードしたものを削除できませんでした。使用しているものがなくなったら、もう一度やり直してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "배경화면으로 표시 중인 사진처럼 어떤 프로그램이 이 파일을 사용하고 있어 macOS가 다운로드를 제거할 수 없습니다. 이 파일을 사용하는 항목이 없을 때 다시 시도하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Een programma gebruikt dit bestand, zoals de bureaubladachtergrond wordt gebruikt, dus macOS kon de download ervan niet verwijderen. Probeer het opnieuw zodra niets het meer gebruikt."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Jakiś program używa tego pliku, tak jak używana jest tapeta, więc macOS nie mógł usunąć jego pobranej kopii. Spróbuj ponownie, gdy nic nie będzie go już używać."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Um programa está usando este arquivo, como acontece com a imagem de fundo, então o macOS não conseguiu remover o download dele. Tente novamente quando nada estiver usando o arquivo."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Fișierul este folosit de un program, așa cum este folosită imaginea desktopului, așa că macOS nu i‑a putut elimina descărcarea. Încercați din nou când nimic nu îl mai folosește."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Этот файл использует какая-то программа, как это бывает с обоями рабочего стола, поэтому macOS не удалось удалить его загруженную копию. Повторите попытку, когда файл ничем не будет использоваться."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ett program använder filen, på samma sätt som skrivbordsbilden används, så macOS kunde inte ta bort hämtningen. Försök igen när inget använder den."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bir program bu dosyayı, masaüstü resminin kullanıldığı gibi kullanıyor; bu yüzden macOS indirilen kopyasını kaldıramadı. Hiçbir şey onu kullanmadığında yeniden deneyin."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Цей файл використовує якась програма, як це буває зі шпалерою, тож macOS не вдалося вилучити його викачування. Спробуйте ще раз, коли його ніщо не використовуватиме."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "某个程序正在使用此文件,就像桌面墙纸被使用那样,因此macOS无法移除它的下载。请在没有任何程序使用它后再试一次。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "某個程式正在使用它,就像桌面背景圖片被使用時一樣,因此macOS無法移除它的下載項目。請在沒有任何程式使用它時再試一次。"
+ }
+ }
+ }
+ },
"A rebase puts uncommitted changes aside and brings them back when it ends." : {
"localizations" : {
"cs" : {
@@ -84824,6 +84930,112 @@
}
}
},
+ "Not selected: it is the desktop picture, which macOS keeps open while it is shown, so its download can’t be removed now." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nevybráno: je to tapeta, kterou systém macOS drží otevřenou, dokud se zobrazuje, takže její staženou kopii teď nelze odstranit."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nicht ausgewählt: Diese Datei ist das Hintergrundbild, das macOS geöffnet hält, solange es angezeigt wird, daher kann ihr Download jetzt nicht entfernt werden."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Sin seleccionar: es el fondo de pantalla, que macOS mantiene abierto mientras se muestra, así que ahora no se puede eliminar su descarga."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non sélectionné : il s’agit du fond d’écran, que macOS garde ouvert tant qu’il est affiché, si bien que son téléchargement ne peut pas être retiré pour l’instant."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non selezionato: è lo sfondo della scrivania, che macOS tiene aperto finché è visualizzato, quindi ora non è possibile rimuoverne il download."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未選択: これはデスクトップの壁紙で、表示中はmacOSが開いたままにしているため、現在はダウンロードしたものを削除できません。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "선택되지 않음: 이 파일은 배경화면이며, macOS가 표시하는 동안 열어 두므로 지금은 다운로드를 제거할 수 없습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Niet geselecteerd: dit is de bureaubladachtergrond, die macOS geopend houdt zolang die wordt getoond, dus de download ervan kan nu niet worden verwijderd."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie zaznaczono: ten plik jest tapetą, którą macOS utrzymuje otwartą, dopóki jest wyświetlana, więc nie można teraz usunąć jego pobranej kopii."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Não selecionado: é a imagem de fundo, que o macOS mantém aberta enquanto é exibida, então o download dela não pode ser removido agora."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Neselectat: este imaginea desktopului, pe care macOS o ține deschisă cât timp este afișată, așa că descărcarea sa nu poate fi eliminată acum."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не выбрано: этот файл используется как обои рабочего стола, а macOS держит его открытым, пока он показывается, поэтому его загруженную копию сейчас нельзя удалить."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inte markerad: det är skrivbordsbilden, som macOS håller öppen medan den visas, så hämtningen kan inte tas bort nu."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Seçilmedi: bu, masaüstü resmidir ve macOS onu gösterildiği sürece açık tutar; bu yüzden indirilen kopyası şu anda kaldırılamaz."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не вибрано: це шпалера, яку macOS тримає відкритою, поки її показано, тож її викачування зараз не можна вилучити."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未选择:它是桌面墙纸,macOS在显示它时会一直将其打开,因此现在无法移除它的下载。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未選取:它是桌面背景圖片,macOS在顯示時會讓它保持打開,因此現在無法移除它的下載項目。"
+ }
+ }
+ }
+ },
"Not selected: it stays with %@." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/CloudStorage.swift b/Packages/PeelCore/Sources/PeelCore/Space/CloudStorage.swift
index e87ea9e8..b804a793 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/CloudStorage.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/CloudStorage.swift
@@ -14,6 +14,9 @@ public struct CloudFile: Sendable, Hashable, Identifiable {
/// when a clone shares its blocks.
public let size: Int64
public let modified: Date?
+ /// The picture on one of the displays' desktop, which macOS keeps open while it is shown, so its download cannot be
+ /// removed then.
+ public var isDesktopPicture = false
public var id: URL { url }
}
@@ -35,6 +38,8 @@ public struct CloudRefusal: Sendable, Hashable, Identifiable {
/// Excluded in Settings since the scan, or the exclusions are not known, so it is left as a move to the
/// Trash would be.
case excluded
+ /// A program holds the file, as the desktop picture is held, so macOS could not lock it to free its copy.
+ case inUse
/// macOS refused to free the file. The value is the error message it gave.
case failed(String)
}
@@ -92,6 +97,7 @@ public enum CloudStorage {
home: URL = .homeDirectory,
minimumSize: Int64 = CloudStorage.minimumSize,
exclusions: Exclusions = .none,
+ desktopPictures: Set<URL> = [],
within budget: TimeInterval = CloudStorage.budget
) async -> CloudScan {
let collector = Collector()
@@ -101,6 +107,7 @@ public enum CloudStorage {
home: home,
minimumSize: minimumSize,
exclusions: exclusions,
+ desktopPictures: desktopPictures,
into: collector,
deadline: .now + .seconds(budget),
countingFor: scan,
@@ -190,6 +197,7 @@ public enum CloudStorage {
home: URL,
minimumSize: Int64,
exclusions: Exclusions,
+ desktopPictures: Set<URL> = [],
into collector: Collector,
deadline: ContinuousClock.Instant,
countingFor scan: ScanCount?,
@@ -198,6 +206,7 @@ public enum CloudStorage {
) {
let root = home.appending(path: "Library/Mobile Documents", directoryHint: .isDirectory)
let rootPath = PathPattern.comparablePath(of: root)
+ let pictures = Set(desktopPictures.map(PathPattern.comparablePath))
guard let enumerator = FileManager.default.enumerator(
at: root,
includingPropertiesForKeys: Array(keys),
@@ -248,7 +257,8 @@ public enum CloudStorage {
name: url.lastPathComponent,
container: containerName(of: url, under: root),
size: measured.size,
- modified: measured.modified
+ modified: measured.modified,
+ isDesktopPicture: pictures.contains(PathPattern.comparablePath(of: url))
)
collector.add(file)
}
@@ -289,12 +299,17 @@ public enum CloudStorage {
do {
try FileManager.default.evictUbiquitousItem(at: file.url)
} catch {
- refused.append(CloudRefusal(url: file.url, reason: .failed(error.localizedDescription)))
+ refused.append(CloudRefusal(url: file.url, reason: reason(for: error)))
}
}
return refused
}
+ /// Why freeing a file failed: `NSFileLockingError` when a program holds it, and macOS's own message otherwise.
+ static func reason(for error: any Error) -> CloudRefusal.Reason {
+ (error as? CocoaError)?.code == .fileLocking ? .inUse : .failed(error.localizedDescription)
+ }
+
/// A document saved as a package, which iCloud keeps as one item: what removing its download frees, and the
/// newest date of anything inside, since editing a file inside leaves the package's own date as it was. Nil for
/// a package with something excluded inside, one that could not be read whole, or a walk that was stopped.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift
index 9376a00d..2744fdbe 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CloudStorageTests.swift
@@ -284,4 +284,29 @@ struct CloudStorageTests {
#expect(untouched.map(\.reason) != [.changedSinceScan], "only iCloud can remove a download, so a test's fails")
#expect(edited.map(\.reason) == [.changedSinceScan])
}
+
+ /// A file a program holds, as the desktop picture is held, cannot be locked, and the person is told so.
+ @Test func aFileAProgramHoldsIsRefusedAsInUse() {
+ let locked = CocoaError(.fileLocking)
+ #expect(CloudStorage.reason(for: locked) == .inUse)
+ let other = CocoaError(.fileWriteNoPermission)
+ #expect(CloudStorage.reason(for: other) == .failed(other.localizedDescription))
+ }
+
+ /// The desktop picture is open for as long as it is shown, so the scan says which file it is.
+ @Test func theDesktopPictureIsMarked() throws {
+ let directory = try TemporaryDirectory()
+ let drive = "Library/Mobile Documents/com~apple~CloudDocs"
+ let picture = try directory.file("\(drive)/Wallpaper.png", bytes: 2_000_000)
+ try directory.file("\(drive)/Other.png", bytes: 2_000_000)
+
+ let collector = CloudStorage.Collector()
+ CloudStorage.collect(
+ home: directory.url, minimumSize: 1, exclusions: .none, desktopPictures: [picture], into: collector,
+ deadline: .now + .seconds(20), countingFor: nil, isSafe: { _ in true }, unless: { false }
+ )
+ let marked = Dictionary(uniqueKeysWithValues: collector.collected.files.map { ($0.name, $0.isDesktopPicture) })
+
+ #expect(marked == ["Wallpaper.png": true, "Other.png": false])
+ }
}
diff --git a/Peel/Model/CloudLibrary.swift b/Peel/Model/CloudLibrary.swift
index 62d77f26..8607ff97 100644
--- a/Peel/Model/CloudLibrary.swift
+++ b/Peel/Model/CloudLibrary.swift
@@ -1,4 +1,4 @@
-import Foundation
+import AppKit
import Observation
import PeelCore
@@ -50,9 +50,10 @@ final class CloudLibrary {
/// Scans again. What the last Free Up Space refused is cleared, since it described the old list.
func refresh() async {
refusals = []
+ let pictures = Set(NSScreen.screens.compactMap { NSWorkspace.shared.desktopImageURL(for: $0) })
guard
let scan = await scanRun.run({
- await CloudStorage.downloaded(exclusions: ExclusionsStore.shared.exclusions)
+ await CloudStorage.downloaded(exclusions: ExclusionsStore.shared.exclusions, desktopPictures: pictures)
})
else { return }
files = scan.files
diff --git a/Peel/Views/Cloud/CloudView.swift b/Peel/Views/Cloud/CloudView.swift
index affca533..b8ef42e1 100644
--- a/Peel/Views/Cloud/CloudView.swift
+++ b/Peel/Views/Cloud/CloudView.swift
@@ -46,7 +46,9 @@ struct CloudView: View {
RemovalRow(
url: file.url,
icon: .file(file.url),
- detail: nil,
+ detail: file.isDesktopPicture
+ ? "Not selected: it is the desktop picture, which macOS keeps open while it is shown, so its download can’t be removed now."
+ : nil,
size: file.size,
isFirst: index == 0,
hasNoteColumn: false,
@@ -63,8 +65,9 @@ struct CloudView: View {
} actions: {
SelectMenu(
list: SelectableRows(
- rows: listed.map(\.url), selectable: listed.map(\.url), recommended: listed.map(\.url),
- leftToTheClick: []
+ rows: listed.map(\.url), selectable: listed.map(\.url),
+ recommended: listed.filter { !$0.isDesktopPicture }.map(\.url),
+ leftToTheClick: listed.filter(\.isDesktopPicture).map(\.url)
),
place: Text(Tool.cloud.title),
selection: cloud
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index d361d26e..669bf321 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -200,6 +200,7 @@ extension CloudRefusal {
switch reason {
case .changedSinceScan: String(localized: "It isn’t as it was when Peel looked at it: it may have been edited, stopped syncing, or been freed already, so Peel left it alone.")
case .excluded: String(localized: "Excluded in Settings")
+ case .inUse: String(localized: "A program is using it, as the desktop picture is used, so macOS couldn’t remove its download. Try again once nothing uses it.")
case .failed(let message): message
}
}