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.

End the wait for the helper on time on a busy Mac

Țugui Dragoș4b1e6dd8aa7b
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift b/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift
index 29c08a5b..03754ba4 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift
@@ -149,6 +149,9 @@ public enum PrivilegedHelper {
/// How long the helper is waited for before the request counts as unanswered.
private static let longestWait: TimeInterval = 120
+ /// At utility quality these timers would wait behind any utility work queued before them.
+ static let timers = DispatchQueue.global(qos: .userInitiated)
+
@concurrent
public static func moveToTrash(_ urls: [URL]) async -> TrashResult {
var result = TrashResult()
@@ -301,7 +304,7 @@ public enum PrivilegedHelper {
// A helper that is running but never answers keeps the connection valid, so only this timer ends
// the wait. `longestWait` outlasts any request: at most `HelperRequest.maximumItems` renames, or one
// `launchctl` run that the helper stops after 30 seconds.
- DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + longestWait) { finish(fallback) }
+ timers.asyncAfter(deadline: .now() + longestWait) { finish(fallback) }
guard
let helper = connection.remoteObjectProxyWithErrorHandler({ _ in finish(fallback) })
as? any PeelHelperProtocol
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HelperAnswerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HelperAnswerTests.swift
new file mode 100644
index 00000000..6fabb1bb
--- /dev/null
+++ b/Packages/PeelCore/Tests/PeelCoreTests/HelperAnswerTests.swift
@@ -0,0 +1,9 @@
+import Foundation
+@testable import PeelCore
+import Testing
+
+struct HelperAnswerTests {
+ @Test func theTimerThatEndsAWaitForTheHelperNeverWaitsBehindWorkOfLowerQuality() {
+ #expect(PrivilegedHelper.timers.label == DispatchQueue.global(qos: .userInitiated).label)
+ }
+}