Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Keep Remove Peel going, and told, whatever page started it

Țugui Dragoșf787fbce5279
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index affd7798..2c677356 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -118126,6 +118126,112 @@
}
}
},
+ "Peel is still moving something, putting something back, or running Homebrew. Try again once it’s done." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ještě něco přesouvá, něco vrací zpět nebo spouští Homebrew. Zkuste to znovu, až skončí."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel verschiebt gerade noch etwas, legt etwas zurück oder führt Homebrew aus. Versuche es erneut, sobald Peel fertig ist."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel aún está trasladando algo, restaurando algo o ejecutando Homebrew. Vuelve a intentarlo cuando termine."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel est encore en train de déplacer quelque chose, de remettre quelque chose en place ou d’exécuter Homebrew. Réessayez une fois qu’il a terminé."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel sta ancora spostando o ripristinando qualcosa, oppure sta eseguendo Homebrew. Riprova quando avrà finito."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelはまだ、何かを移動しているか、何かを戻しているか、Homebrewを実行しています。完了したら、もう一度やり直してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 아직 무언가를 이동하거나, 되돌려 놓거나, Homebrew를 실행하고 있습니다. 작업이 끝나면 다시 시도하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel is nog iets aan het verplaatsen of terugzetten, of voert Homebrew uit. Probeer het opnieuw zodra dat klaar is."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nadal coś przenosi, coś przywraca lub uruchamia Homebrew. Spróbuj ponownie, gdy skończy."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel ainda está movendo algo, colocando algo de volta ou executando o Homebrew. Tente novamente quando ele terminar."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel încă mută ceva, pune ceva înapoi sau rulează Homebrew. Încercați din nou după ce termină."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel еще что-то перемещает или восстанавливает либо работает с Homebrew. Повторите попытку, когда он закончит."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel håller fortfarande på att flytta något, lägga tillbaka något eller köra Homebrew. Försök igen när det är klart."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel hâlâ bir şey taşıyor, bir şeyi yerine koyuyor veya Homebrew’u çalıştırıyor. Bu iş bittiğinde yeniden deneyin."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ще щось переміщує, щось повертає або виконує команди Homebrew. Спробуйте ще раз, коли вона закінчить."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel仍在移动或放回某些内容,或者正在运行Homebrew。请在它完成后再试一次。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel仍在移動項目、還原項目或執行Homebrew。請在完成後再試一次。"
+ }
+ }
+ }
+ },
"Peel is still set to open at login: remove it in System Settings > General > Login Items & Extensions." : {
"localizations" : {
"cs" : {
@@ -137743,6 +137849,112 @@
}
}
},
+ "Removing Peel…" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Odstraňování Peelu…"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel wird entfernt …"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Eliminando Peel…"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Suppression de Peel…"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Rimuovo Peel…"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelをアンインストール中…"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel 제거 중…"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel verwijderen…"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Odinstalowuję Peel…"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Removendo o Peel…"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Eliminare Peel…"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Удаление Peel…"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tar bort Peel…"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kaldırılıyor…"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Вилучення Peel…"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在移除Peel…"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在移除Peel⋯"
+ }
+ }
+ }
+ },
"Removing this signs you out of websites the app kept you signed in to." : {
"localizations" : {
"cs" : {
diff --git a/Peel/Model/QuitGuard.swift b/Peel/Model/QuitGuard.swift
index 97e9d7d7..43198870 100644
--- a/Peel/Model/QuitGuard.swift
+++ b/Peel/Model/QuitGuard.swift
@@ -47,6 +47,9 @@ final class QuitGuard {
return try await work()
}
+ /// Whether a removal, a Put Back or a Homebrew command is under way.
+ var hasWorkUnderWay: Bool { running > 0 }
+
/// Runs Peel's removal of itself, which ends Peel its own way, so a quit asked meanwhile is refused. Quitting
/// through AppKit would write the window's place and Peel's settings again, just after they went to the Trash.
func runRefusingQuit<T>(_ work: () async -> T) async -> T {
diff --git a/Peel/Model/SelfUninstall.swift b/Peel/Model/SelfUninstall.swift
index 768419cb..f0415d90 100644
--- a/Peel/Model/SelfUninstall.swift
+++ b/Peel/Model/SelfUninstall.swift
@@ -3,17 +3,57 @@ import Foundation
import Observation
import PeelCore
-/// Peel removing itself: its own files and the app, once the helper and the login item are gone.
+/// Peel removing itself: its own files and the app, once the helper and the login item are gone. The app holds one,
+/// so a removal goes on, and is told, whatever page or window started it.
@Observable
final class SelfUninstall {
private(set) var isRunning = false
- var failure: String?
- /// What stayed after the app itself moved to the Trash: files, and a login item. Peel is running from the Trash by
- /// then, so the alert that lists them has a single button, which quits.
- private(set) var leftBehind: String?
/// Where Peel's words are read once it is in the Trash: the folder of the language it was using, there, since the
/// main bundle still names the place Peel left. Nil reads them from the main bundle.
private(set) var words: Bundle?
+ /// Says what came of a removal that didn't end with Peel gone: the app's own alert, which a test stands in for.
+ private let tell: @MainActor (Report, _ words: Bundle?) -> Void
+
+ enum Report: Equatable {
+ case stayed(String)
+ /// Peel is in the Trash, and what stayed behind, after which Peel quits.
+ case leftBehind(String)
+ }
+
+ init(tell: @escaping @MainActor (Report, _ words: Bundle?) -> Void = SelfUninstall.alert) {
+ self.tell = tell
+ }
+
+ /// The alert of the app, shown wherever the person is, since the page that started the removal may be gone.
+ static func alert(_ report: Report, words: Bundle?) {
+ let alert = NSAlert()
+ switch report {
+ case .stayed(let reason):
+ alert.messageText = String(localized: "Peel couldn’t remove itself.")
+ alert.informativeText = reason
+ alert.runModal()
+ case .leftBehind(let lines):
+ alert.messageText = String(localized: "Peel is in the Trash, but a few things stayed behind.", bundle: words)
+ alert.informativeText = lines
+ alert.addButton(withTitle: String(localized: "Quit Peel", bundle: words))
+ alert.runModal()
+ quit()
+ }
+ }
+
+ /// Runs `removal` alone: never beside another removal of Peel, nor while Peel moves something, puts something
+ /// back, or runs Homebrew, whose History and folder Remove Peel takes. A quit is refused meanwhile, since Peel ends
+ /// itself once it has gone.
+ func runAlone(quitGuard: QuitGuard = .shared, _ removal: () async -> Void) async {
+ guard !isRunning else { return }
+ guard !quitGuard.hasWorkUnderWay else {
+ tell(.stayed(String(localized: "Peel is still moving something, putting something back, or running Homebrew. Try again once it’s done.")), words)
+ return
+ }
+ isRunning = true
+ defer { isRunning = false }
+ await quitGuard.runRefusingQuit(removal)
+ }
/// How this copy of Peel is removed: with Homebrew's command when Homebrew installed it, which it goes on listing
/// otherwise, or with Remove Peel.
@@ -43,16 +83,14 @@ final class SelfUninstall {
}
/// Removes Peel. The plan is made first, so a plan that cannot be made leaves Peel as it was, and then
- /// `SelfRemoval.remove` takes the steps. A quit is refused meanwhile, since Peel ends itself once it has gone.
+ /// `SelfRemoval.remove` takes the steps.
func run(
installedApps: [InstalledApp],
helper: HelperModel,
pausing work: StandingWork,
recording record: (TrashResult) async -> Void = { _ in }
) async {
- isRunning = true
- defer { isRunning = false }
- await QuitGuard.shared.runRefusingQuit {
+ await runAlone {
await remove(installedApps: installedApps, helper: helper, pausing: work, recording: record)
}
}
@@ -65,7 +103,7 @@ final class SelfUninstall {
) async {
let bundleURL = Bundle.main.bundleURL
guard let app = await AppLibrary.inspect(bundleURL) else {
- failure = String(localized: "Peel couldn’t read its own files.")
+ tell(.stayed(String(localized: "Peel couldn’t read its own files.")), words)
return
}
let exclusions = ExclusionsStore.shared.exclusions
@@ -75,7 +113,7 @@ final class SelfUninstall {
if let block = SelfRemoval.block(
selection: urls, isExcluded: plan.isExcluded, isOnAReadOnlyVolume: isOnAReadOnlyVolume
) {
- failure = Self.explanation(of: block)
+ tell(.stayed(Self.explanation(of: block)), words)
return
}
@@ -96,7 +134,7 @@ final class SelfUninstall {
)
guard case .moved(let moved, let stayed, let opensAtLogin) = outcome else {
if case .stayed(let stay) = outcome {
- failure = Self.failure(for: stay)
+ tell(.stayed(Self.failure(for: stay)), words)
}
return
}
@@ -110,10 +148,10 @@ final class SelfUninstall {
lines.append(String(localized: "Peel is still set to open at login: remove it in System Settings > General > Login Items & Extensions.", bundle: words))
}
guard lines.isEmpty else {
- leftBehind = lines.joined(separator: "\n\n")
+ tell(.leftBehind(lines.joined(separator: "\n\n")), words)
return
}
- quit()
+ Self.quit()
}
static func explanation(of block: SelfRemoval.Block) -> String {
@@ -150,7 +188,7 @@ final class SelfUninstall {
/// Exits at once with `_exit`: `NSApp.terminate` would let AppKit write the window's frame and saved state again,
/// and `exit` runs the handlers that write the cookie store at exit, all of which were just removed.
- func quit() {
+ static func quit() {
_exit(EXIT_SUCCESS)
}
}
diff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swift
index 2b5d1d55..6765e2b2 100644
--- a/Peel/PeelApp.swift
+++ b/Peel/PeelApp.swift
@@ -71,6 +71,7 @@ struct PeelApp: App {
@State private var space: SpaceLibrary
@State private var carrier: SelectionCarrier
@State private var background = StandingWork()
+ @State private var selfUninstall = SelfUninstall()
@State private var textEditing = TextEditing()
@State private var sheetInFront = SheetInFront()
@State private var hasLaunched = false
@@ -411,6 +412,7 @@ struct PeelApp: App {
.environment(background)
.environment(space)
.environment(carrier)
+ .environment(selfUninstall)
.environment(exclusions)
// Settings also open from the sidebar, so this window needs everything they read, `trashMonitor` too.
.environment(trashMonitor)
@@ -496,6 +498,7 @@ struct PeelApp: App {
.environment(home)
.environment(background)
.environment(orphans)
+ .environment(selfUninstall)
}
.windowResizability(.contentSize)
diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swift
index 3d18ce8d..d73278f4 100644
--- a/Peel/Views/Settings/SettingsView.swift
+++ b/Peel/Views/Settings/SettingsView.swift
@@ -212,7 +212,7 @@ private struct GeneralSettingsView: View {
@Environment(ExclusionsStore.self) private var exclusions
@Environment(StandingWork.self) private var background
@Environment(HomeModel.self) private var home
- @State private var selfUninstall = SelfUninstall()
+ @Environment(SelfUninstall.self) private var selfUninstall
@State private var isChoosingSidebarTools = false
// The widest tool symbol at the body size, so the titles of the tools line up.
@ScaledMetric(relativeTo: .body) private var toolSymbolWidth = 20.0
@@ -419,7 +419,15 @@ private struct GeneralSettingsView: View {
|| !history.mayMove || Self.runsFromAReadOnlyCopy
)
}
- if exclusions.exclusions.isUnreadable {
+ if selfUninstall.isRunning {
+ HStack(spacing: 6) {
+ ProgressView()
+ .controlSize(.small)
+ Text("Removing Peel…")
+ .font(.callout)
+ .foregroundStyle(.secondary)
+ }
+ } else if exclusions.exclusions.isUnreadable {
Text("Peel removes nothing and puts nothing back until you start the list over in Settings.")
.font(.callout)
.foregroundStyle(.secondary)
@@ -485,19 +493,6 @@ private struct GeneralSettingsView: View {
} message: {
Text("Peel, the files that are certainly its own, and its folder in Application Support go to the Trash, all but the Terminal settings zsh and ssh read, and its settings are cleared. That folder holds History, your exclusions, and Saved Settings. What you set in Tweaks and on the Terminal page stays as it is. The space is freed when you empty the Trash.")
}
- .alert("Peel couldn’t remove itself.", isPresented: isShowingSelfRemovalFailure) {
- Button("OK", role: .cancel) {}
- } message: {
- Text(verbatim: selfUninstall.failure ?? "")
- }
- .alert(
- Text("Peel is in the Trash, but a few things stayed behind.", bundle: selfUninstall.words),
- isPresented: .constant(selfUninstall.leftBehind != nil)
- ) {
- Button { selfUninstall.quit() } label: { Text("Quit Peel", bundle: selfUninstall.words) }
- } message: {
- Text(verbatim: selfUninstall.leftBehind ?? "")
- }
}
}
@@ -627,12 +622,6 @@ extension GeneralSettingsView {
)
}
- fileprivate var isShowingSelfRemovalFailure: Binding<Bool> {
- Binding(
- get: { selfUninstall.failure != nil },
- set: { if !$0 { selfUninstall.failure = nil } }
- )
- }
/// The cask Homebrew installed this copy of Peel from, found by the rule the Applications list follows.
fileprivate var ownCask: HomebrewPackage? {
diff --git a/PeelTests/SelfUninstallTests.swift b/PeelTests/SelfUninstallTests.swift
new file mode 100644
index 00000000..c71881f3
--- /dev/null
+++ b/PeelTests/SelfUninstallTests.swift
@@ -0,0 +1,44 @@
+import Foundation
+@testable import Peel
+import PeelCore
+import Synchronization
+import Testing
+
+@MainActor
+struct SelfUninstallTests {
+ @Test func runsOneRemovalOfPeelAtATime() async {
+ let selfUninstall = SelfUninstall { _, _ in }
+ let quitGuard = QuitGuard(asksToStop: { false }, answer: { _ in })
+ let runs = Mutex(0)
+ let (started, start) = AsyncStream<Void>.makeStream()
+ let (released, release) = AsyncStream<Void>.makeStream()
+
+ let first = Task {
+ await selfUninstall.runAlone(quitGuard: quitGuard) {
+ runs.withLock { $0 += 1 }
+ start.yield()
+ for await _ in released { break }
+ }
+ }
+ for await _ in started { break }
+ await selfUninstall.runAlone(quitGuard: quitGuard) { runs.withLock { $0 += 1 } }
+ release.yield()
+ await first.value
+
+ #expect(runs.withLock { $0 } == 1)
+ }
+
+ @Test func waitsForWhatPeelIsMovingFirst() async {
+ let told = Mutex<[SelfUninstall.Report]>([])
+ let selfUninstall = SelfUninstall { report, _ in told.withLock { $0.append(report) } }
+ let quitGuard = QuitGuard(asksToStop: { false }, answer: { _ in })
+ let ran = Mutex(false)
+
+ await quitGuard.run {
+ await selfUninstall.runAlone(quitGuard: quitGuard) { ran.withLock { $0 = true } }
+ }
+
+ #expect(!ran.withLock { $0 })
+ #expect(told.withLock { $0.count } == 1)
+ }
+}