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
Open what an upgrade quit before Stop and Quit ends Peel
Țugui Dragoș1d45fb05a974
diff --git a/Peel/Model/HomebrewLibrary.swift b/Peel/Model/HomebrewLibrary.swiftindex 2bbac231..e396921c 100644--- a/Peel/Model/HomebrewLibrary.swift+++ b/Peel/Model/HomebrewLibrary.swift@@ -409,10 +409,13 @@ final class HomebrewLibrary {/// Runs `command` and returns its result to the caller. Only one command runs at a time: while one runs,/// this returns nil at once. `showsResult` is false for a page that shows the result itself, so the- /// Homebrew page opens no sheet about it later.+ /// Homebrew page opens no sheet about it later. `reopen` opens what was quit for the command as soon as it ends.@discardableResult- func run(_ command: Command, showsResult: Bool = true) async -> CommandResult? {- guard runningCommand == nil, !isForgetting, command.onlyLooks || mayChange else { return nil }+ func run(_ command: Command, showsResult: Bool = true, reopening reopen: () -> Void = {}) async -> CommandResult? {+ guard runningCommand == nil, !isForgetting, command.onlyLooks || mayChange else {+ reopen()+ return nil+ }runningCommand = commanddefer {(runningCommand, isReadingWhatChanged) = (nil, false)@@ -428,7 +431,12 @@ final class HomebrewLibrary {if command.onlyLooks {outcome = await task.value} else {- outcome = await QuitGuard.shared.run(stoppingWith: stop) { await task.value }+ // Inside the guard: a quit of Peel asked for meanwhile ends as soon as this does.+ outcome = await QuitGuard.shared.run(stoppingWith: stop) {+ let outcome = await task.value+ reopen()+ return outcome+ }}(runningTask, progress, isStopping) = (nil, nil, false)if showsResult, let outcome { result = outcome }diff --git a/Peel/Views/AppPageHeader.swift b/Peel/Views/AppPageHeader.swiftindex 83b04e09..d77df224 100644--- a/Peel/Views/AppPageHeader.swift+++ b/Peel/Views/AppPageHeader.swift@@ -242,20 +242,17 @@ struct AppPageHeader: View {homebrew.quittingToUpgrade.check(quit.processes) {// Asked again once its apps have quit, since the exclusions can change meanwhile.guard upgradeRefusal == nil else { return }- Task {- await upgrade(cask)- quit.reopen()- }+ Task { await upgrade(cask, reopening: 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 upgrade(_ cask: HomebrewPackage) async {+ private func upgrade(_ cask: HomebrewPackage, reopening reopen: () -> Void) async {let app = plan.applibrary.record(nil, of: app)// Nil when Homebrew is already running a command. The button is disabled then, so this is only a safeguard.- guard let result = await homebrew.run(.upgrade(cask.id), showsResult: false) else { return }+ guard let result = await homebrew.run(.upgrade(cask.id), showsResult: false, reopening: reopen) else { return }let succeeded = result.succeededupgradeOutput = succeeded ? nil : resultdiff --git a/Peel/Views/Homebrew/HomebrewDetailView.swift b/Peel/Views/Homebrew/HomebrewDetailView.swiftindex 566a58ea..29f6d8d8 100644--- a/Peel/Views/Homebrew/HomebrewDetailView.swift+++ b/Peel/Views/Homebrew/HomebrewDetailView.swift@@ -257,10 +257,7 @@ struct HomebrewDetailView: View {homebrew.quittingToUpgrade.check(quit.processes) {// Asked again once its apps have quit, since the exclusions can change meanwhile.guard upgradeRefusal == nil else { return }- Task {- await homebrew.run(.upgrade(package.id))- quit.reopen()- }+ Task { await homebrew.run(.upgrade(package.id), reopening: quit.reopen) }}}diff --git a/Peel/Views/Homebrew/HomebrewList.swift b/Peel/Views/Homebrew/HomebrewList.swiftindex ab637aa8..3d2fa760 100644--- a/Peel/Views/Homebrew/HomebrewList.swift+++ b/Peel/Views/Homebrew/HomebrewList.swift@@ -679,10 +679,7 @@ struct HomebrewList: View {private func upgradeAll() {let quit = QuitBeforeHomebrew(homebrew.upgradable, library: library)homebrew.quittingToUpgrade.check(quit.processes) {- Task {- await homebrew.run(.upgradeAll)- quit.reopen()- }+ Task { await homebrew.run(.upgradeAll, reopening: quit.reopen) }}}diff --git a/PeelTests/HomebrewLibraryTests.swift b/PeelTests/HomebrewLibraryTests.swiftindex 95ef0169..82f5793b 100644--- a/PeelTests/HomebrewLibraryTests.swift+++ b/PeelTests/HomebrewLibraryTests.swift@@ -42,6 +42,17 @@ import Testing#expect(homebrew.runningCommand == nil && !homebrew.isReadingWhatChanged && homebrew.progress == nil)}+ @Test func whatAnUpgradeQuitOpensAgainBeforeAQuitOfPeelCanEnd() async {+ guard Homebrew.executableURL != nil, await Homebrew.hasLocalDefinitions() else { return }+ // Nothing is read yet, so Upgrade All finds nothing to upgrade and runs no `brew upgrade`.+ let homebrew = HomebrewLibrary()+ var wasReading: Bool?++ await homebrew.run(.upgradeAll, showsResult: false, reopening: { wasReading = homebrew.isReadingWhatChanged })++ #expect(wasReading == false, "an answer to a quit goes out before Homebrew is read again")+ }+@Test func forgetsMovesEndBeforePeelReadsWhatChanged() async {guard Homebrew.executableURL != nil, await Homebrew.hasLocalDefinitions() else { return }let homebrew = HomebrewLibrary()