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
Show nothing about the helper while it is being changed
Țugui Dragoșa055df48d2aa
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/OverlappingChecks.swift b/Packages/PeelCore/Sources/PeelCore/Support/OverlappingChecks.swiftindex 97eb52a6..e9f78374 100644--- a/Packages/PeelCore/Sources/PeelCore/Support/OverlappingChecks.swift+++ b/Packages/PeelCore/Sources/PeelCore/Support/OverlappingChecks.swift@@ -1,6 +1,7 @@/// Which of several overlapping checks of one thing may show its answer: each one as soon as it ends, unless a check/// that started after it has shown its own, or the thing changed after it started. Waiting for the newest check alone-/// shows nothing for as long as each check outlasts the start of the next.+/// shows nothing for as long as each check outlasts the start of the next. While the thing changes, what a check finds+/// is neither the old thing nor the new one, so nothing shows until the change ends.public struct OverlappingChecks: Sendable {public struct Check: Sendable {fileprivate let number: Int@@ -10,6 +11,7 @@ public struct OverlappingChecks: Sendable {private var started = 0private var shown = 0private var changes = 0+ private var isChanging = falsepublic init() {}@@ -18,13 +20,17 @@ public struct OverlappingChecks: Sendable {return Check(number: started, change: changes)}- /// The thing checked changed, so no check started before now may show its answer.- public mutating func changed() {+ public mutating func changeStarts() {+ isChanging = true+ }++ public mutating func changeEnds() {changes += 1+ isChanging = false}public mutating func mayShow(_ check: Check) -> Bool {- guard check.change == changes, check.number > shown else { return false }+ guard !isChanging, check.change == changes, check.number > shown else { return false }shown = check.numberreturn true}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OverlappingChecksTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OverlappingChecksTests.swiftindex 471db852..dd7c6132 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OverlappingChecksTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OverlappingChecksTests.swift@@ -35,7 +35,8 @@ struct OverlappingChecksTests {@Test func aChangeLeavesOutWhatChecksStartedBeforeItFound() {var checks = OverlappingChecks()let before = checks.start()- checks.changed()+ checks.changeStarts()+ checks.changeEnds()var shows = [checks.mayShow(before)]let after = checks.start()@@ -44,6 +45,22 @@ struct OverlappingChecksTests {#expect(shows == [false, true])}+ /// What a check finds while the helper is being repaired is neither the old helper nor the new one.+ @Test func noAnswerShowsWhileAChangeRuns() {+ var checks = OverlappingChecks()+ let before = checks.start()+ checks.changeStarts()+ let during = checks.start()++ var shows = [checks.mayShow(during), checks.mayShow(before)]+ checks.changeEnds()+ shows.append(checks.mayShow(during))+ let after = checks.start()+ shows.append(checks.mayShow(after))++ #expect(shows == [false, false, false, true])+ }+/// Each check outlasts the start of the next, as Home's and Settings' did while the helper didn't answer.@Test func noAnswerWaitsForTheChecksToStopOverlapping() {var checks = OverlappingChecks()diff --git a/Peel/Model/HelperModel.swift b/Peel/Model/HelperModel.swiftindex d7170c16..42a3bdf1 100644--- a/Peel/Model/HelperModel.swift+++ b/Peel/Model/HelperModel.swift@@ -64,6 +64,7 @@ final class HelperModel {guard !isChanging else { return }isChanging = truedefer { isChanging = false }+ checks.changeStarts()do {try await PrivilegedHelper.register()} catch {@@ -72,7 +73,7 @@ final class HelperModel {failure = Failure(action: .install, reason: error.localizedDescription)}}- checks.changed()+ checks.changeEnds()refresh()if status == .requiresApproval {PrivilegedHelper.openLoginItemsSettings()@@ -83,12 +84,13 @@ final class HelperModel {guard !isChanging else { return }isChanging = truedefer { isChanging = false }+ checks.changeStarts()do {try await PrivilegedHelper.repair()} catch {failure = Failure(action: .repair, reason: error.localizedDescription)}- checks.changed()+ checks.changeEnds()refresh()if status == .requiresApproval {PrivilegedHelper.openLoginItemsSettings()@@ -97,14 +99,16 @@ final class HelperModel {}func uninstall() async {+ guard !isChanging else { return }isChanging = truedefer { isChanging = false }+ checks.changeStarts()do {try await PrivilegedHelper.unregister()} catch {failure = Failure(action: .uninstall, reason: error.localizedDescription)}- checks.changed()+ checks.changeEnds()refresh()}}