@@ -33,7 +33,7 @@ mod thumbnails;
3333mod tray;
3434mod update_project_names;
3535mod upload;
36- mod web_api;
36+ pub mod web_api;
3737mod window_exclusion;
3838mod windows;
3939
@@ -89,6 +89,7 @@ use std::{
8989 } ,
9090 time:: { Duration , SystemTime , UNIX_EPOCH } ,
9191} ;
92+ use tauri:: Listener ;
9293use tauri:: { AppHandle , Manager , State , Window , WindowEvent , ipc:: Channel } ;
9394use tauri_plugin_deep_link:: DeepLinkExt ;
9495use tauri_plugin_dialog:: DialogExt ;
@@ -158,6 +159,24 @@ impl AppExitState {
158159 }
159160}
160161
162+ pub struct MainWindowReadyState ( AtomicBool ) ;
163+
164+ impl Default for MainWindowReadyState {
165+ fn default ( ) -> Self {
166+ Self ( AtomicBool :: new ( false ) )
167+ }
168+ }
169+
170+ impl MainWindowReadyState {
171+ pub fn is_ready ( & self ) -> bool {
172+ self . 0 . load ( Ordering :: Acquire )
173+ }
174+
175+ pub fn set_ready ( & self , value : bool ) {
176+ self . 0 . store ( value, Ordering :: Release ) ;
177+ }
178+ }
179+
161180const APP_EXIT_STEP_TIMEOUT : Duration = Duration :: from_millis ( 750 ) ;
162181const APP_EXIT_CAMERA_SHUTDOWN_TIMEOUT : Duration = Duration :: from_millis ( 1200 ) ;
163182const APP_EXIT_TOTAL_TIMEOUT : Duration = Duration :: from_secs ( 3 ) ;
@@ -1113,14 +1132,6 @@ async fn cleanup_app_resources_for_exit(app: &AppHandle) {
11131132 } )
11141133 . await ;
11151134
1116- #[ cfg( target_os = "macos" ) ]
1117- {
1118- app. state :: < CameraWindowCloseGate > ( ) . set_allow_close ( true ) ;
1119- if let Some ( camera_window) = CapWindowId :: Camera . get ( app) {
1120- let _ = camera_window. close ( ) ;
1121- }
1122- }
1123-
11241135 if let Some ( rx) = camera_shutdown {
11251136 let _ = await_exit_step (
11261137 "camera_preview_shutdown" ,
@@ -3501,16 +3512,6 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
35013512 } ) ;
35023513 }
35033514
3504- tokio:: spawn ( {
3505- let app = app. clone ( ) ;
3506- async move {
3507- resume_uploads ( app)
3508- . await
3509- . map_err ( |err| warn ! ( "Error resuming uploads: {err}" ) )
3510- . ok ( ) ;
3511- }
3512- } ) ;
3513-
35143515 {
35153516 let ( server_url, should_update) = if cfg ! ( debug_assertions)
35163517 && let Ok ( url) = std:: env:: var ( "VITE_SERVER_URL" )
@@ -3570,12 +3571,30 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
35703571 app. manage ( CameraWindowPositionGuard :: default ( ) ) ;
35713572 app. manage ( CameraWindowOperationLock :: default ( ) ) ;
35723573 app. manage ( AppExitState :: default ( ) ) ;
3574+ app. manage ( MainWindowReadyState :: default ( ) ) ;
35733575
35743576 app. manage ( Arc :: new ( RwLock :: new (
35753577 ClipboardContext :: new ( ) . expect ( "Failed to create clipboard context" ) ,
35763578 ) ) ) ;
35773579 }
35783580
3581+ app. listen_any ( "main-window-ready" , {
3582+ let app = app. clone ( ) ;
3583+ move |_| {
3584+ app. state :: < MainWindowReadyState > ( ) . set_ready ( true ) ;
3585+ }
3586+ } ) ;
3587+
3588+ tokio:: spawn ( {
3589+ let app = app. clone ( ) ;
3590+ async move {
3591+ resume_uploads ( app)
3592+ . await
3593+ . map_err ( |err| warn ! ( "Error resuming uploads: {err}" ) )
3594+ . ok ( ) ;
3595+ }
3596+ } ) ;
3597+
35793598 spawn_mic_error_handler ( app. clone ( ) , mic_error_rx) ;
35803599 spawn_device_watchers ( app. clone ( ) ) ;
35813600 spawn_devices_snapshot_emitter ( app. clone ( ) ) ;
@@ -3825,6 +3844,7 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
38253844 reopen_main_window ( app) ;
38263845 }
38273846
3847+ #[ cfg( target_os = "macos" ) ]
38283848 return ;
38293849 }
38303850 CapWindowId :: Upgrade | CapWindowId :: ModeSelect => {
@@ -3840,6 +3860,7 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
38403860 }
38413861 }
38423862 restore_camera_window ( app) ;
3863+ #[ cfg( target_os = "macos" ) ]
38433864 return ;
38443865 }
38453866 CapWindowId :: TargetSelectOverlay { display_id } => {
@@ -3875,18 +3896,8 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
38753896 } ;
38763897 }
38773898
3878- if let Some ( settings) = GeneralSettingsStore :: get ( app) . unwrap_or ( None )
3879- && settings. hide_dock_icon
3880- && app. webview_windows ( ) . keys ( ) . all ( |label| {
3881- CapWindowId :: from_str ( label)
3882- . map ( |id| !id. activates_dock ( ) )
3883- . unwrap_or ( false )
3884- } )
3885- {
3886- #[ cfg( target_os = "macos" ) ]
3887- app. set_activation_policy ( tauri:: ActivationPolicy :: Accessory )
3888- . ok ( ) ;
3889- }
3899+ #[ cfg( target_os = "macos" ) ]
3900+ crate :: permissions:: sync_macos_dock_visibility ( app) ;
38903901 }
38913902 #[ cfg( target_os = "macos" ) ]
38923903 WindowEvent :: Focused ( focused) => {
@@ -3906,8 +3917,7 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
39063917 && let Ok ( window_id) = window_id
39073918 && window_id. activates_dock ( )
39083919 {
3909- app. set_activation_policy ( tauri:: ActivationPolicy :: Regular )
3910- . ok ( ) ;
3920+ crate :: permissions:: sync_macos_dock_visibility ( app) ;
39113921 }
39123922 }
39133923 WindowEvent :: DragDrop ( tauri:: DragDropEvent :: Drop { paths, .. } ) => {
0 commit comments