mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
feat(ios): add background listening core toggle (#18261)
Co-authored-by: Mariano Belinky <mariano@mb-server-643.local>
This commit is contained in:
@@ -114,6 +114,7 @@ final class NodeAppModel {
|
||||
private var talkVoiceWakeSuspended = false
|
||||
private var backgroundVoiceWakeSuspended = false
|
||||
private var backgroundTalkSuspended = false
|
||||
private var backgroundTalkKeptActive = false
|
||||
private var backgroundedAt: Date?
|
||||
private var reconnectAfterBackgroundArmed = false
|
||||
|
||||
@@ -269,15 +270,18 @@ final class NodeAppModel {
|
||||
|
||||
|
||||
func setScenePhase(_ phase: ScenePhase) {
|
||||
let keepTalkActive = UserDefaults.standard.bool(forKey: "talk.background.enabled")
|
||||
switch phase {
|
||||
case .background:
|
||||
self.isBackgrounded = true
|
||||
self.stopGatewayHealthMonitor()
|
||||
self.backgroundedAt = Date()
|
||||
self.reconnectAfterBackgroundArmed = true
|
||||
// Be conservative: release the mic when the app backgrounds.
|
||||
// Release voice wake mic in background.
|
||||
self.backgroundVoiceWakeSuspended = self.voiceWake.suspendForExternalAudioCapture()
|
||||
self.backgroundTalkSuspended = self.talkMode.suspendForBackground()
|
||||
let shouldKeepTalkActive = keepTalkActive && self.talkMode.isEnabled
|
||||
self.backgroundTalkKeptActive = shouldKeepTalkActive
|
||||
self.backgroundTalkSuspended = self.talkMode.suspendForBackground(keepActive: shouldKeepTalkActive)
|
||||
case .active, .inactive:
|
||||
self.isBackgrounded = false
|
||||
if self.operatorConnected {
|
||||
@@ -289,8 +293,12 @@ final class NodeAppModel {
|
||||
Task { [weak self] in
|
||||
guard let self else { return }
|
||||
let suspended = await MainActor.run { self.backgroundTalkSuspended }
|
||||
await MainActor.run { self.backgroundTalkSuspended = false }
|
||||
await self.talkMode.resumeAfterBackground(wasSuspended: suspended)
|
||||
let keptActive = await MainActor.run { self.backgroundTalkKeptActive }
|
||||
await MainActor.run {
|
||||
self.backgroundTalkSuspended = false
|
||||
self.backgroundTalkKeptActive = false
|
||||
}
|
||||
await self.talkMode.resumeAfterBackground(wasSuspended: suspended, wasKeptActive: keptActive)
|
||||
}
|
||||
}
|
||||
if phase == .active, self.reconnectAfterBackgroundArmed {
|
||||
|
||||
Reference in New Issue
Block a user