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
What is selected on one storage tool's page travels to the others
Țugui Dragoș7d477b4e953e
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex 1e724173..3ad97805 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -76,8 +76,9 @@ Take the most common case, uninstalling an app. Every other page follows the sam6. **Finish.** Only for what really moved: the launch jobs whose files went are stopped, and macOS is told toforget the preference domains whose files went.7. **Record.** Every removal goes into History (`removals.json`, through `RemovalLog`), with where each item came- from and where it went, so it can be put back; History keeps the most recent 20,000 items. What Peel refused to- move is recorded too (`refusals.json`), and History lists it under Not Moved, one removal to an entry.+ from and where it went, so it can be put back; History keeps the most recent 20,000 items. A removal is one+ entry, even when it moved what was selected on several pages. What Peel refused to move is recorded too+ (`refusals.json`), and History lists it under Not Moved, one removal to an entry.8. **Put back.** History's Put Back reads its record as a request, not as a fact: an item returns only from areal Trash, only to a place the guard allows, and, through the helper, only if the helper's own ledger saysit moved that very item from that very place.@@ -127,7 +128,10 @@ macOS asks the user to approve it once. It talks to the app over XPC.- **Pages and models.** The sidebar lists the tools. Each has its page in `Peel/Views/<Tool>/` and a model in`Peel/Model/` (`AppLibrary`, `OrphanLibrary`, `DuplicateLibrary`, and so on) that owns its scan and itsselection. The pages share `RemovalRow` for a row that can be selected and `RemovalBar` for the button that- moves the selection.+ moves the selection. On the pages that free space (Orphaned Files, Space, Developer, Build Artifacts, Installers+ and Backups, Duplicates, and File Search) the selection travels: what is selected on every such page the user+ has opened stays selected, and Move to Trash on any of them moves it all as one removal, each page's part by its+ own tool with that tool's checks (`SelectionCarrier`, over `CarriedSelection` in PeelCore).- **Concurrency.** The app target runs on the main actor by default. Heavy work lives in PeelCore and is marked`@concurrent`, so it runs off the main actor.- **Two looks.** Home, the menu bar panel, and About use Peel's own look, a paper sheet with stickers. Everydiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 161f146d..a0d2150b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,6 +20,8 @@ The first public release, for macOS 26 and later, on Apple silicon and Intel Mac- Changes settings macOS has but doesn't show, and puts back what was there when you turn one off.- Moves what it removes to the Trash instead of deleting it, and keeps a History that puts it back and listswhat it didn't move, with the reason.+- Keeps what you select on the pages that free space while you look at the others, and moves it all at once, as+ one entry in History.- Leaves alone the files, folders, and apps you exclude.- Checks your apps for updates, and watches the Trash for apps you remove yourself.- Says in About when a new version of Peel is out, with where to get it, and downloads nothing itself.diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex c2a1ea71..8a5fbd5e 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -4388,6 +4388,1044 @@}}},+ "%@: ^[%lld item](inflect: true)" : {+ "localizations" : {+ "cs" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld položky"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld položky"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld položka"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld položek"+ }+ }+ }+ }+ },+ "de" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld Objekt"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld Objekte"+ }+ }+ }+ }+ },+ "en" : {+ "stringUnit" : {+ "state" : "new",+ "value" : "%1$@: ^[%2$lld item](inflect: true)"+ }+ },+ "es" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld de ítems"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld ítem"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld ítems"+ }+ }+ }+ }+ },+ "fr" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ : %lld d’éléments"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ : %lld élément"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ : %lld éléments"+ }+ }+ }+ }+ },+ "it" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld di elementi"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld elemento"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld elementi"+ }+ }+ }+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld項目"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: 항목 %lld개"+ }+ },+ "nl" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld onderdeel"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld onderdelen"+ }+ }+ }+ }+ },+ "pl" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld rzeczy"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld rzeczy"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld rzecz"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld rzeczy"+ }+ }+ }+ }+ },+ "pt" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld de itens"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld item"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld itens"+ }+ }+ }+ }+ },+ "ro" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld articole"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld articol"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld de articole"+ }+ }+ }+ }+ },+ "ru" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld объекта"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld объектов"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld объект"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld объекта"+ }+ }+ }+ }+ },+ "sv" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld objekt"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld objekt"+ }+ }+ }+ }+ },+ "tr" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld öğe"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld öğe"+ }+ }+ }+ }+ },+ "uk" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld елементи"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld елементів"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld елемент"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld елемента"+ }+ }+ }+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@:%lld个项目"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@:%lld個項目"+ }+ }+ }+ },+ "%@: ^[%lld item](inflect: true), %@" : {+ "localizations" : {+ "cs" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld položky, %@"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld položky, %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld položka, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld položek, %@"+ }+ }+ }+ }+ },+ "de" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld Objekt, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld Objekte, %@"+ }+ }+ }+ }+ },+ "en" : {+ "stringUnit" : {+ "state" : "new",+ "value" : "%1$@: ^[%2$lld item](inflect: true), %3$@"+ }+ },+ "es" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld de ítems, %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld ítem, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld ítems, %@"+ }+ }+ }+ }+ },+ "fr" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ : %lld d’éléments, %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ : %lld élément, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ : %lld éléments, %@"+ }+ }+ }+ }+ },+ "it" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld di elementi, %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld elemento, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld elementi, %@"+ }+ }+ }+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld項目、%@"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: 항목 %lld개, %@"+ }+ },+ "nl" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld onderdeel, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld onderdelen, %@"+ }+ }+ }+ }+ },+ "pl" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld rzeczy, %@"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld rzeczy, %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld rzecz, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld rzeczy, %@"+ }+ }+ }+ }+ },+ "pt" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld de itens, %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld item, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld itens, %@"+ }+ }+ }+ }+ },+ "ro" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld articole, %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld articol, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld de articole, %@"+ }+ }+ }+ }+ },+ "ru" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld объекта, %@"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld объектов, %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld объект, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld объекта, %@"+ }+ }+ }+ }+ },+ "sv" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld objekt, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld objekt, %@"+ }+ }+ }+ }+ },+ "tr" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld öğe, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld öğe, %@"+ }+ }+ }+ }+ },+ "uk" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld елементи, %@"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld елементів, %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld елемент, %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld елемента, %@"+ }+ }+ }+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@:%lld个项目,%@"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@:%lld個項目,%@"+ }+ }+ }+ },+ "%@: ^[%lld item](inflect: true), over %@" : {+ "localizations" : {+ "cs" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld položky, přes %@"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld položky, přes %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld položka, přes %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld položek, přes %@"+ }+ }+ }+ }+ },+ "de" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld Objekt, über %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld Objekte, über %@"+ }+ }+ }+ }+ },+ "en" : {+ "stringUnit" : {+ "state" : "new",+ "value" : "%1$@: ^[%2$lld item](inflect: true), over %3$@"+ }+ },+ "es" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld de ítems, más de %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld ítem, más de %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld ítems, más de %@"+ }+ }+ }+ }+ },+ "fr" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ : %lld d’éléments, plus de %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ : %lld élément, plus de %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ : %lld éléments, plus de %@"+ }+ }+ }+ }+ },+ "it" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld di elementi, oltre %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld elemento, oltre %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld elementi, oltre %@"+ }+ }+ }+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld項目、%@以上"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: 항목 %lld개, %@ 이상"+ }+ },+ "nl" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld onderdeel, meer dan %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld onderdelen, meer dan %@"+ }+ }+ }+ }+ },+ "pl" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld rzeczy, ponad %@"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld rzeczy, ponad %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld rzecz, ponad %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld rzeczy, ponad %@"+ }+ }+ }+ }+ },+ "pt" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld de itens, mais de %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld item, mais de %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld itens, mais de %@"+ }+ }+ }+ }+ },+ "ro" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld articole, peste %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld articol, peste %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld de articole, peste %@"+ }+ }+ }+ }+ },+ "ru" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld объекта, более %@"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld объектов, более %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld объект, более %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld объекта, более %@"+ }+ }+ }+ }+ },+ "sv" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld objekt, över %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld objekt, över %@"+ }+ }+ }+ }+ },+ "tr" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld öğe, %@ üzeri"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld öğe, %@ üzeri"+ }+ }+ }+ }+ },+ "uk" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld елементи, понад %@"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld елементів, понад %@"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld елемент, понад %@"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@: %lld елемента, понад %@"+ }+ }+ }+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@:%lld个项目,超过%@"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@:%lld個項目,超過%@"+ }+ }+ }+ },"%@: links" : {"localizations" : {"cs" : {@@ -22530,6 +23568,112 @@}}},+ "Deselect" : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Odznačit"+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Auswahl aufheben"+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Anular selección"+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Désélectionner"+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Deseleziona"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "選択解除"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "선택 해제"+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Deselecteer"+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Usuń zaznaczenie"+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Desmarcar"+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Deselectați"+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Снять выбор"+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Avmarkera"+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Seçimi Kaldır"+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Зняти вибір"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "取消选择"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "取消選取"+ }+ }+ }+ },"Deselect All" : {"localizations" : {"cs" : {@@ -93399,6 +94543,346 @@}}},+ "Selected on ^[%lld page](inflect: true)" : {+ "localizations" : {+ "cs" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Vybráno na %lld stránkách"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Vybráno na %lld stránky"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Vybráno na %lld stránce"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Vybráno na %lld stránkách"+ }+ }+ }+ }+ },+ "de" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Auf %lld Seite ausgewählt"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Auf %lld Seiten ausgewählt"+ }+ }+ }+ }+ },+ "es" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "en la selección de %lld de páginas"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "en la selección de %lld página"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "en la selección de %lld páginas"+ }+ }+ }+ }+ },+ "fr" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "sélectionné(s) sur %lld de pages"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "sélectionné(s) sur %lld page"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "sélectionné(s) sur %lld pages"+ }+ }+ }+ }+ },+ "it" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "nella selezione su %lld di pagine"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "nella selezione su %lld pagina"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "nella selezione su %lld pagine"+ }+ }+ }+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%lldページで選択済み"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "페이지 %lld개에서 선택됨"+ }+ },+ "nl" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Geselecteerd op %lld pagina"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Geselecteerd op %lld pagina's"+ }+ }+ }+ }+ },+ "pl" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Zaznaczone na %lld stronach"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Zaznaczone na %lld stronach"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Zaznaczone na %lld stronie"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Zaznaczone na %lld strony"+ }+ }+ }+ }+ },+ "pt" : {+ "variations" : {+ "plural" : {+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "na seleção em %lld de páginas"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "na seleção em %lld página"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "na seleção em %lld páginas"+ }+ }+ }+ }+ },+ "ro" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Selectat în %lld pagini"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Selectat în %lld pagină"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Selectat în %lld de pagini"+ }+ }+ }+ }+ },+ "ru" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Выбрано на %lld страницах"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Выбрано на %lld страницах"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Выбрано на %lld странице"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Выбрано на %lld страницы"+ }+ }+ }+ }+ },+ "sv" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "markerade på %lld sida"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "markerade på %lld sidor"+ }+ }+ }+ }+ },+ "tr" : {+ "variations" : {+ "plural" : {+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%lld sayfada seçili"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%lld sayfada seçili"+ }+ }+ }+ }+ },+ "uk" : {+ "variations" : {+ "plural" : {+ "few" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Вибрано на %lld сторінках"+ }+ },+ "many" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Вибрано на %lld сторінках"+ }+ },+ "one" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Вибрано на %lld сторінці"+ }+ },+ "other" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Вибрано на %lld сторінки"+ }+ }+ }+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "已在%lld个页面上选择"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "已在%lld個頁面上選取"+ }+ }+ }+ },"Services" : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Removals.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Removals.swiftindex 05973e98..11c3b1ff 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Removals.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Removals.swift@@ -15,10 +15,7 @@ enum Removals {) async -> Bool {await refusals.add(result.failures, source: source, sourceKey: sourceKey, tool: tool)guard !result.trashed.isEmpty else { return true }- let batch = UUID()- let records = result.trashed.map {- RemovalRecord(batch: batch, item: $0, size: sizes[$0.originalURL], source: source, sourceKey: sourceKey, tool: tool)- }+ let records = RemovalPart(source: source, sourceKey: sourceKey, tool: tool).records(of: result, sizes: sizes, batch: UUID())return await log.add(records).records != nil}}diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/CarriedSelection.swift b/Packages/PeelCore/Sources/PeelCore/Removal/CarriedSelection.swiftindex 4c9c8ff6..e79e7853 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/CarriedSelection.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/CarriedSelection.swift@@ -17,16 +17,18 @@ public struct CarriedSelection: Sendable {}}- /// What one page has selected: its items with the sizes the page measured, nil where it could not, and the- /// source History names them by.+ /// What one page has selected: its items with the sizes the page measured, nil where it could not, the page's+ /// title as the page shows it, and the source History names them by.public struct Part: Sendable, Hashable, Identifiable {public let page: Page+ public let title: Stringpublic let source: Stringpublic let sourceKey: String?public let sizes: [URL: Int64?]- public init(page: Page, source: String, sourceKey: String?, sizes: [URL: Int64?]) {+ public init(page: Page, title: String, source: String, sourceKey: String?, sizes: [URL: Int64?]) {self.page = page+ self.title = titleself.source = sourceself.sourceKey = sourceKeyself.sizes = sizes@@ -36,19 +38,13 @@ public struct CarriedSelection: Sendable {public var count: Int { sizes.count }public var total: SizeTotal { SizeTotal(sizes.values) }- /// What moved of this part, as History records of `batch`: each under the part's source and tool, with the- /// size its page measured, and none where the page could not measure it.- public func records(of result: TrashResult, batch: UUID) -> [RemovalRecord] {- result.trashed.map { item in- RemovalRecord(- batch: batch,- item: item,- size: sizes[item.originalURL] ?? nil,- source: source,- sourceKey: sourceKey,- tool: page.tool- )- }+ public var removalPart: RemovalPart {+ RemovalPart(source: source, sourceKey: sourceKey, tool: page.tool)+ }++ /// The sizes History records for the part: those its page measured.+ public var measuredSizes: [URL: Int64] {+ [URL: Int64](measured: sizes.lazy.map { ($0.key, $0.value) })}}@@ -56,6 +52,11 @@ public struct CarriedSelection: Sendable {public struct Pass: Sendable {public var moved: [(part: Part, result: TrashResult)] = []public var kept: [Part] = []++ /// Every item the moved parts moved, and every one their tools refused.+ public var result: TrashResult {+ TrashResult(trashed: moved.flatMap(\.result.trashed), failures: moved.flatMap(\.result.failures))+ }}/// The pages seen so far, in the order they were first seen.diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGrouping.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGrouping.swiftindex 854a7e05..2860ed30 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGrouping.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGrouping.swift@@ -85,6 +85,16 @@ public struct RemovalPart: Sendable, Hashable {}}+extension RemovalPart {+ /// History's records of what moved from this part, all in `batch`, each with its size in `sizes`, and none+ /// where it was not measured.+ public func records(of result: TrashResult, sizes: [URL: Int64], batch: UUID) -> [RemovalRecord] {+ result.trashed.map {+ RemovalRecord(batch: batch, item: $0, size: sizes[$0.originalURL], source: source, sourceKey: sourceKey, tool: tool)+ }+ }+}+extension RemovalRecord {public var part: RemovalPart { RemovalPart(source: source, sourceKey: sourceKey, tool: tool) }}diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swiftindex 820677dd..fa479304 100644--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift@@ -22,6 +22,14 @@ public enum SpaceRemoval {public var appsToQuit: [String] {Set(inUse.map(\.name)).sorted()}++ /// What to select of this plan when it replaces `previous`, the area's last plan, `selected` being what+ /// was selected: a child that was already there keeps its checkbox as it was, and a child new to the area+ /// is selected when its size is known, as every child is in an area's first plan.+ public func selection(replacing previous: Plan?, selected: Set<URL>) -> Set<URL> {+ let known = Set(previous?.removable ?? [])+ return Set(removable.filter { known.contains($0) ? selected.contains($0) : sizes[$0] != nil })+ }}@concurrent@@ -42,6 +50,32 @@ public enum SpaceRemoval {running: [String: String],measure: FileSize.Measure) async -> Plan {+ let children = children(of: item, environment: environment, exclusions: exclusions, running: running)+ var sizes: [URL: Int64] = [:]+ for child in children.removable where !Task.isCancelled {+ sizes[child] = await measure(child)+ }+ return Plan(removable: children.removable, inUse: children.inUse, leftToDeveloper: children.leftToDeveloper, sizes: sizes)+ }++ /// What of `item` can move now, measuring nothing: the check a move makes just before it moves, since an app+ /// opened since the plan may be writing to some of these folders.+ @concurrent+ public static func removable(+ in item: SpaceItem,+ environment: SearchEnvironment = .current,+ exclusions: Exclusions = .none,+ running: [String: String] = [:]+ ) async -> [URL] {+ children(of: item, environment: environment, exclusions: exclusions, running: running).removable+ }++ private static func children(+ of item: SpaceItem,+ environment: SearchEnvironment,+ exclusions: Exclusions,+ running: [String: String]+ ) -> (removable: [URL], inUse: [(url: URL, name: String)], leftToDeveloper: [URL]) {let removalGuard = RemovalGuard(environment: environment, exclusions: exclusions)let children = item.urls.flatMap { url in(try? FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)) ?? []@@ -60,11 +94,7 @@ public enum SpaceRemoval {removable.append(child)}}- var sizes: [URL: Int64] = [:]- for child in removable where !Task.isCancelled {- sizes[child] = await measure(child)- }- return Plan(removable: removable, inUse: inUse, leftToDeveloper: leftToDeveloper, sizes: sizes)+ return (removable, inUse, leftToDeveloper)}/// Maps each name an open app answers to, normalized, to the app's display name. The names are the bundlediff --git a/Packages/PeelCore/Tests/PeelCoreTests/CarriedSelectionTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CarriedSelectionTests.swiftindex 0b3be8eb..8c5d38e6 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/CarriedSelectionTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/CarriedSelectionTests.swift@@ -13,6 +13,7 @@ struct CarriedSelectionTests {private func part(_ tool: String, _ scope: String, _ sizes: [String: Int64?], source: String? = nil) -> Part {Part(page: Page(tool: tool, scope: scope),+ title: scope,source: source ?? scope,sourceKey: nil,sizes: Dictionary(uniqueKeysWithValues: sizes.map { (URL(filePath: "/Users/x/\($0.key)"), $0.value) })@@ -93,6 +94,29 @@ struct CarriedSelectionTests {#expect(pass.moved.map(\.part.page.scope) == ["Peel"])}+ /// What a pass did is told once, whichever parts it came from: every item the parts moved, and every one+ /// their tools refused.+ @Test func aPassTellsWhatEveryPartMovedAndRefused() async {+ let parts = [+ part("developer", "Xcode", ["DerivedData": 900, "ModuleCache": 100]),+ part("space", "caches", ["com.gone.app": 50]),+ ]+ let pass = await CarriedSelection.pass(parts) { part in+ var result = TrashResult()+ for url in part.sizes.keys {+ if url.lastPathComponent == "ModuleCache" {+ result.failures.append(TrashFailure(url: url, reason: .protectedLocation))+ } else {+ result.trashed.append(TrashedItem(originalURL: url, trashedURL: url, date: .now))+ }+ }+ return result+ }++ #expect(Set(pass.result.trashed.map(\.originalURL.lastPathComponent)) == ["DerivedData", "com.gone.app"])+ #expect(pass.result.failures.map(\.url.lastPathComponent) == ["ModuleCache"])+ }+/// What a pass moved is one History batch, each record under its own part's source and tool, with the size/// its page measured, and none for an item whose size was not known.@Test func whatMovedIsOneBatchWithEachPartsName() async {@@ -104,7 +128,7 @@ struct CarriedSelectionTests {var records: [RemovalRecord] = []_ = await CarriedSelection.pass(parts) { part inlet result = TrashResult(trashed: part.sizes.keys.map { TrashedItem(originalURL: $0, trashedURL: $0, date: .now) })- records += part.records(of: result, batch: batch)+ records += part.removalPart.records(of: result, sizes: part.measuredSizes, batch: batch)return result}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swiftindex 59a28f2d..90d2f594 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift@@ -65,6 +65,22 @@ struct SpaceRemovalTests {#expect(plan.appsToQuit == ["Spotify"])}+ /// A move asks again just before it moves anything, since an app opened since the plan may be writing to some+ /// of these folders. It needs to know what may go, not how big it is, and it finds what a plan would.+ @Test func theMovesCheckFindsWhatAPlanWould() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Caches/com.spotify.client/audio.db")+ try directory.file("home/Library/Caches/com.gone.app/old.db")+ try directory.file("home/Library/Caches/Coursier/v1/https/repo.jar")+ let running = ["comspotifyclient": "Spotify"]++ let plan = await SpaceRemoval.plan(for: item(directory), environment: environment(directory), running: running)+ let removable = await SpaceRemoval.removable(in: item(directory), environment: environment(directory), running: running)++ #expect(removable.map(\.lastPathComponent) == ["com.gone.app"])+ #expect(removable == plan.removable)+ }+/// Many cache and log folders are named after the app rather than its bundle identifier, such as `Firefox`,/// `Mozilla`, `JetBrains` and `Zed`. Emptying one while its app writes to it is the risk here.@Test func leavesAloneAFolderNamedAfterTheOpenAppRatherThanItsIdentifier() async throws {@@ -170,4 +186,30 @@ struct SpaceRemovalTests {#expect(Set(plan.removable.map(\.lastPathComponent)) == ["com.slow.app", "com.gone.app"])#expect(plan.sizes.keys.map(\.lastPathComponent) == ["com.gone.app"])}++ /// An area's plan is made again when the disk changes, and what the person chose in it stays chosen: a child+ /// that was already there keeps its checkbox as it was, one new to the area is selected when its size is+ /// known, as every child is in the area's first plan, and one that went is no longer selected.+ @Test func aPlanMadeAgainKeepsWhatThePersonChose() {+ let caches = URL(filePath: "/Users/x/Library/Caches", directoryHint: .isDirectory)+ let (kept, deselected, chosenByHand, unmeasured, new, gone) = (+ caches.appending(path: "com.a"), caches.appending(path: "com.b"), caches.appending(path: "com.c"),+ caches.appending(path: "com.d"), caches.appending(path: "com.e"), caches.appending(path: "com.f")+ )+ let first = SpaceRemoval.Plan(+ removable: [kept, deselected, chosenByHand, unmeasured, gone],+ inUse: [],+ leftToDeveloper: [],+ sizes: [kept: 1, deselected: 2, gone: 5]+ )+ #expect(first.selection(replacing: nil, selected: []) == [kept, deselected, gone])++ let again = SpaceRemoval.Plan(+ removable: [kept, deselected, chosenByHand, unmeasured, new],+ inUse: [],+ leftToDeveloper: [],+ sizes: [kept: 1, deselected: 2, chosenByHand: 3, unmeasured: 4, new: 6]+ )+ #expect(again.selection(replacing: first, selected: [kept, chosenByHand, gone]) == [kept, chosenByHand, new])+ }}diff --git a/Peel/Model/DeveloperLibrary.swift b/Peel/Model/DeveloperLibrary.swiftindex 560e8201..d4f87953 100644--- a/Peel/Model/DeveloperLibrary.swift+++ b/Peel/Model/DeveloperLibrary.swift@@ -30,26 +30,53 @@ final class DeveloperLibrary {}}- /// Whether one of the environment's apps is running. Asked each time rather than stored, since an app can- /// be opened while the page is on screen.- /// The name of one of the environment's apps that is running, or nil when none is.+ /// The name of one of the environment's apps that is running, or nil when none is. Asked each time rather+ /// than stored, since an app can be opened while the page is on screen.func runningApp(of environment: DeveloperEnvironment) -> String? {environment.runningApp { identifier inNSRunningApplication.runningApplications(withBundleIdentifier: identifier).lazy.compactMap(\.localizedName).first}}- /// Moves the selected locations of `environment` to the Trash. Returns nil, moving nothing, when one of its- /// apps was opened between the button and the confirmation: files never move out from under a running app.- func removeSelected(from environment: DeveloperEnvironment, recording record: (TrashResult) async -> Void) async -> TrashResult? {+ private func environment(of page: CarriedSelection.Page) -> DeveloperEnvironment? {+ environments?.first { $0.id == page.scope }+ }+}++extension DeveloperLibrary: CarriesSelection {+ var carriedParts: [CarriedSelection.Part] {+ (environments ?? []).compactMap { environment in+ let selected = environment.locations.filter { selectedURLs.contains($0.url) }+ guard !selected.isEmpty else { return nil }+ return CarriedSelection.Part(+ page: Tool.developer.page(environment.id),+ title: environment.name,+ source: environment.name,+ sourceKey: nil,+ sizes: Dictionary(selected.map { ($0.url, $0.size) }, uniquingKeysWith: { first, _ in first })+ )+ }+ }++ func appToQuit(for part: CarriedSelection.Part) -> String? {+ environment(of: part.page).flatMap(runningApp(of:))+ }++ /// Moves nothing while one of the environment's apps is open: files never move out from under a running app.+ func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {+ guard let environment = environment(of: part.page) else { return TrashResult() }guard runningApp(of: environment) == nil else { return nil }isRemoving = truedefer { isRemoving = false }- let urls = environment.locations.map(\.url).filter(selectedURLs.contains)- let result = await TrashService(exclusions: ExclusionsStore.shared.exclusions).trash(urls)- // Written down before the rescan, which can take a while: History is the way back for what just moved.- await record(result)+ let urls = environment.locations.map(\.url).filter { selectedURLs.contains($0) && part.sizes.keys.contains($0) }+ return await TrashService(exclusions: ExclusionsStore.shared.exclusions).trash(urls)+ }++ func refresh(after parts: [CarriedSelection.Part], apps: AppLibrary) async {await refresh()- return result+ }++ func choose(_ page: CarriedSelection.Page) {+ selection = page.scope}}diff --git a/Peel/Model/DuplicateLibrary.swift b/Peel/Model/DuplicateLibrary.swiftindex ed0d986e..38e27cb1 100644--- a/Peel/Model/DuplicateLibrary.swift+++ b/Peel/Model/DuplicateLibrary.swift@@ -24,7 +24,7 @@ final class DuplicateLibrary {didSet { readScan() }}/// The space each duplicate file frees, by path. Built once per scan, with `reclaimableFolders` and the- /// counts below, so summing the selection doesn't walk the whole scan on every change.+ /// counts below, so reading the selection's sizes doesn't walk the whole scan on every change.private(set) var reclaimable: [URL: Int64] = [:]private(set) var reclaimableFolders: [URL: Int64] = [:]private(set) var copyCount = 0@@ -68,11 +68,6 @@ final class DuplicateLibrary {selectedURLs.count + selectedFolders.count}- var selectedReclaimableSize: Int64 {- selectedURLs.reduce(0) { $0 + (reclaimable[$1] ?? 0) }- + selectedFolders.reduce(0) { $0 + (reclaimableFolders[$1] ?? 0) }- }-private func readScan() {guard let scan else {reclaimable = [:]@@ -115,29 +110,6 @@ final class DuplicateLibrary {selectedFolders = []}- func removeSelected() async -> TrashResult {- guard let scan else { return TrashResult() }- isRemoving = true- defer { isRemoving = false }- let result = await DuplicateRemoval.trash(- selectedURLs,- folders: selectedFolders,- from: scan,- using: TrashService(exclusions: ExclusionsStore.shared.exclusions)- )- let trashed = Set(result.trashed.map(\.originalURL))- // Reads the list again, since an exclusion can have narrowed it while the move ran.- guard let latest = self.scan else { return result }- let remaining = latest.removing(trashed)- self.scan = remaining- selectedURLs.subtract(trashed)- selectedFolders.subtract(trashed)- if let selection, !remaining.holds(selection) {- self.selection = nil- }- return result- }-/// Narrows the list to what `exclusions` leave. Duplicates scans only when asked, so without this a copy/// excluded from its own row would stay listed and selected until the move refused it.func leaveOut(_ exclusions: Exclusions) async {@@ -230,3 +202,49 @@ private extension DuplicateScan {extension DuplicateLibrary: StoppableWork {var isRunning: Bool { isScanning }}++extension DuplicateLibrary: CarriesSelection {+ var carriedParts: [CarriedSelection.Part] {+ guard selectedCount > 0 else { return [] }+ let files = selectedURLs.map { ($0, reclaimable[$0]) }+ let folders = selectedFolders.map { ($0, reclaimableFolders[$0]) }+ return [CarriedSelection.Part(+ page: Tool.duplicates.page(),+ title: String(localized: Tool.duplicates.title),+ source: Tool.duplicates.title.inEnglish,+ sourceKey: "tool",+ sizes: Dictionary(files + folders, uniquingKeysWith: { first, _ in first })+ )]+ }++ func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {+ guard let scan else { return TrashResult() }+ isRemoving = true+ defer { isRemoving = false }+ let result = await DuplicateRemoval.trash(+ selectedURLs.filter { part.sizes.keys.contains($0) },+ folders: selectedFolders.filter { part.sizes.keys.contains($0) },+ from: scan,+ using: TrashService(exclusions: ExclusionsStore.shared.exclusions)+ )+ let trashed = Set(result.trashed.map(\.originalURL))+ // Reads the list again, since an exclusion can have narrowed it while the move ran.+ guard let latest = self.scan else { return result }+ let remaining = latest.removing(trashed)+ self.scan = remaining+ selectedURLs.subtract(trashed)+ selectedFolders.subtract(trashed)+ if let selection, !remaining.holds(selection) {+ self.selection = nil+ }+ return result+ }++ /// Nothing to bring up to date: the move took what it moved out of the list.+ func refresh(after parts: [CarriedSelection.Part], apps: AppLibrary) async {}++ func deselect(_ part: CarriedSelection.Part) {+ selectedURLs.subtract(part.sizes.keys)+ selectedFolders.subtract(part.sizes.keys)+ }+}diff --git a/Peel/Model/FileSearchLibrary.swift b/Peel/Model/FileSearchLibrary.swiftindex e2f156d0..66f0ec96 100644--- a/Peel/Model/FileSearchLibrary.swift+++ b/Peel/Model/FileSearchLibrary.swift@@ -25,10 +25,6 @@ final class FileSearchLibrary {/// The exclusions the list is filtered by: those the search ran under, or those it was narrowed to since.private var filteredBy = Exclusions.none- var selectedSize: Int64 {- selectedURLs.reduce(0) { $0 + (sizes[$1] ?? 0) }- }-var chosenFile: FoundFile? {results?.files.first { $0.url == chosen }}@@ -86,15 +82,30 @@ final class FileSearchLibrary {exclusions.keeping(files, url: \.url)}- /// Moves the selected files to the Trash. `record` writes History before the search runs again, since a- /// Spotlight query can take a while and History is the way back for what just moved.- func removeSelected(recording record: (TrashResult) async -> Void) async -> TrashResult {+}++extension FileSearchLibrary: CarriesSelection {+ var carriedParts: [CarriedSelection.Part] {+ guard !selectedURLs.isEmpty else { return [] }+ return [CarriedSelection.Part(+ page: Tool.fileSearch.page(),+ title: String(localized: Tool.fileSearch.title),+ source: Tool.fileSearch.title.inEnglish,+ sourceKey: "tool",+ sizes: Dictionary(uniqueKeysWithValues: selectedURLs.map { ($0, sizes[$0]) })+ )]+ }++ func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {isRemoving = truedefer { isRemoving = false }- let files = results?.files.filter { selectedURLs.contains($0.url) && !$0.requiresPrivileges } ?? []- let result = await FileSearch.trash(files, using: TrashService(exclusions: ExclusionsStore.shared.exclusions))- await record(result)+ let files = results?.files.filter {+ selectedURLs.contains($0.url) && part.sizes.keys.contains($0.url) && !$0.requiresPrivileges+ } ?? []+ return await FileSearch.trash(files, using: TrashService(exclusions: ExclusionsStore.shared.exclusions))+ }++ func refresh(after parts: [CarriedSelection.Part], apps: AppLibrary) async {await search()- return result}}diff --git a/Peel/Model/InstallerLibrary.swift b/Peel/Model/InstallerLibrary.swiftindex 7dbc9cfc..4dede132 100644--- a/Peel/Model/InstallerLibrary.swift+++ b/Peel/Model/InstallerLibrary.swift@@ -33,17 +33,42 @@ final class InstallerLibrary {}}- func removeSelected(in kind: InstallerItem.Kind, installedApps: [InstalledApp], recording record: (TrashResult) async -> Void) async -> TrashResult {+ private func selected(in kind: InstallerItem.Kind) -> [InstallerItem] {+ items(in: kind).filter { !$0.isReadOnly && selectedURLs.contains($0.url) }+ }+}++extension InstallerLibrary: CarriesSelection {+ var carriedParts: [CarriedSelection.Part] {+ sections.compactMap { kind in+ let selected = selected(in: kind)+ guard !selected.isEmpty else { return nil }+ return CarriedSelection.Part(+ page: Tool.installers.page(kind.rawValue),+ title: String(localized: kind.title),+ source: kind.title.inEnglish,+ sourceKey: "installers.\(kind.rawValue)",+ sizes: Dictionary(selected.map { ($0.url, $0.size) }, uniquingKeysWith: { first, _ in first })+ )+ }+ }++ func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {+ guard let kind = InstallerItem.Kind(rawValue: part.page.scope) else { return TrashResult() }isRemoving = truedefer { isRemoving = false }- let selected = items(in: kind).filter { !$0.isReadOnly && selectedURLs.contains($0.url) }+ let selected = selected(in: kind).filter { part.sizes.keys.contains($0.url) }let privileged = Set(selected.filter(\.requiresPrivileges).map(\.url))- let result = await TrashService(exclusions: ExclusionsStore.shared.exclusions)+ return await TrashService(exclusions: ExclusionsStore.shared.exclusions).trash(selected.map(\.url), usingHelperFor: privileged)- // Written down before the rescan, which can take a while: History is the way back for what just moved.- await record(result)- await refresh(installedApps: installedApps)- return result+ }++ func refresh(after parts: [CarriedSelection.Part], apps: AppLibrary) async {+ await refresh(installedApps: apps.apps)+ }++ func choose(_ page: CarriedSelection.Page) {+ selection = InstallerItem.Kind(rawValue: page.scope)}}diff --git a/Peel/Model/OrphanLibrary.swift b/Peel/Model/OrphanLibrary.swiftindex c37b900f..cf56c20d 100644--- a/Peel/Model/OrphanLibrary.swift+++ b/Peel/Model/OrphanLibrary.swift@@ -20,8 +20,6 @@ final class OrphanLibrary {scan?.groups.first { $0.id == selection }}- /// The selected items in `group`. Selections are kept across groups, but only the group on screen is- /// counted or moved.func selected(in group: OrphanGroup) -> [OrphanItem] {group.items.filter { selectedURLs.contains($0.url) }}@@ -48,15 +46,41 @@ final class OrphanLibrary {}}- func removeSelected(in group: OrphanGroup, installedApps: [InstalledApp]) async -> TrashResult {+}++extension OrphanLibrary: CarriesSelection {+ var carriedParts: [CarriedSelection.Part] {+ (scan?.groups ?? []).compactMap { group in+ let selected = selected(in: group)+ guard !selected.isEmpty else { return nil }+ return CarriedSelection.Part(+ page: Tool.orphans.page(group.identifier),+ title: group.title,+ source: group.identifier,+ sourceKey: nil,+ sizes: Dictionary(selected.map { ($0.url, $0.size) }, uniquingKeysWith: { first, _ in first })+ )+ }+ }++ func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {+ guard let group = scan?.groups.first(where: { $0.identifier == part.page.scope }) else { return TrashResult() }isRemoving = truedefer { isRemoving = false }let exclusions = ExclusionsStore.shared.exclusionsreturn await OrphanRemoval.trash(- selected(in: group),- installedApps: installedApps,+ selected(in: group).filter { part.sizes.keys.contains($0.url) },+ installedApps: apps.apps,scanner: OrphanScanner(exclusions: exclusions),using: TrashService(exclusions: exclusions))}++ func refresh(after parts: [CarriedSelection.Part], apps: AppLibrary) async {+ await refresh(from: apps)+ }++ func choose(_ page: CarriedSelection.Page) {+ selection = page.scope+ }}diff --git a/Peel/Model/ProjectLibrary.swift b/Peel/Model/ProjectLibrary.swiftindex cccfcf5c..c8cd81d2 100644--- a/Peel/Model/ProjectLibrary.swift+++ b/Peel/Model/ProjectLibrary.swift@@ -107,17 +107,6 @@ final class ProjectLibrary {await refresh()}- func removeSelected(in group: ProjectGroup, recording record: (TrashResult) async -> Void) async -> TrashResult {- isRemoving = true- defer { isRemoving = false }- let urls = group.artifacts.map(\.url).filter(selectedURLs.contains)- let result = await TrashService(exclusions: ExclusionsStore.shared.exclusions).trash(urls)- // Written down before the rescan, which can take a while: History is the way back for what just moved.- await record(result)- await refresh()- return result- }-/// True when every artifact the checkbox acts on is excluded from backups. Artifacts with a generic name/// are never excluded by it, so they are not counted.func isExcludedFromBackups(_ group: ProjectGroup) -> Bool {@@ -146,4 +135,40 @@ final class ProjectLibrary {private func save() {UserDefaults.standard.set(folders.map { $0.path(percentEncoded: false) }, forKey: Self.foldersKey)}++ private func group(of page: CarriedSelection.Page) -> ProjectGroup? {+ groups?.first { $0.project.path(percentEncoded: false) == page.scope }+ }+}++extension ProjectLibrary: CarriesSelection {+ var carriedParts: [CarriedSelection.Part] {+ (groups ?? []).compactMap { group in+ let selected = group.artifacts.filter { selectedURLs.contains($0.url) }+ guard !selected.isEmpty else { return nil }+ return CarriedSelection.Part(+ page: Tool.projects.page(group.project.path(percentEncoded: false)),+ title: group.project.lastPathComponent,+ source: group.project.lastPathComponent,+ sourceKey: nil,+ sizes: Dictionary(selected.map { ($0.url, $0.size) }, uniquingKeysWith: { first, _ in first })+ )+ }+ }++ func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {+ guard let group = group(of: part.page) else { return TrashResult() }+ isRemoving = true+ defer { isRemoving = false }+ let urls = group.artifacts.map(\.url).filter { selectedURLs.contains($0) && part.sizes.keys.contains($0) }+ return await TrashService(exclusions: ExclusionsStore.shared.exclusions).trash(urls)+ }++ func refresh(after parts: [CarriedSelection.Part], apps: AppLibrary) async {+ await refresh()+ }++ func choose(_ page: CarriedSelection.Page) {+ selection = group(of: page)?.project+ }}diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swiftindex d0f86a23..5ee6286d 100644--- a/Peel/Model/RemovalHistoryStore.swift+++ b/Peel/Model/RemovalHistoryStore.swift@@ -61,6 +61,16 @@ struct RemovalBatch: Identifiable, Hashable {}}+/// A removal written into History part by part, so what each part moved is there as soon as it moved, and told+/// once, by `RemovalHistoryStore.finish`.+struct RemovalInProgress {+ let batch = UUID()+ /// What the removal refused is an entry of its own, and History's list tells its entries apart by id, so it+ /// never shares the removal's.+ let refusals = UUID()+ fileprivate(set) var records: [RemovalRecord] = []+}+/// What Peel was asked to move in one removal and did not.struct RefusalBatch: Identifiable, Hashable {let id: UUID@@ -136,33 +146,47 @@ final class RemovalHistoryStore {})}- /// Records a removal in History. When Peel wrote the source itself, pass it in English along with a- /// `sourceKey`, so History can show it in the user's language (see `RemovalRecord.sourceKey`). An item missing- /// from `sizes` is recorded as unknown.+ /// Records a removal from one place in History, as one entry. When Peel wrote the source itself, pass it in+ /// English along with a `sourceKey`, so History can show it in the user's language (see+ /// `RemovalRecord.sourceKey`). An item missing from `sizes` is recorded as unknown.func record(_ result: TrashResult, tool: Tool, source: String, sourceKey: String? = nil, sizes: [URL: Int64]) async {+ var removal = RemovalInProgress()+ await record(result, part: RemovalPart(source: source, sourceKey: sourceKey, tool: tool.rawValue), sizes: sizes, in: &removal)+ finish(removal)+ }++ /// Records in History what one part of `removal` moved, and what it refused.+ func record(_ result: TrashResult, part: RemovalPart, sizes: [URL: Int64], in removal: inout RemovalInProgress) async {// Refusals are logged before the early return below: a removal where nothing moved is the one most// worth a record.- await refusals.add(result.failures, source: source, sourceKey: sourceKey, tool: tool.rawValue)+ await refusals.add(result.failures, source: part.source, sourceKey: part.sourceKey, tool: part.tool, batch: removal.refusals)if !result.failures.isEmpty {await loadRefusals()}guard !result.trashed.isEmpty else { return }- let batch = UUID()- let new = result.trashed.map {- RemovalRecord(batch: batch, item: $0, size: sizes[$0.originalURL], source: source, sourceKey: sourceKey, tool: tool.rawValue)- }+ let new = part.records(of: result, sizes: sizes, batch: removal.batch)+ removal.records += new+ // History first: it is the way back for what just moved, and nothing that follows may keep it unwritten.+ apply(await log.add(new))+ }++ /// Tells what `removal` moved once every part of it is recorded: the bar's "Moved", VoiceOver, the lifetime+ /// totals, and Undo.+ func finish(_ removal: RemovalInProgress) {+ guard !removal.records.isEmpty else { return }let moved = RemovalBatch(- id: batch,- parts: [RemovalPart(source: source, sourceKey: sourceKey, tool: tool.rawValue)],+ id: removal.batch,+ parts: RemovalPart.of(removal.records.map { ($0.date, $0.part) }),date: .now,- records: new+ records: removal.records)justMoved = movedAccessibilityNotification.Announcement(moved.movedAnnouncement).post()- // History first: it is the way back for what just moved, and nothing that follows may keep it unwritten.- apply(await log.add(new))- stats?.add(result, sizes: sizes)- registerUndo(of: new, source: moved.title)+ stats?.add(+ TrashResult(trashed: removal.records.map(\.trashedItem)),+ sizes: [URL: Int64](measured: removal.records.map { ($0.originalURL, $0.size) })+ )+ registerUndo(of: removal.records, source: moved.title)}/// Makes the last batch undoable, as Finder does after a move to the Trash: Command-Z puts it back, and thediff --git a/Peel/Model/RemovalOutcome.swift b/Peel/Model/RemovalOutcome.swiftindex c2911f3f..2d19d387 100644--- a/Peel/Model/RemovalOutcome.swift+++ b/Peel/Model/RemovalOutcome.swift@@ -15,23 +15,31 @@ final class RemovalOutcome {private(set) var failures: [TrashFailure] = []/// The privacy resets the removal ran that are worth telling the user about.private(set) var privacy: [Privacy] = []+ /// The apps to quit before what their tools kept can move.+ private(set) var appsToQuit: [String] = []private(set) var movedCount = 0- var isEmpty: Bool { failures.isEmpty && privacy.isEmpty }+ var isEmpty: Bool { failures.isEmpty && privacy.isEmpty && appsToQuit.isEmpty }/// Keeps what the removal could not do, for the alert. `privacy` is every reset the removal ran, and/// `PrivacyReset.worthTelling` picks which of them to tell. A removal with nothing to tell changes nothing.- func report(_ result: TrashResult, privacy resets: [(app: InstalledApp, result: PrivacyReset.Result)] = []) {+ func report(+ _ result: TrashResult,+ privacy resets: [(app: InstalledApp, result: PrivacyReset.Result)] = [],+ appsToQuit: [String] = []+ ) {let privacy = PrivacyReset.worthTelling(resets, after: result).map { Privacy(app: $0.app.name, result: $0.result) }- guard !result.failures.isEmpty || !privacy.isEmpty else { return }+ guard !result.failures.isEmpty || !privacy.isEmpty || !appsToQuit.isEmpty else { return }failures = result.failuresmovedCount = result.trashed.countself.privacy = privacy+ self.appsToQuit = appsToQuit}func clear() {failures = []movedCount = 0privacy = []+ appsToQuit = []}}diff --git a/Peel/Model/SelectionCarrier.swift b/Peel/Model/SelectionCarrier.swiftnew file mode 100644index 00000000..5b4fe0dc--- /dev/null+++ b/Peel/Model/SelectionCarrier.swift@@ -0,0 +1,113 @@+import Foundation+import Observation+import PeelCore++/// A storage tool whose selection travels: Move to Trash on any storage tool's page moves what is selected on this+/// tool's pages too, once each has been seen (`CarriedSelection`).+protocol CarriesSelection: AnyObject {+ /// What is selected on each of the tool's pages, a part for each page with something selected.+ var carriedParts: [CarriedSelection.Part] { get }+ /// The app to quit before `part` can move, or nil when none of its apps is open.+ func appToQuit(for part: CarriedSelection.Part) -> String?+ /// Moves what is still selected of `part`, by the tool's own routine and checks. Nil, moving nothing, when the+ /// tool keeps the whole part because one of its apps is open.+ func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult?+ /// Brings the tool up to date once `parts` have moved, as after its own Move to Trash.+ func refresh(after parts: [CarriedSelection.Part], apps: AppLibrary) async+ func deselect(_ part: CarriedSelection.Part)+ /// Chooses the page in its tool, so the tool shows it when it is shown.+ func choose(_ page: CarriedSelection.Page)+}++extension CarriesSelection {+ func appToQuit(for part: CarriedSelection.Part) -> String? { nil }+ func choose(_ page: CarriedSelection.Page) {}+}++extension CarriesSelection where Self: RowSelection {+ func deselect(_ part: CarriedSelection.Part) {+ selectedURLs.subtract(part.sizes.keys)+ }+}++extension Tool {+ /// One of the tool's pages: `scope` names the page within the tool, and is empty for a tool that is one page.+ func page(_ scope: String = "") -> CarriedSelection.Page {+ CarriedSelection.Page(tool: rawValue, scope: scope)+ }+}++/// Carries what is selected on the storage tools' pages to Move to Trash on any of them, and moves it as one+/// removal: each part by its own tool, with that tool's checks, into one History entry.+@Observable+final class SelectionCarrier {+ private var carried = CarriedSelection()+ /// True while a Move to Trash moves the parts, one after another.+ private(set) var isMoving = false+ @ObservationIgnored private let tools: [Tool: any CarriesSelection]+ @ObservationIgnored private let apps: AppLibrary+ @ObservationIgnored private let history: RemovalHistoryStore+ @ObservationIgnored private let outcome: RemovalOutcome++ init(tools: [Tool: any CarriesSelection], apps: AppLibrary, history: RemovalHistoryStore, outcome: RemovalOutcome) {+ self.tools = tools+ self.apps = apps+ self.history = history+ self.outcome = outcome+ }++ func saw(_ page: CarriedSelection.Page) {+ carried.saw(page)+ }++ /// What Move to Trash moves from `page`: what is selected there and on every page seen before, in the+ /// sidebar's order.+ func parts(from page: CarriedSelection.Page) -> [CarriedSelection.Part] {+ var carried = carried+ carried.saw(page)+ let order = Tool.Group.allCases.flatMap(\.tools)+ return carried.parts(from: order.compactMap { tools[$0] }.flatMap(\.carriedParts), order: order.map(\.rawValue))+ }++ func appToQuit(among parts: [CarriedSelection.Part]) -> String? {+ parts.lazy.compactMap { part in self.tool(of: part)?.appToQuit(for: part) }.first+ }++ func deselect(_ part: CarriedSelection.Part) {+ tool(of: part)?.deselect(part)+ }++ func show(_ page: CarriedSelection.Page) {+ guard let tool = Tool(rawValue: page.tool) else { return }+ tools[tool]?.choose(page)+ Navigator.shared.requestedTool = tool+ }++ /// Moves `parts` as one removal. Each part is in History as soon as it moved, so nothing that moved is lost if+ /// Peel stops halfway, and a part whose tool kept it stays selected, with the app to quit named after.+ func move(_ parts: [CarriedSelection.Part]) async {+ isMoving = true+ defer { isMoving = false }+ var removal = RemovalInProgress()+ var appsToQuit: [String] = []+ let pass = await CarriedSelection.pass(parts) { part in+ guard let tool = tool(of: part), let result = await tool.move(part, apps: apps) else {+ appsToQuit.append(tool(of: part)?.appToQuit(for: part) ?? part.title)+ return nil+ }+ await history.record(result, part: part.removalPart, sizes: part.measuredSizes, in: &removal)+ return result+ }+ history.finish(removal)+ outcome.report(pass.result, appsToQuit: appsToQuit)+ let moved = pass.moved.map(\.part)+ for name in moved.tools {+ guard let tool = Tool(rawValue: name) else { continue }+ await tools[tool]?.refresh(after: moved.filter { $0.page.tool == name }, apps: apps)+ }+ }++ private func tool(of part: CarriedSelection.Part) -> (any CarriesSelection)? {+ Tool(rawValue: part.page.tool).flatMap { tools[$0] }+ }+}diff --git a/Peel/Model/SpaceLibrary.swift b/Peel/Model/SpaceLibrary.swiftindex b198d71f..069124c4 100644--- a/Peel/Model/SpaceLibrary.swift+++ b/Peel/Model/SpaceLibrary.swift@@ -9,20 +9,97 @@ final class SpaceLibrary: RowSelection {let scanRun = ScanRun()var isScanning: Bool { scanRun.isRunning }var selection: SpaceItem.ID?- /// What is selected inside the chosen item's folders.+ /// What is selected inside the areas' folders.var selectedURLs: Set<URL> = []- var isRemoving = false+ private(set) var isRemoving = false+ /// Each area's last plan: what its page lists, and what a selection carried from it is counted by.+ private(set) var plans: [SpaceItem.ID: SpaceRemoval.Plan] = [:]+ /// The area as it was, and the exclusions' revision, when its plan was made.+ @ObservationIgnored private var plannedFor: [SpaceItem.ID: (item: SpaceItem, exclusions: Int)] = [:]var selectedItem: SpaceItem? {report?.items.first { $0.id == selection }}func refresh() async {+ await refresh(replanning: [])+ }++ /// Makes the area's plan from what is on disk now, keeping what was chosen in it+ /// (`SpaceRemoval.Plan.selection(replacing:selected:)`).+ func plan(_ item: SpaceItem) async {+ let revision = ExclusionsStore.shared.revision+ let plan = await SpaceRemoval.plan(+ for: item,+ exclusions: ExclusionsStore.shared.exclusions,+ running: SpaceRemoval.namesOfRunningApps()+ )+ // A plan cut short measured only part of the area, and would read the rest as unknown.+ guard !Task.isCancelled else { return }+ let previous = plans[item.id]+ let chosen = plan.selection(replacing: previous, selected: selectedURLs)+ selectedURLs.subtract(previous?.removable ?? [])+ selectedURLs.formUnion(chosen)+ plans[item.id] = plan+ plannedFor[item.id] = (item, revision)+ }++ /// Scans again, and makes again the plans of the areas in `replanning` and of every area that changed since+ /// its plan was made, so what is carried from them follows what is on disk.+ private func refresh(replanning: Set<SpaceItem.ID>) async {guard let result = await scanRun.run({ await SpaceInventory.scan() }) else { return }report = result+ for id in plans.keys.filter({ id in !result.items.contains { $0.id == id } }) {+ selectedURLs.subtract(plans[id]?.removable ?? [])+ plans[id] = nil+ plannedFor[id] = nil+ }if let selection, !result.items.contains(where: { $0.id == selection }) {self.selection = nil}+ for item in result.items where plans[item.id] != nil {+ let made = plannedFor[item.id]+ if replanning.contains(item.id) || made?.item != item || made?.exclusions != ExclusionsStore.shared.revision {+ await plan(item)+ }+ }+ }+}++extension SpaceLibrary: CarriesSelection {+ var carriedParts: [CarriedSelection.Part] {+ (report?.items ?? []).compactMap { item in+ guard let plan = plans[item.id] else { return nil }+ let selected = plan.removable.filter(selectedURLs.contains)+ guard !selected.isEmpty else { return nil }+ return CarriedSelection.Part(+ page: Tool.space.page(item.id),+ title: String(localized: item.words.title),+ source: item.words.title.inEnglish,+ sourceKey: "space.\(item.id)",+ sizes: Dictionary(selected.map { ($0, plan.sizes[$0]) }, uniquingKeysWith: { first, _ in first })+ )+ }+ }++ /// Asks the area again rather than trusting its plan: an app opened since may be writing to some of these+ /// folders, and they are left where they are.+ func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {+ guard let item = report?.items.first(where: { $0.id == part.page.scope }) else { return TrashResult() }+ isRemoving = true+ defer { isRemoving = false }+ let exclusions = ExclusionsStore.shared.exclusions+ let removable = await SpaceRemoval.removable(in: item, exclusions: exclusions, running: SpaceRemoval.namesOfRunningApps())+ return await TrashService(exclusions: exclusions)+ .trash(removable.filter { selectedURLs.contains($0) && part.sizes.keys.contains($0) })+ }++ func refresh(after parts: [CarriedSelection.Part], apps: AppLibrary) async {+ await refresh(replanning: Set(parts.map(\.page.scope)))+ }++ func choose(_ page: CarriedSelection.Page) {+ selection = page.scope}}diff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swiftindex 371356df..76e00aef 100644--- a/Peel/PeelApp.swift+++ b/Peel/PeelApp.swift@@ -26,36 +26,66 @@ struct PeelApp: App {@State private var notifications: PeelNotifications@State private var stats = LifetimeStats()@State private var found = FoundLastTimeStore()- @State private var library = AppLibrary()- @State private var orphans = OrphanLibrary()- @State private var projects = ProjectLibrary()- @State private var installers = InstallerLibrary()+ @State private var library: AppLibrary+ @State private var orphans: OrphanLibrary+ @State private var projects: ProjectLibrary+ @State private var installers: InstallerLibrary@State private var tweaks = TweakLibrary()@State private var extensions = ExtensionLibrary()@State private var cloud = CloudLibrary()@State private var backgroundItems = BackgroundItemLibrary()@State private var packages = PackageLibrary()- @State private var developer = DeveloperLibrary()- @State private var duplicates = DuplicateLibrary()- @State private var fileSearch = FileSearchLibrary()+ @State private var developer: DeveloperLibrary+ @State private var duplicates: DuplicateLibrary+ @State private var fileSearch: FileSearchLibrary@State private var plugins = PluginLibrary()@State private var homebrew = HomebrewLibrary()@State private var helper = HelperModel()@State private var home = HomeModel()- @State private var history = RemovalHistoryStore()- @State private var outcome = RemovalOutcome()+ @State private var history: RemovalHistoryStore+ @State private var outcome: RemovalOutcome@State private var intel = IntelLibrary()- @State private var space = SpaceLibrary()+ @State private var space: SpaceLibrary+ @State private var carrier: SelectionCarrier@State private var background = BackgroundWork()@State private var hasLaunched = falseprivate let exclusions = ExclusionsStore.shared/// Sets the notification delegate before launch finishes, which `UNUserNotificationCenter.h` requires for- /// clicks on notifications to reach it. A view's task can run later than that.+ /// clicks on notifications to reach it. A view's task can run later than that. The storage tools are made here+ /// too, so the carrier of their selection reads the same libraries their pages show.init() {let notifications = PeelNotifications()notifications.activate()_notifications = State(initialValue: notifications)++ let (library, history, outcome) = (AppLibrary(), RemovalHistoryStore(), RemovalOutcome())+ let (orphans, space, developer, projects) = (OrphanLibrary(), SpaceLibrary(), DeveloperLibrary(), ProjectLibrary())+ let (installers, duplicates, fileSearch) = (InstallerLibrary(), DuplicateLibrary(), FileSearchLibrary())+ _library = State(initialValue: library)+ _history = State(initialValue: history)+ _outcome = State(initialValue: outcome)+ _orphans = State(initialValue: orphans)+ _space = State(initialValue: space)+ _developer = State(initialValue: developer)+ _projects = State(initialValue: projects)+ _installers = State(initialValue: installers)+ _duplicates = State(initialValue: duplicates)+ _fileSearch = State(initialValue: fileSearch)+ _carrier = State(initialValue: SelectionCarrier(+ tools: [+ .orphans: orphans,+ .space: space,+ .developer: developer,+ .projects: projects,+ .installers: installers,+ .duplicates: duplicates,+ .fileSearch: fileSearch,+ ],+ apps: library,+ history: history,+ outcome: outcome+ ))}/// Keeps the app list current as apps are installed and removed while Peel is open.@@ -177,6 +207,7 @@ struct PeelApp: App {.environment(history).environment(intel).environment(space)+ .environment(carrier).environment(exclusions)// Settings also open from the sidebar, so this window needs everything they read, `trashMonitor` too..environment(trashMonitor)diff --git a/Peel/Views/CarriedPartsList.swift b/Peel/Views/CarriedPartsList.swiftnew file mode 100644index 00000000..e5631612--- /dev/null+++ b/Peel/Views/CarriedPartsList.swift@@ -0,0 +1,73 @@+import PeelCore+import SwiftUI++/// The pages a selection is on, each with what is selected there: a click on another page goes there, and the+/// button beside each deselects what is selected on it.+struct CarriedPartsList: View {+ @Environment(SelectionCarrier.self) private var carrier+ @Environment(\.dismiss) private var dismiss+ @State private var pointingAt: CarriedSelection.Page?+ /// The page the list was opened from.+ let page: CarriedSelection.Page++ var body: some View {+ VStack(spacing: 2) {+ ForEach(carrier.parts(from: page)) { part in+ HStack(spacing: 6) {+ if part.page == page {+ label(part)+ } else {+ Button {+ carrier.show(part.page)+ dismiss()+ } label: {+ label(part)+ }+ .buttonStyle(.plain)+ .background(.quaternary.opacity(pointingAt == part.page ? 1 : 0), in: .rect(cornerRadius: 6))+ .pointerStyle(.link)+ .onHover { pointingAt = $0 ? part.page : (pointingAt == part.page ? nil : pointingAt) }+ }+ Button {+ carrier.deselect(part)+ } label: {+ Label("Deselect", systemImage: "xmark.circle.fill")+ .minimumTarget()+ }+ .labelStyle(.iconOnly)+ .buttonStyle(.borderless)+ .foregroundStyle(.secondary)+ .help(Text("Deselect"))+ }+ }+ }+ .padding(10)+ .frame(width: 340)+ }++ private func label(_ part: CarriedSelection.Part) -> some View {+ HStack(spacing: 10) {+ if let tool = Tool(rawValue: part.page.tool) {+ Image(systemName: tool.systemImage)+ .foregroundStyle(.secondary)+ .frame(width: 20)+ .accessibilityLabel(Text(tool.title))+ }+ VStack(alignment: .leading, spacing: 2) {+ Text(verbatim: part.title)+ .lineLimit(1)+ .truncationMode(.middle)+ Text("^[\(part.count) item](inflect: true)")+ .font(.caption)+ .foregroundStyle(.secondary)+ }+ Spacer(minLength: 8)+ Text(part.total.text)+ .rowFigure()+ }+ .padding(.horizontal, 6)+ .padding(.vertical, 4)+ .contentShape(.rect)+ .accessibilityElement(children: .combine)+ }+}diff --git a/Peel/Views/Developer/DeveloperDetailView.swift b/Peel/Views/Developer/DeveloperDetailView.swiftindex 5c09ae02..66f46de6 100644--- a/Peel/Views/Developer/DeveloperDetailView.swift+++ b/Peel/Views/Developer/DeveloperDetailView.swift@@ -3,12 +3,6 @@ import SwiftUIstruct DeveloperDetailView: View {@Environment(DeveloperLibrary.self) private var developer- @Environment(RemovalHistoryStore.self) private var history- @State private var isConfirmingRemoval = false- @Environment(RemovalOutcome.self) private var outcome- @State private var isShowingQuitAlert = false- /// The app the quit alert names: whichever of the environment's apps is running.- @State private var appToQuit = ""let environment: DeveloperEnvironmentvar body: some View {@@ -37,42 +31,11 @@ struct DeveloperDetailView: View {}.dimmedWhileBusy(developer.isScanning).safeAreaBar(edge: .bottom) {- RemovalBar(- selectedSize: selected.known,- isSelectionMeasured: selected.isComplete,- isScanning: developer.isScanning,- scan: developer.scanRun,- isEnabled: !selectedLocations.isEmpty && !developer.isRemoving && !developer.isScanning,- onRemove: requestRemoval- )+ RemovalBar(page: Tool.developer.page(environment.id), isScanning: developer.isScanning, scan: developer.scanRun)}.fadesInColumn(whenRowsChange: environment.locations.map(\.id)).navigationTitle(environment.name).toolbar(removing: .title)- .confirmationDialog(Text.movingToTrash(selectedLocations.count, selected), isPresented: $isConfirmingRemoval) {- Button("Move to Trash") {- Task {- let result = await developer.removeSelected(from: environment) { result in- await history.record(- result,- tool: .developer,- source: environment.name,- sizes: [URL: Int64](measured: environment.locations.map { ($0.url, $0.size) })- )- }- // A nil result means nothing moved: one of the environment's apps was opened in the meantime.- guard let result else {- askToQuit()- return- }- outcome.report(result)- }- }- Button("Cancel", role: .cancel) {}- }- .alert("Quit \(appToQuit) before removing its files.", isPresented: $isShowingQuitAlert) {- Button("OK", role: .cancel) {}- }}private var header: some View {@@ -102,27 +65,6 @@ struct DeveloperDetailView: View {private var keptByDefault: Int {environment.locations.count { !$0.isRecommended }}-- private var selectedLocations: [DeveloperEnvironment.Location] {- environment.locations.filter { developer.selectedURLs.contains($0.url) }- }-- private var selected: SizeTotal {- SizeTotal(selectedLocations.map(\.size))- }-- private func requestRemoval() {- if developer.runningApp(of: environment) != nil {- askToQuit()- } else {- isConfirmingRemoval = true- }- }-- private func askToQuit() {- appToQuit = developer.runningApp(of: environment) ?? environment.name- isShowingQuitAlert = true- }}extension DeveloperEnvironment.ContentKind {diff --git a/Peel/Views/Duplicates/DuplicateStatusViews.swift b/Peel/Views/Duplicates/DuplicateStatusViews.swiftindex 4106cb2b..30c18695 100644--- a/Peel/Views/Duplicates/DuplicateStatusViews.swift+++ b/Peel/Views/Duplicates/DuplicateStatusViews.swift@@ -92,40 +92,14 @@ struct DuplicateSummaryView: View {struct DuplicateRemovalBar: View {@Environment(DuplicateLibrary.self) private var duplicates- @Environment(RemovalHistoryStore.self) private var history- @Environment(RemovalOutcome.self) private var outcome- @State private var isConfirmingRemoval = falsevar body: some View {+ // The selection can include groups a search hides, so the question says how many groups it reaches.RemovalBar(- selectedSize: duplicates.selectedReclaimableSize,+ page: Tool.duplicates.page(),isScanning: false,- isEnabled: duplicates.selectedCount > 0 && !duplicates.isRemoving,- onRemove: { isConfirmingRemoval = true }+ message: Text("From ^[\(groupsAffected) group](inflect: true). A selected folder goes with everything in it."))- .confirmationDialog(- Text.movingToTrash(duplicates.selectedCount, SizeTotal(known: duplicates.selectedReclaimableSize, isComplete: true)),- isPresented: $isConfirmingRemoval- ) {- Button("Move to Trash") {- Task {- // Sizes are read before the move: `removeSelected()` takes the moved copies out of the scan.- let scan = duplicates.scan- let sizes = Dictionary(- (scan?.groups ?? []).flatMap(\.files).map { ($0.url, $0.reclaimableSize) }- + (scan?.folderGroups ?? []).flatMap(\.folders).map { ($0.url, $0.reclaimableSize) },- uniquingKeysWith: { first, _ in first }- )- let result = await duplicates.removeSelected()- await history.record(result, tool: .duplicates, source: Tool.duplicates.title.inEnglish, sourceKey: "tool", sizes: sizes)- outcome.report(result)- }- }- Button("Cancel", role: .cancel) {}- } message: {- // The selection can include groups a search hides, so the message says how many groups it reaches.- Text("From ^[\(groupsAffected) group](inflect: true). A selected folder goes with everything in it.")- }}}diff --git a/Peel/Views/FileSearch/FileSearchList.swift b/Peel/Views/FileSearch/FileSearchList.swiftindex 44687733..21c3f6d6 100644--- a/Peel/Views/FileSearch/FileSearchList.swift+++ b/Peel/Views/FileSearch/FileSearchList.swift@@ -5,11 +5,8 @@ import SwiftUIstruct FileSearchList: View {@Environment(FileSearchLibrary.self) private var search@Environment(ExclusionsStore.self) private var exclusions- @Environment(RemovalHistoryStore.self) private var history- @State private var isConfirmingRemoval = false@State private var isShowingFilters = false@State private var isRescanning = false- @Environment(RemovalOutcome.self) private var outcomevar body: some View {@Bindable var search = search@@ -72,12 +69,7 @@ struct FileSearchList: View {}.safeAreaBar(edge: .bottom) {if search.results?.files.isEmpty == false {- RemovalBar(- selectedSize: search.selectedSize,- isScanning: search.isSearching,- isEnabled: !search.selectedURLs.isEmpty && !search.isRemoving && !search.isSearching,- onRemove: { isConfirmingRemoval = true }- )+ RemovalBar(page: Tool.fileSearch.page(), isScanning: search.isSearching)}}.fadesInColumn(whenRowsChange: search.results?.files.map(\.id))@@ -118,27 +110,6 @@ struct FileSearchList: View {.task(id: exclusions.revision) {await search.leaveOut(exclusions.exclusions)}- .confirmationDialog(- Text.movingToTrash(search.selectedURLs.count, SizeTotal(known: search.selectedSize, isComplete: true)),- isPresented: $isConfirmingRemoval- ) {- Button("Move to Trash") {- Task {- let files = search.results?.files ?? []- let result = await search.removeSelected { result in- await history.record(- result,- tool: .fileSearch,- source: Tool.fileSearch.title.inEnglish,- sourceKey: "tool",- sizes: Dictionary(files.map { ($0.url, $0.size) }, uniquingKeysWith: { first, _ in first })- )- }- outcome.report(result)- }- }- Button("Cancel", role: .cancel) {}- }}private var phase: ScanPhase {diff --git a/Peel/Views/Installers/InstallerDetailView.swift b/Peel/Views/Installers/InstallerDetailView.swiftindex 29d43380..2499cfd1 100644--- a/Peel/Views/Installers/InstallerDetailView.swift+++ b/Peel/Views/Installers/InstallerDetailView.swift@@ -3,19 +3,13 @@ import PeelCoreimport SwiftUIstruct InstallerDetailView: View {- @Environment(AppLibrary.self) private var library@Environment(InstallerLibrary.self) private var installers- @Environment(RemovalHistoryStore.self) private var history- @State private var isConfirmingRemoval = false- @Environment(RemovalOutcome.self) private var outcome@Environment(HelperModel.self) private var helperlet kind: InstallerItem.Kindvar body: some View {let rows = itemslet hasNoteColumn = rows.contains { !$0.isReadOnly && detail(for: $0) != nil }- let selectedRows = selectedItems(among: rows)- let selected = SizeTotal(selectedRows.map(\.size))List {header(rows)@@ -79,32 +73,12 @@ struct InstallerDetailView: View {.dimmedWhileBusy(installers.isScanning).safeAreaBar(edge: .bottom) {if kind != .deviceBackup {- RemovalBar(- selectedSize: selected.known,- isSelectionMeasured: selected.isComplete,- isScanning: installers.isScanning,- scan: installers.scanRun,- isEnabled: !selectedRows.isEmpty && !installers.isRemoving && !installers.isScanning,- onRemove: { isConfirmingRemoval = true }- )+ RemovalBar(page: Tool.installers.page(kind.rawValue), isScanning: installers.isScanning, scan: installers.scanRun)}}.fadesInColumn(whenRowsChange: items.map(\.id)).navigationTitle(Text(kind.title)).toolbar(removing: .title)- .confirmationDialog(Text.movingToTrash(selectedRows.count, selected), isPresented: $isConfirmingRemoval) {- Button("Move to Trash") {- Task {- // Sizes are read before the move: the rescan after it does not list the items that moved.- let sizes = [URL: Int64](measured: items.map { ($0.url, $0.size) })- let result = await installers.removeSelected(in: kind, installedApps: library.apps) { result in- await history.record(result, tool: .installers, source: kind.title.inEnglish, sourceKey: "installers.\(kind.rawValue)", sizes: sizes)- }- outcome.report(result)- }- }- Button("Cancel", role: .cancel) {}- }}private var items: [InstallerItem] {@@ -134,10 +108,6 @@ struct InstallerDetailView: View {}}- private func selectedItems(among rows: [InstallerItem]) -> [InstallerItem] {- rows.filter { !$0.isReadOnly && installers.selectedURLs.contains($0.url) }- }-private func detail(for item: InstallerItem) -> LocalizedStringResource? {if let app = item.installedApp {return "\(app) is already installed"diff --git a/Peel/Views/Orphans/OrphanDetailView.swift b/Peel/Views/Orphans/OrphanDetailView.swiftindex c2d440a9..1c0472f6 100644--- a/Peel/Views/Orphans/OrphanDetailView.swift+++ b/Peel/Views/Orphans/OrphanDetailView.swift@@ -2,12 +2,8 @@ import PeelCoreimport SwiftUIstruct OrphanDetailView: View {- @Environment(AppLibrary.self) private var library@Environment(OrphanLibrary.self) private var orphans@Environment(HelperModel.self) private var helper- @Environment(RemovalHistoryStore.self) private var history- @State private var isConfirmingRemoval = false- @Environment(RemovalOutcome.self) private var outcomelet group: OrphanGroupvar body: some View {@@ -52,25 +48,11 @@ struct OrphanDetailView: View {}.dimmedWhileBusy(orphans.isScanning).safeAreaBar(edge: .bottom) {- RemovalBar(- selectedSize: selected.known,- isSelectionMeasured: selected.isComplete,- isScanning: orphans.isScanning,- scan: orphans.scanRun,- isEnabled: !orphans.selected(in: group).isEmpty && !orphans.isRemoving && !orphans.isScanning,- onRemove: { isConfirmingRemoval = true }- )+ RemovalBar(page: Tool.orphans.page(group.identifier), isScanning: orphans.isScanning, scan: orphans.scanRun)}.fadesInColumn(whenRowsChange: group.items.map(\.id)).navigationTitle(group.title).toolbar(removing: .title)- // The dialog counts only this group's selected items, because items selected in other groups are not moved.- .confirmationDialog(Text.movingToTrash(orphans.selected(in: group).count, selected), isPresented: $isConfirmingRemoval) {- Button("Move to Trash") {- Task { await remove() }- }- Button("Cancel", role: .cancel) {}- }}private var hasNoteColumn: Bool {@@ -114,21 +96,9 @@ struct OrphanDetailView: View {}}- private var selected: SizeTotal {- SizeTotal(orphans.selected(in: group).map(\.size))- }-/// What Select All selects. A row held back waits to be chosen by hand, as Review Before Removing does on an/// app's page.private var selectableURLs: [URL] {group.items.filter { $0.heldBack == nil && (helper.canAct || !$0.requiresPrivileges) }.map(\.url)}-- private func remove() async {- let result = await orphans.removeSelected(in: group, installedApps: library.apps)- outcome.report(result)- // History is written before the rescan, which can take a while: it is how the user puts back what just moved.- await history.record(result, tool: .orphans, source: group.identifier, sizes: [URL: Int64](measured: group.items.map { ($0.url, $0.size) }))- await orphans.refresh(from: library)- }}diff --git a/Peel/Views/Projects/ProjectDetailView.swift b/Peel/Views/Projects/ProjectDetailView.swiftindex 515ca07a..01dd02c7 100644--- a/Peel/Views/Projects/ProjectDetailView.swift+++ b/Peel/Views/Projects/ProjectDetailView.swift@@ -3,9 +3,6 @@ import SwiftUIstruct ProjectDetailView: View {@Environment(ProjectLibrary.self) private var projects- @Environment(RemovalHistoryStore.self) private var history- @State private var isConfirmingRemoval = false- @Environment(RemovalOutcome.self) private var outcomelet group: ProjectGroupvar body: some View {@@ -67,33 +64,14 @@ struct ProjectDetailView: View {.dimmedWhileBusy(projects.isScanning).safeAreaBar(edge: .bottom) {RemovalBar(- selectedSize: selected.known,- isSelectionMeasured: selected.isComplete,+ page: Tool.projects.page(group.project.path(percentEncoded: false)),isScanning: projects.isScanning,- scan: projects.scanRun,- isEnabled: !selectedArtifacts.isEmpty && !projects.isRemoving && !projects.isScanning,- onRemove: { isConfirmingRemoval = true }+ scan: projects.scanRun)}.fadesInColumn(whenRowsChange: group.artifacts.map(\.url)).navigationTitle(group.project.lastPathComponent).toolbar(removing: .title)- .confirmationDialog(Text.movingToTrash(selectedArtifacts.count, selected), isPresented: $isConfirmingRemoval) {- Button("Move to Trash") {- Task {- let result = await projects.removeSelected(in: group) { result in- await history.record(- result,- tool: .projects,- source: group.project.lastPathComponent,- sizes: [URL: Int64](measured: group.artifacts.map { ($0.url, $0.size) })- )- }- outcome.report(result)- }- }- Button("Cancel", role: .cancel) {}- }}private var header: some View {@@ -124,14 +102,6 @@ struct ProjectDetailView: View {}}- private var selectedArtifacts: [ProjectArtifact] {- group.artifacts.filter { projects.selectedURLs.contains($0.url) }- }-- private var selected: SizeTotal {- SizeTotal(selectedArtifacts.map(\.size))- }-private func detail(for artifact: ProjectArtifact) -> LocalizedStringResource {"Made by \(artifact.tool)"}diff --git a/Peel/Views/RemovalBar.swift b/Peel/Views/RemovalBar.swiftindex 45dc52c7..c74cf6ff 100644--- a/Peel/Views/RemovalBar.swift+++ b/Peel/Views/RemovalBar.swift@@ -4,16 +4,19 @@ import SwiftUIstruct RemovalBar: View {@Environment(ExclusionsStore.self) private var exclusions@Environment(RemovalHistoryStore.self) private var history+ @Environment(SelectionCarrier.self) private var carrier/// What the last removal moved while this bar was on screen, shown briefly in place of the selection.@State private var moved: RemovalBatch?- let selectedSize: Int64- /// False when a selected item's size is unknown, so the total shown is only a lower bound ("Over X").- var isSelectionMeasured = true+ /// What the question asks about: the parts as they were when Move to Trash was pressed.+ @State private var question: [CarriedSelection.Part] = []+ @State private var isAsking = false+ @State private var appToQuit = ""+ @State private var isAskingToQuit = false+ @State private var isShowingPages = false+ private let purpose: Purposelet isScanning: Bool/// The page's scan. Its count of items read is shown beside the spinner.var scan: ScanRun?- let isEnabled: Bool- let onRemove: () -> Void/// The button's title. iCloud Drive passes its own, since freeing a local copy isn't moving it to the Trash.var title: LocalizedStringResource = "Move to Trash"var systemImage = "trash"@@ -21,11 +24,72 @@ struct RemovalBar: View {/// action History doesn't record (freeing iCloud files, for example).var notice: BarNotice?- private var total: SizeTotal {- SizeTotal(known: selectedSize, isComplete: isSelectionMeasured)+ private enum Purpose {+ /// What the page itself selected, which `onRemove` acts on.+ case own(SizeTotal, isEnabled: Bool, onRemove: () -> Void)+ /// A storage tool's page: the bar counts and moves what is selected there and on every such page seen+ /// before (`SelectionCarrier`). `message` goes under the question when only this page's selection moves.+ case carried(CarriedSelection.Page, message: Text?)+ }++ private struct Reading {+ let total: SizeTotal+ /// How many pages the selection is on, when one of them is not this page.+ let pages: Int?+ let isEnabled: Bool+ let remove: () -> Void+ }++ /// A bar for what the page itself selected. `isSelectionMeasured` is false when a selected item's size is+ /// unknown, so the total shown is only a lower bound ("Over X").+ init(+ selectedSize: Int64,+ isSelectionMeasured: Bool = true,+ isScanning: Bool,+ scan: ScanRun? = nil,+ isEnabled: Bool,+ onRemove: @escaping () -> Void,+ title: LocalizedStringResource = "Move to Trash",+ systemImage: String = "trash",+ notice: BarNotice? = nil+ ) {+ purpose = .own(SizeTotal(known: selectedSize, isComplete: isSelectionMeasured), isEnabled: isEnabled, onRemove: onRemove)+ self.isScanning = isScanning+ self.scan = scan+ self.title = title+ self.systemImage = systemImage+ self.notice = notice+ }++ /// A bar for a page of the storage tools, whose selection travels to the others' pages.+ init(page: CarriedSelection.Page, isScanning: Bool, scan: ScanRun? = nil, message: Text? = nil) {+ purpose = .carried(page, message: message)+ self.isScanning = isScanning+ self.scan = scan+ }++ private var page: CarriedSelection.Page? {+ if case .carried(let page, _) = purpose { page } else { nil }+ }++ private var reading: Reading {+ switch purpose {+ case .own(let total, let isEnabled, let onRemove):+ return Reading(total: total, pages: nil, isEnabled: isEnabled, remove: onRemove)+ case .carried(let page, _):+ let parts = carrier.parts(from: page)+ return Reading(+ total: parts.total,+ pages: parts.contains { $0.page != page } ? parts.count : nil,+ isEnabled: !parts.isEmpty && !carrier.isMoving && !isScanning,+ remove: { ask(about: parts) }+ )+ }}var body: some View {+ let reading = reading+ let isEnabled = reading.isEnabled && !exclusions.exclusions.isUnreadableFloatingBar {if let notice {Text(verbatim: notice.figure)@@ -44,22 +108,41 @@ struct RemovalBar: View {.controlSize(.small)ReadSoFar(scan: scan).foregroundStyle(.secondary)+ } else if let pages = reading.pages, let page {+ // The pages go under the figure rather than beside it, so the capsule stays as wide as with the+ // selection of one page, which fits beside the button in every language at the narrowest column.+ Button {+ isShowingPages = true+ } label: {+ VStack(alignment: .leading, spacing: 0) {+ figure(reading.total)+ HStack(spacing: 4) {+ Text("Selected on ^[\(pages) page](inflect: true)")+ Image(systemName: "chevron.up")+ .font(.caption2.weight(.semibold))+ .accessibilityHidden(true)+ }+ .font(.subheadline)+ .foregroundStyle(.secondary)+ }+ .contentShape(.rect)+ }+ .buttonStyle(.plain)+ .popover(isPresented: $isShowingPages, arrowEdge: .top) {+ CarriedPartsList(page: page)+ }} else {- Text(total.text)- .font(.barFigure)- .monospacedDigit()- // Given the value, the digits roll down when the total falls and up when it rises.- .contentTransition(.numericText(value: Double(selectedSize)))- .id(total.textKind)+ figure(reading.total)Text("Selected").foregroundStyle(.secondary)}} action: {- Button(String(localized: title), systemImage: systemImage, action: onRemove)- .disabled(!isEnabled || exclusions.exclusions.isUnreadable)+ Button(String(localized: title), systemImage: systemImage, action: reading.remove)+ .disabled(!isEnabled)}- .focusedSceneValue(\.moveToTrash, MenuCommand(title: title, isEnabled: isEnabled && !exclusions.exclusions.isUnreadable, perform: onRemove))- .motion(value: selectedSize)+ .focusedSceneValue(\.moveToTrash, MenuCommand(title: title, isEnabled: isEnabled, perform: reading.remove))+ .motion(value: reading.total)+ .motion(value: reading.pages).motion(value: isScanning).motion(value: moved).motion(value: notice)@@ -72,6 +155,62 @@ struct RemovalBar: View {guard !Task.isCancelled else { return }moved = nil}+ .task(id: page) {+ if let page { carrier.saw(page) }+ }+ .confirmationDialog(Text.movingToTrash(question.itemCount, question.total), isPresented: $isAsking) {+ Button("Move to Trash") {+ let parts = question+ Task { await carrier.move(parts) }+ }+ Button("Cancel", role: .cancel) {}+ } message: {+ questionMessage+ }+ .alert("Quit \(appToQuit) before removing its files.", isPresented: $isAskingToQuit) {+ Button("OK", role: .cancel) {}+ }+ }++ private func figure(_ total: SizeTotal) -> some View {+ Text(total.text)+ .font(.barFigure)+ .monospacedDigit()+ // Given the value, the digits roll down when the total falls and up when it rises.+ .contentTransition(.numericText(value: Double(total.known)))+ .id(total.textKind)+ }++ /// Asks before moving anything, unless an open app keeps one of the parts: then nothing moves until it quits+ /// or its part is deselected.+ private func ask(about parts: [CarriedSelection.Part]) {+ if let app = carrier.appToQuit(among: parts) {+ appToQuit = app+ isAskingToQuit = true+ } else {+ question = parts+ isAsking = true+ }+ }++ /// Under the question: the page's own words when only its selection moves, and otherwise a line for each page.+ @ViewBuilder+ private var questionMessage: some View {+ if case .carried(let page, let message) = purpose, question.map(\.page) == [page] {+ message+ } else {+ Text(verbatim: question.map(line).joined(separator: "\n"))+ }+ }++ private func line(_ part: CarriedSelection.Part) -> String {+ let total = part.total+ if total.known == 0 {+ return String(inflecting: "\(part.title): ^[\(part.count) item](inflect: true)")+ }+ return total.isComplete+ ? String(inflecting: "\(part.title): ^[\(part.count) item](inflect: true), \(total.known.byteCount)")+ : String(inflecting: "\(part.title): ^[\(part.count) item](inflect: true), over \(total.known.byteCount)")}}@@ -85,4 +224,3 @@ struct BarNotice: Equatable {let figure: Stringlet words: LocalizedStringResource}-diff --git a/Peel/Views/RemovalFailureAlert.swift b/Peel/Views/RemovalFailureAlert.swiftindex 4358e027..86d56a96 100644--- a/Peel/Views/RemovalFailureAlert.swift+++ b/Peel/Views/RemovalFailureAlert.swift@@ -37,14 +37,14 @@ struct RemovalFailureAlert: ViewModifier {}private var title: Text {- if outcome.failures.isEmpty {+ if outcome.failures.isEmpty, outcome.appsToQuit.isEmpty {return outcome.privacy.count == 1 ? Text("Privacy permissions weren’t reset.") : Text("Some privacy permissions weren’t reset.")}return outcome.movedCount == 0 ? Text("Nothing was moved to the Trash.") : Text("Some items couldn’t be moved to the Trash.")}private var message: String {- var lines = outcome.failures.prefix(Self.mostListed).map { "\($0.url.abbreviatedPath)\n\($0.reason.explanation)" }+ var lines = quitLines + outcome.failures.prefix(Self.mostListed).map { "\($0.url.abbreviatedPath)\n\($0.reason.explanation)" }let rest = outcome.failures.count - lines.countif rest > 0 {lines.append(String(inflecting: "And ^[\(rest) more item](inflect: true)."))@@ -65,11 +65,16 @@ struct RemovalFailureAlert: ViewModifier {/// Copies every item with its full path, since the alert lists only the first few and its text can't be/// selected.private func copyDetails() {- let lines = outcome.failures.map { "\($0.url.path(percentEncoded: false))\n\($0.reason.explanation)" } + extraLines+ let lines = quitLines + outcome.failures.map { "\($0.url.path(percentEncoded: false))\n\($0.reason.explanation)" } + extraLinesNSPasteboard.general.clearContents()NSPasteboard.general.setString(lines.joined(separator: "\n\n"), forType: .string)}+ /// A line for each app whose tool kept what was selected for it, since the app was open.+ private var quitLines: [String] {+ outcome.appsToQuit.map { String(localized: "Quit \($0) before removing its files.") }+ }+/// One line per privacy reset. When a single failed reset is all there is to report, the title already/// says so, and the line gives only the reason.private var privacyLines: [String] {diff --git a/Peel/Views/Space/SpaceDetailView.swift b/Peel/Views/Space/SpaceDetailView.swiftindex 511772e0..8db5829d 100644--- a/Peel/Views/Space/SpaceDetailView.swift+++ b/Peel/Views/Space/SpaceDetailView.swift@@ -4,19 +4,15 @@ import SwiftUIstruct SpaceDetailView: View {@Environment(SpaceLibrary.self) private var space- @Environment(RemovalHistoryStore.self) private var history- @Environment(RemovalOutcome.self) private var outcome- @Environment(ExclusionsStore.self) private var exclusions- @State private var isConfirmingRemoval = false- @State private var plan: SpaceRemoval.Plan?- /// The plan's removable children, in the order every list uses: unknown sizes first, then the largest.- @State private var rows: [URL] = []let item: SpaceItem- /// The apps that are open, by the names their folders may carry. Read each time rather than stored, since- /// an app can be opened while this page is on screen.- private var running: [String: String] {- SpaceRemoval.namesOfRunningApps()+ private var plan: SpaceRemoval.Plan? {+ space.plans[item.id]+ }++ /// The plan's removable children, in the order every list uses: unknown sizes first, then the largest.+ private var rows: [URL] {+ plan.map(Self.ordered) ?? []}var body: some View {@@ -77,36 +73,18 @@ struct SpaceDetailView: View {}.safeAreaBar(edge: .bottom) {if !item.isReadOnly {- RemovalBar(- selectedSize: selected.known,- isSelectionMeasured: selected.isComplete,- isScanning: plan == nil,- isEnabled: !selectedRows.isEmpty && !space.isRemoving,- onRemove: { isConfirmingRemoval = true }- )+ RemovalBar(page: Tool.space.page(item.id), isScanning: plan == nil)}}- // Builds the plan again when a rescan changes the item's size or the exclusions change, so the list- // follows what is on disk, not what was there when the page opened.- .task(id: [item.id, String(item.size ?? 0), String(exclusions.revision)]) {- plan = nil+ // Made again each time the page opens, since what is inside changes as apps run. A rescan that finds the+ // area changed makes it again too (`SpaceLibrary.refresh`).+ .task(id: item.id) {guard !item.isReadOnly else { return }- let found = await SpaceRemoval.plan(for: item, exclusions: exclusions.exclusions, running: running)- guard !Task.isCancelled else { return }- plan = found- rows = Self.ordered(found)- // Selects only the children whose size is known, as every page does, and leaves the rest to the user.- space.selectedURLs = Set(found.removable.filter { found.sizes[$0] != nil })+ await space.plan(item)}.fadesInColumn(whenRowsChange: rows).navigationTitle(Text(item.words.title)).toolbar(removing: .title)- .confirmationDialog(Text.movingToTrash(selectedRows.count, selected), isPresented: $isConfirmingRemoval) {- Button("Move to Trash") {- Task { await remove() }- }- Button("Cancel", role: .cancel) {}- }}@ViewBuilder@@ -184,31 +162,6 @@ struct SpaceDetailView: View {return plan == nil ? Text("in here") : Text("to remove")}- private var selectedRows: [URL] {- plan?.removable.filter { space.selectedURLs.contains($0) } ?? []- }-- private var selected: SizeTotal {- SizeTotal(selectedRows.map { plan?.sizes[$0] })- }-- private func remove() async {- space.isRemoving = true- defer { space.isRemoving = false }- let exclusions = ExclusionsStore.shared.exclusions- // Builds the plan again rather than trusting the one on screen. An app opened since then may be writing- // to some of these folders, and the new plan leaves them out.- let fresh = await SpaceRemoval.plan(for: item, exclusions: exclusions, running: running)- let urls = fresh.removable.filter { space.selectedURLs.contains($0) }- let result = await TrashService(exclusions: exclusions).trash(urls)- outcome.report(result)- await history.record(result, tool: .space, source: item.words.title.inEnglish, sourceKey: "space.\(item.id)", sizes: fresh.sizes)- let after = await SpaceRemoval.plan(for: item, exclusions: exclusions, running: running)- plan = after- rows = Self.ordered(after)- await space.refresh()- }-private static func ordered(_ plan: SpaceRemoval.Plan) -> [URL] {plan.removable.sorted { first, second inSizeTotal([plan.sizes[second]]) < SizeTotal([plan.sizes[first]])diff --git a/README.md b/README.mdindex 7522f058..ada7e5cd 100644--- a/README.md+++ b/README.md@@ -98,6 +98,11 @@ Peel is free and open source, and it speaks English and 17 other languages.- **Space:** what's taking up room, and which app it belongs to.- **File Search:** large or old files, found through Spotlight.+What you select on these pages, iCloud Drive aside, stays selected while you look at the others, and Move to Trash+on any of them moves it all at once, as one entry in History. Only the pages you have opened count, so nothing Peel+selected on a page you never saw goes with it. The bar at the foot of the page says how many pages that is, and+lists them.+### Look after your Mac<p align="center">diff --git a/SAFETY.md b/SAFETY.mdindex 1fb4cafa..90476828 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -153,6 +153,14 @@ moves only when you select it yourself.In Duplicates, one copy of every group always stays, and a file that changed since the scan is refused.+What you select on the pages that free space (Orphaned Files, Space, Developer, Build Artifacts, Installers and+Backups, Duplicates, and File Search) stays selected while you look at the others, and Move to Trash on any of+them moves all of it. Only a page you have opened counts: Developer and Build Artifacts select for you in every+tool and project they list, and what they selected on a page you never saw stays where it is. Before anything+moves, the question lists every page with how much it holds, and each page's part is moved by its own tool, with+that tool's checks at that moment: Developer waits for its app to quit, Space leaves out what an app opened since+is writing to, and Duplicates refuses a copy that changed.+Some things are shown and never removed at all, because the removal cannot be undone: local Time Machinesnapshots are explained, never deleted.