Add busy state for robust recorder cleanup

This commit is contained in:
Beingpax 2025-07-11 09:05:51 +05:45
parent 720d6ae8c8
commit 57f47af062
4 changed files with 17 additions and 23 deletions

View File

@ -28,7 +28,7 @@ class HotkeyManager: ObservableObject {
// MARK: - Helper Properties
private var canProcessHotkeyAction: Bool {
whisperState.recordingState != .transcribing && whisperState.recordingState != .enhancing
whisperState.recordingState != .transcribing && whisperState.recordingState != .enhancing && whisperState.recordingState != .busy
}
// NSEvent monitoring for modifier keys

View File

@ -153,7 +153,7 @@ class Recorder: ObservableObject {
}
deviceManager.isRecordingActive = false
}
private func updateAudioMeter() {
guard let recorder = recorder else { return }
recorder.updateMeters()

View File

@ -53,23 +53,32 @@ extension WhisperState {
}
func dismissMiniRecorder() async {
if recordingState == .busy { return }
let wasRecording = recordingState == .recording
logger.notice("📱 Dismissing \(self.recorderType) recorder")
await MainActor.run {
self.recordingState = .busy
NotificationManager.shared.dismissNotification()
}
if recordingState == .recording {
if wasRecording {
await recorder.stopRecording()
}
// Hide recorder panel first before doing anything else
hideRecorderPanel()
await MainActor.run {
recordingState = .idle
isMiniRecorderVisible = false
}
await cleanupModelResources()
await MainActor.run {
recordingState = .idle
}
}
func cancelRecording() async {

View File

@ -12,6 +12,7 @@ enum RecordingState: Equatable {
case recording
case transcribing
case enhancing
case busy
}
@MainActor
@ -349,9 +350,6 @@ class WhisperState: NSObject, ObservableObject {
}
await self.dismissMiniRecorder()
Task.detached(priority: .background) {
await self.cleanupModelResources()
}
} catch {
do {
@ -377,17 +375,7 @@ class WhisperState: NSObject, ObservableObject {
logger.error("❌ Could not create a record for the failed transcription: \(error.localizedDescription)")
}
await MainActor.run {
NotificationManager.shared.showNotification(
title: "Transcription Failed",
type: .error
)
}
await self.dismissMiniRecorder()
Task.detached(priority: .background) {
await self.cleanupModelResources()
}
}
}
@ -397,7 +385,7 @@ class WhisperState: NSObject, ObservableObject {
private func checkCancellationAndCleanup() async -> Bool {
if shouldCancelRecording {
await cleanupAndDismiss()
await dismissMiniRecorder()
return true
}
return false
@ -405,9 +393,6 @@ class WhisperState: NSObject, ObservableObject {
private func cleanupAndDismiss() async {
await dismissMiniRecorder()
Task.detached(priority: .background) {
await self.cleanupModelResources()
}
}
}