mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-22 19:58:37 +00:00
refactor(macos): dedupe UI, pairing, and runtime helpers
This commit is contained in:
46
apps/macos/Sources/OpenClaw/MicRefreshSupport.swift
Normal file
46
apps/macos/Sources/OpenClaw/MicRefreshSupport.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
enum MicRefreshSupport {
|
||||
private static let refreshDelayNs: UInt64 = 300_000_000
|
||||
|
||||
static func startObserver(_ observer: AudioInputDeviceObserver, triggerRefresh: @escaping @MainActor () -> Void) {
|
||||
observer.start {
|
||||
Task { @MainActor in
|
||||
triggerRefresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
static func schedule(
|
||||
refreshTask: inout Task<Void, Never>?,
|
||||
action: @escaping @MainActor () async -> Void)
|
||||
{
|
||||
refreshTask?.cancel()
|
||||
refreshTask = Task { @MainActor in
|
||||
try? await Task.sleep(nanoseconds: self.refreshDelayNs)
|
||||
guard !Task.isCancelled else { return }
|
||||
await action()
|
||||
}
|
||||
}
|
||||
|
||||
static func selectedMicName<T>(
|
||||
selectedID: String,
|
||||
in devices: [T],
|
||||
uid: KeyPath<T, String>,
|
||||
name: KeyPath<T, String>) -> String
|
||||
{
|
||||
guard !selectedID.isEmpty else { return "" }
|
||||
return devices.first(where: { $0[keyPath: uid] == selectedID })?[keyPath: name] ?? ""
|
||||
}
|
||||
|
||||
@MainActor
|
||||
static func voiceWakeBinding(for state: AppState) -> Binding<Bool> {
|
||||
Binding(
|
||||
get: { state.swabbleEnabled },
|
||||
set: { newValue in
|
||||
Task { await state.setVoiceWakeEnabled(newValue) }
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user