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.

Don't give up an upgrade when the page changes while apps quit

Țugui Dragoșba624d1ea185
diff --git a/Peel/Model/HomebrewLibrary.swift b/Peel/Model/HomebrewLibrary.swift
index 08593903..2bbac231 100644
--- a/Peel/Model/HomebrewLibrary.swift
+++ b/Peel/Model/HomebrewLibrary.swift
@@ -16,6 +16,10 @@ final class HomebrewLibrary {
/// through an upgrade, but their versions change.
private(set) var revision = 0
@ObservationIgnored private let appsOfCask: (HomebrewPackage) -> [InstalledApp]
+ /// Waiting for a cask's apps to quit before Homebrew changes them. These are the library's, not a page's: choosing
+ /// another row builds another page, and the command the person asked for still has to run.
+ let quittingToUpgrade = QuitBeforeRemoving()
+ let quittingToUninstall = QuitBeforeRemoving()
init(appsOfCask: @escaping (HomebrewPackage) -> [InstalledApp] = { _ in [] }) {
self.appsOfCask = appsOfCask
diff --git a/Peel/Views/AppDetailView.swift b/Peel/Views/AppDetailView.swift
index b0b31981..9284e718 100644
--- a/Peel/Views/AppDetailView.swift
+++ b/Peel/Views/AppDetailView.swift
@@ -9,7 +9,6 @@ struct AppDetailView: View {
@Environment(HomebrewLibrary.self) private var homebrew
@State private var plan: RemovalPlan
@State private var quitting = QuitBeforeRemoving()
- @State private var quittingToUpgrade = QuitBeforeRemoving()
@Environment(RemovalOutcome.self) private var outcome
@State private var isRescanning = false
@State private var progress = MoveProgress()
@@ -63,7 +62,6 @@ struct AppDetailView: View {
}
.forceQuitOffer(quitting)
.onDisappear { quitting.giveUp() }
- .quitBeforeHomebrew(quittingToUpgrade, upgrading: true)
.sheet(isPresented: $isShowingReset, onDismiss: {
guard resetChangedFiles else { return }
resetChangedFiles = false
@@ -114,8 +112,7 @@ struct AppDetailView: View {
upgradeOutput: $upgradeOutput,
receiptToForget: $receiptToForget,
isForgettingReceipt: isForgettingReceipt,
- isRemoving: plan.isRemoving || quitting.isWaiting,
- quittingToUpgrade: quittingToUpgrade
+ isRemoving: plan.isRemoving || quitting.isWaiting
)
.listRowSeparator(.hidden)
diff --git a/Peel/Views/AppPageHeader.swift b/Peel/Views/AppPageHeader.swift
index ba435eac..83b04e09 100644
--- a/Peel/Views/AppPageHeader.swift
+++ b/Peel/Views/AppPageHeader.swift
@@ -19,9 +19,6 @@ struct AppPageHeader: View {
let isForgettingReceipt: Bool
/// True while the page removes the app or waits for it to quit first, when nothing else is started from here.
let isRemoving: Bool
- /// Asks the app to quit before Homebrew upgrades it. The page owns it and shows its questions, since a List
- /// takes this header away when it is scrolled out of view, and that would end the wait.
- let quittingToUpgrade: QuitBeforeRemoving
var body: some View {
VStack(alignment: .leading, spacing: 16) {
@@ -225,7 +222,7 @@ struct AppPageHeader: View {
}
}
.buttonStyle(.borderedProminent)
- .disabled(homebrew.runningCommand != nil || quittingToUpgrade.isWaiting)
+ .disabled(homebrew.runningCommand != nil || homebrew.quittingToUpgrade.isWaiting)
case .developer, .automatic:
Button("Open \(plan.app.name)", systemImage: "arrow.up.forward.app") {
NSWorkspace.shared.open(plan.app.url)
@@ -242,7 +239,7 @@ struct AppPageHeader: View {
private func upgradeWithHomebrew() {
guard let cask = library.cask(for: plan.app) else { return }
let quit = QuitBeforeHomebrew([cask], library: library)
- quittingToUpgrade.check(quit.processes) {
+ homebrew.quittingToUpgrade.check(quit.processes) {
// Asked again once its apps have quit, since the exclusions can change meanwhile.
guard upgradeRefusal == nil else { return }
Task {
diff --git a/Peel/Views/ContentView.swift b/Peel/Views/ContentView.swift
index b25458b4..994acac7 100644
--- a/Peel/Views/ContentView.swift
+++ b/Peel/Views/ContentView.swift
@@ -142,6 +142,8 @@ struct ContentView: View {
.clearTitleBar()
.measuresFrames()
.focusedSceneValue(\.selectedTool, shownTool)
+ .quitBeforeHomebrew(homebrew.quittingToUpgrade, upgrading: true)
+ .quitBeforeHomebrew(homebrew.quittingToUninstall, upgrading: false)
// The page changes only for a bundle that is an app, since any app or web page can send the link.
.onOpenURL { url in
guard let applicationURL = OpenRequest.applicationURL(from: url) else { return }
diff --git a/Peel/Views/Homebrew/HomebrewDetailView.swift b/Peel/Views/Homebrew/HomebrewDetailView.swift
index 5c1424a6..566a58ea 100644
--- a/Peel/Views/Homebrew/HomebrewDetailView.swift
+++ b/Peel/Views/Homebrew/HomebrewDetailView.swift
@@ -9,8 +9,6 @@ struct HomebrewDetailView: View {
@Environment(PeelUpdater.self) private var updater
@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?)?
@@ -187,8 +185,8 @@ struct HomebrewDetailView: View {
}
}
.disabled(
- homebrew.runningCommand != nil || homebrew.isForgetting || quittingToUpgrade.isWaiting
- || quittingToUninstall.isWaiting
+ homebrew.runningCommand != nil || homebrew.isForgetting || homebrew.quittingToUpgrade.isWaiting
+ || homebrew.quittingToUninstall.isWaiting
)
if package.waitsForAnUpgrade, package.isPeelItself {
Text("Peel updates itself, so it isn’t upgraded from here: Homebrew would have to quit Peel first.")
@@ -252,13 +250,11 @@ struct HomebrewDetailView: View {
} 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) {
+ homebrew.quittingToUpgrade.check(quit.processes) {
// Asked again once its apps have quit, since the exclusions can change meanwhile.
guard upgradeRefusal == nil else { return }
Task {
@@ -270,7 +266,7 @@ struct HomebrewDetailView: View {
private func uninstall() {
let quit = QuitBeforeHomebrew([package], library: library)
- quittingToUninstall.check(quit.processes) {
+ homebrew.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)) }
diff --git a/Peel/Views/Homebrew/HomebrewList.swift b/Peel/Views/Homebrew/HomebrewList.swift
index 21a3d1c8..ab637aa8 100644
--- a/Peel/Views/Homebrew/HomebrewList.swift
+++ b/Peel/Views/Homebrew/HomebrewList.swift
@@ -12,7 +12,6 @@ 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 {
@@ -104,7 +103,6 @@ struct HomebrewList: View {
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) {
@@ -534,7 +532,8 @@ struct HomebrewList: View {
}
.buttonStyle(.borderless)
.disabled(
- homebrew.upgradable.isEmpty || isBusy || quittingToUpgrade.isWaiting || !homebrew.mayChange
+ homebrew.upgradable.isEmpty || isBusy || homebrew.quittingToUpgrade.isWaiting
+ || !homebrew.mayChange
|| homebrew.upgradable.contains { $0.kind == .cask } && !library.knowsHomebrewsApps
)
}
@@ -679,7 +678,7 @@ struct HomebrewList: View {
private func upgradeAll() {
let quit = QuitBeforeHomebrew(homebrew.upgradable, library: library)
- quittingToUpgrade.check(quit.processes) {
+ homebrew.quittingToUpgrade.check(quit.processes) {
Task {
await homebrew.run(.upgradeAll)
quit.reopen()
diff --git a/Peel/Views/Homebrew/QuitBeforeHomebrewAlert.swift b/Peel/Views/Homebrew/QuitBeforeHomebrewAlert.swift
index f6c44823..b476d313 100644
--- a/Peel/Views/Homebrew/QuitBeforeHomebrewAlert.swift
+++ b/Peel/Views/Homebrew/QuitBeforeHomebrewAlert.swift
@@ -16,6 +16,5 @@ extension View {
: Text("Homebrew deletes what it uninstalls, even while it runs, so Peel quits it first.")
}
.forceQuitOffer(quitting)
- .onDisappear { quitting.giveUp() }
}
}