@@ -42,7 +42,7 @@ use general_settings::GeneralSettingsStore;
4242use mp4:: Mp4Reader ;
4343use notifications:: NotificationType ;
4444use png:: { ColorType , Encoder } ;
45- use recording:: InProgressRecording ;
45+ use recording:: { InProgressRecording , StartRecordingInputs } ;
4646use relative_path:: RelativePathBuf ;
4747
4848use scap:: capturer:: Capturer ;
@@ -85,6 +85,12 @@ use windows::EditorWindowIds;
8585use windows:: set_window_transparent;
8686use windows:: { CapWindowId , ShowCapWindow } ;
8787
88+ pub enum RecordingState {
89+ None ,
90+ Pending ,
91+ Active ( InProgressRecording ) ,
92+ }
93+
8894#[ derive( specta:: Type , Serialize ) ]
8995#[ serde( rename_all = "camelCase" ) ]
9096pub struct App {
@@ -104,7 +110,7 @@ pub struct App {
104110 #[ serde( skip) ]
105111 handle : AppHandle ,
106112 #[ serde( skip) ]
107- current_recording : Option < InProgressRecording > ,
113+ recording_state : RecordingState ,
108114 #[ serde( skip) ]
109115 recording_logging_handle : LoggingHandle ,
110116 server_url : String ,
@@ -140,16 +146,27 @@ pub struct VideoUploadInfo {
140146}
141147
142148impl App {
143- pub fn set_current_recording ( & mut self , actor : InProgressRecording ) {
144- self . current_recording = Some ( actor) ;
149+ pub fn set_pending_recording ( & mut self ) {
150+ self . recording_state = RecordingState :: Pending ;
151+ CurrentRecordingChanged . emit ( & self . handle ) . ok ( ) ;
152+ }
145153
154+ pub fn set_current_recording ( & mut self , actor : InProgressRecording ) {
155+ self . recording_state = RecordingState :: Active ( actor) ;
146156 CurrentRecordingChanged . emit ( & self . handle ) . ok ( ) ;
147157 }
148158
149159 pub fn clear_current_recording ( & mut self ) -> Option < InProgressRecording > {
150- self . close_occluder_windows ( ) ;
151-
152- self . current_recording . take ( )
160+ match std:: mem:: replace ( & mut self . recording_state , RecordingState :: None ) {
161+ RecordingState :: Active ( recording) => {
162+ self . close_occluder_windows ( ) ;
163+ Some ( recording)
164+ }
165+ _ => {
166+ self . close_occluder_windows ( ) ;
167+ None
168+ }
169+ }
153170 }
154171
155172 fn close_occluder_windows ( & self ) {
@@ -175,6 +192,24 @@ impl App {
175192
176193 Ok ( ( ) )
177194 }
195+
196+ pub fn current_recording ( & self ) -> Option < & InProgressRecording > {
197+ match & self . recording_state {
198+ RecordingState :: Active ( recording) => Some ( recording) ,
199+ _ => None ,
200+ }
201+ }
202+
203+ pub fn current_recording_mut ( & mut self ) -> Option < & mut InProgressRecording > {
204+ match & mut self . recording_state {
205+ RecordingState :: Active ( recording) => Some ( recording) ,
206+ _ => None ,
207+ }
208+ }
209+
210+ pub fn is_recording_active_or_pending ( & self ) -> bool {
211+ !matches ! ( self . recording_state, RecordingState :: None )
212+ }
178213}
179214
180215#[ tauri:: command]
@@ -389,7 +424,7 @@ async fn get_current_recording(
389424 state : MutableState < ' _ , App > ,
390425) -> Result < JsonValue < Option < CurrentRecording > > , ( ) > {
391426 let state = state. read ( ) . await ;
392- Ok ( JsonValue :: new ( & state. current_recording . as_ref ( ) . map ( |r| {
427+ Ok ( JsonValue :: new ( & state. current_recording ( ) . map ( |r| {
393428 let bounds = r. bounds ( ) ;
394429
395430 let target = match r. capture_target ( ) {
@@ -2041,7 +2076,7 @@ pub async fn run(recording_logging_handle: LoggingHandle) {
20412076 camera_feed_initialization : None ,
20422077 mic_samples_tx : audio_input_tx,
20432078 mic_feed : None ,
2044- current_recording : None ,
2079+ recording_state : RecordingState :: None ,
20452080 recording_logging_handle,
20462081 server_url : GeneralSettingsStore :: get ( & app)
20472082 . ok ( )
@@ -2130,7 +2165,7 @@ pub async fn run(recording_logging_handle: LoggingHandle) {
21302165 let state = app. state :: < Arc < RwLock < App > > > ( ) ;
21312166 let app_state = & mut * state. write ( ) . await ;
21322167
2133- if app_state. current_recording . is_none ( ) {
2168+ if ! app_state. is_recording_active_or_pending ( ) {
21342169 app_state. mic_feed . take ( ) ;
21352170 app_state. camera_feed . take ( ) ;
21362171
0 commit comments