@@ -457,12 +457,17 @@ async fn set_camera_input(
457457 . map_err ( |e| e. to_string ( ) ) ?;
458458 }
459459 Some ( id) => {
460+ {
461+ let app = & mut * state. write ( ) . await ;
462+ app. selected_camera_id = Some ( id. clone ( ) ) ;
463+ app. camera_in_use = true ;
464+ app. camera_cleanup_done = false ;
465+ }
466+
460467 let mut attempts = 0 ;
461- loop {
468+ let init_result : Result < ( ) , String > = loop {
462469 attempts += 1 ;
463470
464- // We first ask the actor to set the input
465- // This returns a future that resolves when the camera is actually ready
466471 let request = camera_feed
467472 . ask ( feeds:: camera:: SetInput { id : id. clone ( ) } )
468473 . await
@@ -474,10 +479,10 @@ async fn set_camera_input(
474479 } ;
475480
476481 match result {
477- Ok ( _) => break ,
482+ Ok ( _) => break Ok ( ( ) ) ,
478483 Err ( e) => {
479484 if attempts >= 3 {
480- return Err ( format ! (
485+ break Err ( format ! (
481486 "Failed to initialize camera after {} attempts: {}" ,
482487 attempts, e
483488 ) ) ;
@@ -489,6 +494,13 @@ async fn set_camera_input(
489494 tokio:: time:: sleep ( Duration :: from_millis ( 500 ) ) . await ;
490495 }
491496 }
497+ } ;
498+
499+ if let Err ( e) = init_result {
500+ let app = & mut * state. write ( ) . await ;
501+ app. selected_camera_id = None ;
502+ app. camera_in_use = false ;
503+ return Err ( e) ;
492504 }
493505
494506 ShowCapWindow :: Camera
@@ -2765,7 +2777,13 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
27652777 let state = app. state :: < ArcLock < App > > ( ) ;
27662778 let app_state = & mut * state. write ( ) . await ;
27672779
2768- if !app_state. is_recording_active_or_pending ( ) {
2780+ let camera_window_open =
2781+ CapWindowId :: Camera . get ( & app) . is_some ( ) ;
2782+
2783+ if !app_state. is_recording_active_or_pending ( )
2784+ && !camera_window_open
2785+ && !app_state. camera_in_use
2786+ {
27692787 let _ =
27702788 app_state. mic_feed . ask ( microphone:: RemoveInput ) . await ;
27712789 let _ = app_state
@@ -2775,7 +2793,6 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
27752793
27762794 app_state. selected_mic_label = None ;
27772795 app_state. selected_camera_id = None ;
2778- app_state. camera_in_use = false ;
27792796 }
27802797 } ) ;
27812798 }
0 commit comments