Fix dead record button after mic permission denial
The watch app's permission-denied state was a computed property reading AVAudioApplication.shared.recordPermission — external state Observation cannot track — so after a denied prompt the UI never flipped to the 'Microphone access is off' screen and the record button silently did nothing. Store the denied flag as a tracked property instead, updated on every permission request. Also: log (instead of swallow) recorder start failures, drop phantom recordings when no file was written (the watch simulator has no audio input device), sweep orphaned metadata sidecars on reconcile, and add a DEBUG-only 'autorecord' launch argument for CLI-driven testing. Claude-Session: https://claude.ai/code/session_01GKfAiKiQKLDTmbiGva4FGE
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import AVFoundation
|
||||
import Foundation
|
||||
import IndieSync
|
||||
import OSLog
|
||||
import WatchKit
|
||||
|
||||
/// Records a single voice note on the watch into a persisted
|
||||
@@ -53,14 +54,16 @@ final class WatchAudioRecorder {
|
||||
/// Ask for microphone access, returning whether it was granted. Safe to call
|
||||
/// every time recording starts — the system only prompts once.
|
||||
func requestPermission() async -> Bool {
|
||||
await AVAudioApplication.requestRecordPermission()
|
||||
let granted = await AVAudioApplication.requestRecordPermission()
|
||||
permissionDenied = !granted
|
||||
return granted
|
||||
}
|
||||
|
||||
/// Whether the mic has been explicitly denied, so the UI can show a jump to
|
||||
/// Settings instead of a dead record button.
|
||||
var permissionDenied: Bool {
|
||||
AVAudioApplication.shared.recordPermission == .denied
|
||||
}
|
||||
/// Settings instead of a dead record button. Stored (not computed from
|
||||
/// `AVAudioApplication.shared.recordPermission`) so Observation tracks it and
|
||||
/// the UI actually flips to the denied state the moment a request is refused.
|
||||
private(set) var permissionDenied = AVAudioApplication.shared.recordPermission == .denied
|
||||
|
||||
/// Begin recording into a fresh `<ULID>.m4a`. A no-op if already recording.
|
||||
/// Throws if the audio session or recorder can't be configured.
|
||||
@@ -111,6 +114,14 @@ final class WatchAudioRecorder {
|
||||
let recording = Recording(
|
||||
id: current.id, url: current.url, duration: duration, recordedAt: current.startedAt)
|
||||
teardown()
|
||||
// The watch simulator has no audio input device: record() reports
|
||||
// success and currentTime advances, but no file is ever written. Don't
|
||||
// hand a phantom recording up to the transfer queue.
|
||||
guard FileManager.default.fileExists(atPath: recording.url.path) else {
|
||||
Logger(subsystem: "dev.rzen.indie.Notes.watchkitapp", category: "recording")
|
||||
.warning("recording produced no file (simulator has no mic input?): \(recording.url.lastPathComponent, privacy: .public)")
|
||||
return nil
|
||||
}
|
||||
return recording
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user