@@ -36,8 +36,10 @@ use native_dialog::{MessageDialog, MessageType};
3636use regex:: Regex ;
3737extern crate percent_encoding;
3838use tauri:: http:: ResponseBuilder ;
39- use tauri:: GlobalWindowEvent ;
40- mod init;
39+ use tauri:: api:: path:: app_local_data_dir;
40+ use tauri:: generate_context;
41+ use crate :: utilities:: ensure_dir_exists;
42+ use crate :: boot_config:: read_boot_config;
4143mod bugsnag;
4244mod utilities;
4345mod boot_config;
@@ -258,6 +260,7 @@ fn zoom_window(window: tauri::Window, scale_factor: f64) {
258260}
259261
260262// here in case you need to process windows events
263+ // use tauri::GlobalWindowEvent;
261264// fn process_window_event(event: &GlobalWindowEvent) {
262265// if let tauri::WindowEvent::CloseRequested { .. } = event.event() {
263266// // this does nothing and is here if in future you need to persist something on window close.
@@ -366,6 +369,28 @@ fn main() {
366369 tauri_plugin_deep_link:: prepare ( "io.phcode" ) ;
367370 }
368371
372+ let context = generate_context ! ( ) ;
373+ let mut tauri_config = context. config ( ) . clone ( ) ; // Clone the config to modify it
374+
375+ // Get the app data directory before Tauri starts
376+ let app_data_dir: Option < PathBuf > = app_local_data_dir ( & tauri_config) ;
377+
378+ if let Some ( dir) = & app_data_dir {
379+ println ! ( "App Data Directory: {}" , dir. display( ) ) ;
380+ ensure_dir_exists ( dir) ;
381+ } else {
382+ eprintln ! ( "Failed to retrieve app data directory." ) ;
383+ }
384+
385+ let boot_config = read_boot_config ( & app_data_dir) ;
386+
387+ // Modify the first window's visibility based on boot_config.start_as_hidden_window
388+ if let Some ( first_window) = tauri_config. tauri . windows . get_mut ( 0 ) {
389+ if !boot_config. start_as_hidden_window {
390+ first_window. visible = true ;
391+ }
392+ }
393+
369394 // warning: any string that resembles the following strings will be rewritten in source in prod by build scripts.
370395 // This is so that app bundle IDs are correct. IF they are app bundle IDs use the strings. else dont.
371396 // do not use strings: "io.phcode.dev" "io.phcode.staging" "io.phcode" for anything other than bundle identifiers
@@ -439,15 +464,7 @@ fn main() {
439464 put_item, get_item, get_all_items, delete_item,
440465 _get_windows_drives, _rename_path, show_in_folder, move_to_trash, zoom_window,
441466 _get_clipboard_files, _open_url_in_browser_win] )
442- . setup ( |app| {
443- let boot_config = init:: init_app ( app) ;
444-
445- if boot_config. start_as_hidden_window {
446- if let Some ( main_window) = app. get_window ( "main" ) {
447- main_window. hide ( ) . expect ( "Failed to hide main window" ) ;
448- }
449- }
450-
467+ . setup ( move |_app| {
451468 #[ cfg( target_os = "linux" ) ]
452469 {
453470 // In linux, f10 key press events are reserved for gtk-menu-bar-accel and not passed.
@@ -478,6 +495,6 @@ fn main() {
478495 }
479496 Ok ( ( ) )
480497 } )
481- . run ( tauri :: generate_context! ( ) )
498+ . run ( context )
482499 . expect ( "error while running tauri application" ) ;
483500}
0 commit comments