diff --git a/src/api-wrappers/HelperExtensions.swift b/src/api-wrappers/HelperExtensions.swift index a5ab3857..0e1c93cc 100644 --- a/src/api-wrappers/HelperExtensions.swift +++ b/src/api-wrappers/HelperExtensions.swift @@ -115,3 +115,15 @@ func assignIfDifferent(_ a: UnsafeMutablePointer, _ b: T) { a.pointee = b } } + +extension DispatchQoS { + func toQualityOfService() -> QualityOfService { + switch self { + case .userInteractive: return .userInteractive + case .userInitiated: return .userInitiated + case .utility: return .utility + case .background: return .background + default: return .default + } + } +} diff --git a/src/logic/BackgroundWork.swift b/src/logic/BackgroundWork.swift index a9ea0828..8aaf2f65 100644 --- a/src/logic/BackgroundWork.swift +++ b/src/logic/BackgroundWork.swift @@ -19,9 +19,9 @@ class BackgroundWork { accessibilityCommandsQueue = DispatchQueue.globalConcurrent("accessibilityCommandsQueue", .userInteractive) axCallsQueue = DispatchQueue.globalConcurrent("axCallsQueue", .userInteractive) crashReportsQueue = DispatchQueue.globalConcurrent("crashReportsQueue", .utility) - accessibilityEventsThread = BackgroundThreadWithRunLoop("accessibilityEventsThread") - keyboardEventsThread = BackgroundThreadWithRunLoop("keyboardEventsThread") - mouseEventsThread = BackgroundThreadWithRunLoop("mouseEventsThread") + accessibilityEventsThread = BackgroundThreadWithRunLoop("accessibilityEventsThread", .userInteractive) + keyboardEventsThread = BackgroundThreadWithRunLoop("keyboardEventsThread", .userInteractive) + mouseEventsThread = BackgroundThreadWithRunLoop("mouseEventsThread", .userInteractive) } } @@ -48,7 +48,7 @@ class BackgroundThreadWithRunLoop { var thread: Thread? var runLoop: CFRunLoop? - init(_ name: String) { + init(_ name: String, _ qos: DispatchQoS) { thread = Thread { self.runLoop = CFRunLoopGetCurrent() while !self.thread!.isCancelled { @@ -58,6 +58,7 @@ class BackgroundThreadWithRunLoop { } } thread!.name = name + thread!.qualityOfService = qos.toQualityOfService() thread!.start() } }