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.

Quit a cask's app before Homebrew upgrades or uninstalls it

Țugui Dragoș12107cb8b177
diff --git a/GUIDE.md b/GUIDE.md
index a33d40e9..c248c207 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -242,12 +242,13 @@ and how many items the others hold.
- **Intel Software:** what still needs Rosetta, which macOS 27 is the last release to offer for most Intel software:
apps, the Intel-only parts inside other apps, plug-ins, drivers, background items, and the commands in
`/usr/local`.
-- **Homebrew:** your formulae and casks, with Update, Clean Up (and two deeper ones: downloads older than 30 days,
- or every download), Repair Taps, Check Health, Scan for Vulnerabilities, Upgrade, and Uninstall, or the command to
- run in Terminal for a cask that asks for an administrator's password. Uninstall and the cleanups delete for good,
- as Homebrew does, and Peel says so before you confirm them. For a cask whose app Peel leaves alone on the app's own
- page, such as one with a system extension, and for a package you excluded, Uninstall stays off, with the reason
- beside it. A cask Homebrew still lists though what it installed is gone, its app or, for a cask with no app, its
+- **Homebrew:** your formulae and casks, with Update, Clean Up (and two deeper ones: downloads older than 30 days, or
+ every download), Repair Taps, Check Health, Scan for Vulnerabilities, Upgrade, and Uninstall, or the command to run in
+ Terminal for a cask that asks for an administrator's password. Uninstall and the cleanups delete for good, as Homebrew
+ does, and Peel says so before you confirm them. For a cask whose app Peel leaves alone on the app's own page, such as
+ one with a system extension, and for a package you excluded, Uninstall stays off, with the reason beside it. Homebrew
+ replaces or deletes a cask's app even while it runs, so Peel asks the app to quit first, and opens it again after an
+ upgrade. A cask Homebrew still lists though what it installed is gone, its app or, for a cask with no app, its
packages, can't be upgraded. It is listed apart under Apps Already Gone, where Forget Cask, or Forget All for every
one of them, moves Homebrew's record of it to the Trash, with the links Homebrew made into it, so Homebrew stops
listing it, and History can put it back.
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 6d194ef5..d044d558 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -51874,6 +51874,112 @@
}
}
},
+ "Homebrew deletes what it uninstalls, even while it runs, so Peel quits it first." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew smaže, co odinstaluje, i když aplikace běží, a proto ji Peel nejprve ukončí."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew löscht, was es deinstalliert, auch während die App läuft, daher beendet Peel sie zuerst."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew borra lo que desinstala aunque esté en ejecución, así que Peel cierra la app primero."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew supprime définitivement ce qu’il désinstalle, même si l’app est en cours d’exécution : Peel la quitte donc d’abord."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew elimina ciò che disinstalla, anche mentre l’app è in esecuzione, quindi Peel prima la chiude."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrewは、アンインストールするものを実行中であっても削除するため、Peelは先にそのアプリを終了します。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew는 앱이 실행 중이더라도 제거하는 항목을 삭제하므로, Peel이 먼저 앱을 종료합니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew verwijdert definitief wat het deïnstalleert, zelfs terwijl de app actief is, dus Peel stopt de app eerst."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew trwale usuwa to, co odinstalowuje, nawet gdy aplikacja działa, więc Peel najpierw ją zakończy."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Homebrew apaga o que desinstala, mesmo com o app em execução, então o Peel encerra o app primeiro."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew șterge aplicațiile pe care le dezinstalează, chiar dacă rulează, așa că Peel le închide mai întâi."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew удаляет приложение безвозвратно, даже если оно запущено, поэтому Peel сначала завершает его."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew raderar det som avinstalleras, även medan appen är igång, så Peel avslutar den först."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew, yüklemesini kaldırdığı şeyi uygulama çalışırken bile siler, bu yüzden Peel önce uygulamadan çıkar."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew видаляє те, що деінсталює, навіть якщо програма працює, тож Peel спершу її завершує."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew会删除它卸载的内容,即使该App正在运行也是如此,因此Peel会先退出该App。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew會刪除它解除安裝的項目,即使App正在執行也一樣,因此Peel會先結束該App。"
+ }
+ }
+ }
+ },
"Homebrew deprecates a package it means to stop offering, and disables it when it stops. A disabled package can’t be installed again and gets no more upgrades. What is installed stays until you uninstall it." : {
"localizations" : {
"cs" : {
@@ -54418,6 +54524,112 @@
}
}
},
+ "Homebrew replaces what it upgrades, even while it runs, so Peel quits it first and opens it again once Homebrew is done." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew nahradí, co upgraduje, i když aplikace běží, a proto ji Peel nejprve ukončí a znovu ji otevře, až Homebrew skončí."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew ersetzt, wofür es ein Upgrade ausführt, auch während die App läuft, daher beendet Peel sie zuerst und öffnet sie wieder, sobald Homebrew fertig ist."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew reemplaza lo que actualiza aunque esté en ejecución, así que Peel cierra la app primero y vuelve a abrirla cuando Homebrew termine."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew remplace ce qu’il met à niveau, même si l’app est en cours d’exécution : Peel la quitte donc d’abord, puis la rouvre une fois que Homebrew a terminé."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew sostituisce ciò che aggiorna, anche mentre l’app è in esecuzione, quindi Peel prima la chiude e poi la riapre quando Homebrew ha finito."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrewは、アップグレードするものを実行中であっても置き換えるため、Peelは先にそのアプリを終了し、Homebrewの処理が終わったらもう一度開きます。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew는 앱이 실행 중이더라도 업그레이드하는 항목을 대치하므로, Peel이 먼저 앱을 종료하고 Homebrew가 작업을 마치면 다시 엽니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew vervangt wat het upgradet, zelfs terwijl de app actief is, dus Peel stopt de app eerst en opent die weer zodra Homebrew klaar is."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew zastępuje to, co uaktualnia, nawet gdy aplikacja działa, więc Peel najpierw ją zakończy, a gdy Homebrew skończy, otworzy ją ponownie."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ao fazer upgrade, o Homebrew substitui o que está instalado, mesmo com o app em execução, então o Peel encerra o app primeiro e o abre novamente quando o Homebrew terminar."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew înlocuiește aplicațiile cărora le face upgrade, chiar dacă rulează, așa că Peel le închide mai întâi și le deschide din nou după ce Homebrew termină."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew заменяет обновляемое приложение, даже если оно запущено, поэтому Peel сначала завершает его, а когда Homebrew закончит, снова открывает."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew ersätter det som uppgraderas, även medan appen är igång, så Peel avslutar den först och öppnar den igen när Homebrew är klart."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew, yükselttiği şeyi uygulama çalışırken bile yenisiyle değiştirir, bu yüzden Peel önce uygulamadan çıkar ve Homebrew işini bitirdiğinde onu yeniden açar."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew замінює те, що оновлює, навіть якщо програма працює, тож Peel спершу її завершує, а коли Homebrew закінчить, відкриває знову."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew会替换它升级的内容,即使该App正在运行也是如此,因此Peel会先退出该App,并在Homebrew完成后再次打开它。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew會取代它升級的項目,即使App正在執行也一樣,因此Peel會先結束該App,並在Homebrew完成後再次打開它。"
+ }
+ }
+ }
+ },
"Homebrew sends its makers analytics whenever Peel runs it." : {
"localizations" : {
"cs" : {
@@ -129788,6 +130000,218 @@
}
}
},
+ "Quit %@ before uninstalling." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Před odinstalací aplikaci %@ ukončete."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Beende „%@“ vor dem Deinstallieren."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Sal de %@ antes de la desinstalación."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Quittez %@ avant la désinstallation."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Esci da %@ prima della disinstallazione."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "アンインストールする前に、%@を終了してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "제거하기 전에 ‘%@’을(를) 종료하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Stop %@ vóór het deïnstalleren."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zakończ %@ przed odinstalowaniem."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Encerre %@ antes de desinstalar."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Închideți %@ înainte de dezinstalare."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Завершите %@ перед удалением."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Avsluta %@ före avinstallationen."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Yüklemeyi kaldırmadan önce çıkın: %@."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Завершіть програму «%@», перш ніж деінсталювати її."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "请先退出“%@”,再进行卸载。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "解除安裝前,請先結束%@。"
+ }
+ }
+ }
+ },
+ "Quit %@ before upgrading." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Před upgradem aplikaci %@ ukončete."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Beende „%@“ vor dem Upgrade."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Sal de %@ antes de la actualización."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Quittez %@ avant la mise à niveau."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Esci da %@ prima dell’aggiornamento."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "アップグレードする前に、%@を終了してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "업그레이드하기 전에 ‘%@’을(를) 종료하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Stop %@ vóór het upgraden."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zakończ %@ przed uaktualnieniem."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Encerre %@ antes de fazer upgrade."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Închideți %@ înainte de upgrade."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Завершите %@ перед обновлением."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Avsluta %@ före uppgraderingen."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Yükseltmeden önce çıkın: %@."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Завершіть програму «%@», перш ніж оновлювати її."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "请先退出“%@”,再进行升级。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "升級前,請先結束%@。"
+ }
+ }
+ }
+ },
"Quit %@ first, or it can write its own settings over these." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/RunningCopies.swift b/Packages/PeelCore/Sources/PeelCore/Apps/RunningCopies.swift
index 61dad78e..f9ed56f6 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/RunningCopies.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/RunningCopies.swift
@@ -73,4 +73,20 @@ public enum RunningCopies {
}
}
}
+
+ /// Returns the processes in `running` that a Homebrew command on `cask` would replace or delete from under them:
+ /// those of its apps, as `belonging(to:)` finds them, and those its definition names to quit.
+ public static func belonging(
+ toCask cask: HomebrewPackage,
+ apps: [InstalledApp],
+ among running: [Process],
+ installedApps: [InstalledApp]
+ ) -> [Process] {
+ let named = Set(cask.quitIdentifiers.map { $0.lowercased() })
+ let own = Set(apps.flatMap { belonging(to: $0, among: running, installedApps: installedApps) })
+ return running.filter { process in
+ own.contains(process)
+ || (process.mayBeQuit && process.bundleIdentifier.map { named.contains($0.lowercased()) } == true)
+ }
+ }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RunningCopiesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RunningCopiesTests.swift
index 019f27bb..0b3b8131 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/RunningCopiesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/RunningCopiesTests.swift
@@ -24,6 +24,23 @@ struct RunningCopiesTests {
.compactMap(\.bundleIdentifier)
}
+ @Test func aCasksAppsAndWhatItNamesToQuitAreQuitFirst() {
+ let cask = HomebrewPackage(name: "google-chrome", kind: .cask, quitIdentifiers: ["org.example.Updater"])
+ let running = [
+ process("com.google.Chrome", at: "/Applications/Google Chrome.app", pid: 1),
+ process("com.google.Chrome.helper", at: "/Applications/Google Chrome.app/Contents/Frameworks/Helper.app", pid: 2),
+ process("org.example.updater", at: "/Library/Example/Updater.app", pid: 3),
+ process("com.google.Chrome.canary", at: "/Applications/Google Chrome Canary.app", pid: 4),
+ RunningCopies.Process(identifier: 5, bundleIdentifier: "org.example.Updater", bundleURL: nil, mayBeQuit: false),
+ ]
+
+ let quit = RunningCopies.belonging(
+ toCask: cask, apps: [chrome], among: running, installedApps: [chrome, canary]
+ )
+
+ #expect(quit.map(\.identifier) == [1, 2, 3])
+ }
+
/// What runs from inside the app counts whatever its name begins with. A slash and a combining mark after it
/// are one `Character`, so to a comparison of characters a helper named that way ran from nowhere, and the
/// app's files could move while it ran.
diff --git a/Peel/Model/QuitBeforeHomebrew.swift b/Peel/Model/QuitBeforeHomebrew.swift
new file mode 100644
index 00000000..f9e3754e
--- /dev/null
+++ b/Peel/Model/QuitBeforeHomebrew.swift
@@ -0,0 +1,37 @@
+import AppKit
+import PeelCore
+
+/// What a Homebrew command on some casks quits first: Homebrew replaces or deletes a cask's app from under it, and
+/// quits it only when the cask asks, through Apple events Peel isn't allowed to send. The apps it quits open again
+/// once an upgrade is done, as Homebrew opens again what it quits itself.
+struct QuitBeforeHomebrew {
+ let processes: [NSRunningApplication]
+ let reopening: [URL]
+
+ @MainActor
+ init(_ packages: [HomebrewPackage], library: AppLibrary) {
+ let running = RunningCopies.current
+ var seen: Set<pid_t> = []
+ var reopening: [URL] = []
+ var processes: [RunningCopies.Process] = []
+ for cask in packages where cask.kind == .cask {
+ let apps = library.apps.filter { library.cask(for: $0)?.id == cask.id }
+ processes += RunningCopies.belonging(
+ toCask: cask, apps: apps, among: running, installedApps: library.apps
+ ).filter { seen.insert($0.identifier).inserted }
+ reopening += apps.map(\.url).filter { url in
+ running.contains { $0.bundleURL.map(PathPattern.comparablePath) == PathPattern.comparablePath(of: url) }
+ }
+ }
+ self.processes = processes.compactMap { NSRunningApplication(processIdentifier: $0.identifier) }
+ self.reopening = reopening
+ }
+
+ func reopen() {
+ let configuration = NSWorkspace.OpenConfiguration()
+ configuration.activates = false
+ for url in reopening where !url.isMissing {
+ NSWorkspace.shared.openApplication(at: url, configuration: configuration)
+ }
+ }
+}
diff --git a/Peel/Model/QuitBeforeRemoving.swift b/Peel/Model/QuitBeforeRemoving.swift
index dcf98774..165360fa 100644
--- a/Peel/Model/QuitBeforeRemoving.swift
+++ b/Peel/Model/QuitBeforeRemoving.swift
@@ -2,9 +2,10 @@ import AppKit
import Observation
import PeelCore
-/// The processes a removal waits for, since files never move out from under a running app. It asks them to quit,
-/// follows them until none runs, and then goes on with the removal. One still open after a while may be waiting for
-/// the person, to save their work for example, so forcing it is offered, never done unasked.
+/// The processes a removal, or a Homebrew command that replaces or deletes an app, waits for, since nothing leaves
+/// from under a running app. It asks them to quit, follows them until none runs, and then goes on. One still open
+/// after a while may be waiting for the person, to save their work for example, so forcing it is offered, never done
+/// unasked.
@Observable
final class QuitBeforeRemoving {
/// The processes the alerts name.
diff --git a/Peel/Views/AppPageHeader.swift b/Peel/Views/AppPageHeader.swift
index 45555201..c4b59e83 100644
--- a/Peel/Views/AppPageHeader.swift
+++ b/Peel/Views/AppPageHeader.swift
@@ -13,6 +13,7 @@ struct AppPageHeader: View {
@Binding var isShowingReset: Bool
@Binding var isConfirmingPrivacyReset: Bool
@Binding var upgradeOutput: HomebrewLibrary.CommandResult?
+ @State private var quitting = QuitBeforeRemoving()
var body: some View {
AppHeader(
@@ -27,6 +28,7 @@ struct AppPageHeader: View {
) {
appActions
}
+ .quitBeforeHomebrew(quitting, upgrading: true)
}
/// The version an update would bring. Nil when there is no update, or when the user muted this app or
@@ -163,7 +165,7 @@ struct AppPageHeader: View {
}
case .homebrew:
Button {
- Task { await upgradeWithHomebrew() }
+ upgradeWithHomebrew()
} label: {
if isUpgrading {
HStack(spacing: 6) {
@@ -176,7 +178,7 @@ struct AppPageHeader: View {
}
}
.buttonStyle(.borderedProminent)
- .disabled(homebrew.runningCommand != nil)
+ .disabled(homebrew.runningCommand != nil || quitting.isWaiting)
case .developer, .automatic:
Button("Open \(plan.app.name)", systemImage: "arrow.up.forward.app") {
NSWorkspace.shared.open(plan.app.url)
@@ -190,10 +192,20 @@ struct AppPageHeader: View {
return homebrew.runningCommand == .upgrade(cask.id)
}
+ private func upgradeWithHomebrew() {
+ guard let cask = library.cask(for: plan.app) else { return }
+ let quit = QuitBeforeHomebrew([cask], library: library)
+ quitting.check(quit.processes) {
+ Task {
+ await upgrade(cask)
+ quit.reopen()
+ }
+ }
+ }
+
/// Upgrades the app with Homebrew, which can take a while. The button shows progress while it runs, the
/// line under it shows the result, and a notification reports it too, in case the user has moved on.
- private func upgradeWithHomebrew() async {
- guard let cask = library.cask(for: plan.app) else { return }
+ private func upgrade(_ cask: HomebrewPackage) async {
let app = plan.app
library.record(nil, of: app)
// Nil when Homebrew is already running a command. The button is disabled then, so this is only a safeguard.
diff --git a/Peel/Views/Homebrew/HomebrewDetailView.swift b/Peel/Views/Homebrew/HomebrewDetailView.swift
index c386a48f..a2767053 100644
--- a/Peel/Views/Homebrew/HomebrewDetailView.swift
+++ b/Peel/Views/Homebrew/HomebrewDetailView.swift
@@ -8,6 +8,8 @@ struct HomebrewDetailView: View {
@Environment(RemovalHistoryStore.self) private var history
@State private var isConfirmingUninstall = false
@State private var isConfirmingUpgrade = false
+ @State private var quittingToUpgrade = QuitBeforeRemoving()
+ @State private var quittingToUninstall = QuitBeforeRemoving()
@State private var casksToForget: [HomebrewPackage]?
/// What macOS said of the system extensions the cask's apps carry, with the apps it was asked about.
@State private var extensionsAnswer: (apps: [URL], removedElsewhere: RemovedElsewhere?)?
@@ -145,7 +147,10 @@ struct HomebrewDetailView: View {
.disabled(uninstallRefusal != nil)
}
}
- .disabled(homebrew.runningCommand != nil || homebrew.isForgetting)
+ .disabled(
+ homebrew.runningCommand != nil || homebrew.isForgetting || quittingToUpgrade.isWaiting
+ || quittingToUninstall.isWaiting
+ )
if package.waitsForAnUpgrade, homebrew.overrides.contains(.cleansUp) {
Text(HomebrewLibrary.cleansUp)
.font(.callout)
@@ -175,7 +180,7 @@ struct HomebrewDetailView: View {
.toolbar(removing: .title)
// Asked first, as Upgrade All is: an upgrade can run for a long time while Homebrew builds on this Mac.
.confirmationDialog("Upgrade \(package.name)?", isPresented: $isConfirmingUpgrade) {
- Button("Upgrade") { Task { await homebrew.run(.upgrade(package.id)) } }
+ Button("Upgrade") { upgrade() }
Button("Cancel", role: .cancel) {}
} message: {
Text("This can take a long time, since Homebrew builds some packages on this Mac. Its progress shows on this page as it works, and you can stop it there.")
@@ -191,12 +196,33 @@ struct HomebrewDetailView: View {
Button("Uninstall", role: .destructive) {
// Checks again, since the exclusions can change while the dialog is open.
guard uninstallRefusal == nil else { return }
- Task { await homebrew.run(.uninstall(package.id)) }
+ uninstall()
}
Button("Cancel", role: .cancel) {}
} message: {
Text("Homebrew deletes the package for good: nothing goes to the Trash, and History can’t put it back. It won’t do this while another package needs it, and it also removes every formula nothing needs anymore, whichever package brought it in.")
}
+ .quitBeforeHomebrew(quittingToUpgrade, upgrading: true)
+ .quitBeforeHomebrew(quittingToUninstall, upgrading: false)
+ }
+
+ private func upgrade() {
+ let quit = QuitBeforeHomebrew([package], library: library)
+ quittingToUpgrade.check(quit.processes) {
+ Task {
+ await homebrew.run(.upgrade(package.id))
+ quit.reopen()
+ }
+ }
+ }
+
+ private func uninstall() {
+ let quit = QuitBeforeHomebrew([package], library: library)
+ quittingToUninstall.check(quit.processes) {
+ // Asked again once its apps have quit, since the exclusions can change meanwhile.
+ guard uninstallRefusal == nil else { return }
+ Task { await homebrew.run(.uninstall(package.id)) }
+ }
}
private var advisory: HomebrewAdvisory? {
diff --git a/Peel/Views/Homebrew/HomebrewList.swift b/Peel/Views/Homebrew/HomebrewList.swift
index 8f56faea..025b94d8 100644
--- a/Peel/Views/Homebrew/HomebrewList.swift
+++ b/Peel/Views/Homebrew/HomebrewList.swift
@@ -3,6 +3,7 @@ import SwiftUI
struct HomebrewList: View {
@Environment(HomebrewLibrary.self) private var homebrew
+ @Environment(AppLibrary.self) private var library
@Environment(RemovalHistoryStore.self) private var history
@Environment(\.openSettings) private var openSettings
@State private var searchText = ""
@@ -11,6 +12,7 @@ struct HomebrewList: View {
/// One of the deeper clean ups, or the repair, waiting for its confirmation.
@State private var confirming: HomebrewLibrary.Command?
@State private var isConfirmingUpgradeAll = false
+ @State private var quittingToUpgrade = QuitBeforeRemoving()
@State private var casksToForget: [HomebrewPackage]?
var body: some View {
@@ -69,12 +71,13 @@ struct HomebrewList: View {
Text(verbatim: String(inflecting: "Upgrade ^[\(homebrew.upgradable.count) package](inflect: true)?")),
isPresented: $isConfirmingUpgradeAll
) {
- Button("Upgrade All") { start(.upgradeAll) }
+ Button("Upgrade All") { upgradeAll() }
Button("Cancel", role: .cancel) {}
} message: {
Text("This can take a long time, since Homebrew builds some packages on this Mac. Its progress shows on this page as it works, and you can stop it there.")
}
.forgetCasksDialog(for: $casksToForget)
+ .quitBeforeHomebrew(quittingToUpgrade, upgrading: true)
// Clean Up is confirmed first, like Uninstall on a package's page, because Homebrew deletes these files
// permanently and History can't put them back.
.confirmationDialog("Clean up Homebrew?", isPresented: $isConfirmingCleanUp) {
@@ -422,7 +425,7 @@ struct HomebrewList: View {
.minimumTarget()
}
.buttonStyle(.borderless)
- .disabled(homebrew.upgradable.isEmpty || isBusy)
+ .disabled(homebrew.upgradable.isEmpty || isBusy || quittingToUpgrade.isWaiting)
}
}
}
@@ -562,6 +565,16 @@ struct HomebrewList: View {
Task { await homebrew.run(command) }
}
+ private func upgradeAll() {
+ let quit = QuitBeforeHomebrew(homebrew.upgradable, library: library)
+ quittingToUpgrade.check(quit.processes) {
+ Task {
+ await homebrew.run(.upgradeAll)
+ quit.reopen()
+ }
+ }
+ }
+
private var isBusy: Bool {
homebrew.runningCommand != nil || homebrew.isForgetting || homebrew.isScanning
}
diff --git a/Peel/Views/Homebrew/QuitBeforeHomebrewAlert.swift b/Peel/Views/Homebrew/QuitBeforeHomebrewAlert.swift
new file mode 100644
index 00000000..f6c44823
--- /dev/null
+++ b/Peel/Views/Homebrew/QuitBeforeHomebrewAlert.swift
@@ -0,0 +1,21 @@
+import SwiftUI
+
+extension View {
+ /// The alerts that quit a cask's apps before Homebrew upgrades or uninstalls it, as an app's page does before a
+ /// removal.
+ func quitBeforeHomebrew(_ quitting: QuitBeforeRemoving, upgrading: Bool) -> some View {
+ alert(
+ upgrading ? Text("Quit \(quitting.names) before upgrading.") : Text("Quit \(quitting.names) before uninstalling."),
+ isPresented: Bindable(quitting).isAsking
+ ) {
+ Button("Quit \(quitting.names)") { quitting.quit() }
+ Button("Cancel", role: .cancel) { quitting.giveUp() }
+ } message: {
+ upgrading
+ ? Text("Homebrew replaces what it upgrades, even while it runs, so Peel quits it first and opens it again once Homebrew is done.")
+ : Text("Homebrew deletes what it uninstalls, even while it runs, so Peel quits it first.")
+ }
+ .forceQuitOffer(quitting)
+ .onDisappear { quitting.giveUp() }
+ }
+}