Feature(custom): add option to show/hide main window on startup

This commit is contained in:
Kuingsmile
2025-08-27 17:55:29 +08:00
parent a81f0ed9eb
commit 674c9b0041
2 changed files with 10 additions and 6 deletions

View File

@@ -185,6 +185,9 @@ pub fn run() {
utils::path::get_app_logs_dir()?; utils::path::get_app_logs_dir()?;
utils::init_log::init_log()?; utils::init_log::init_log()?;
utils::path::get_app_config_dir()?; utils::path::get_app_config_dir()?;
let settings = conf::config::MergedSettings::load().unwrap_or_default();
let show_window = settings.app.show_window_on_startup.unwrap_or(false);
let app_state = app.state::<AppState>(); let app_state = app.state::<AppState>();
if let Err(e) = app_state.init(app_handle) { if let Err(e) = app_state.init(app_handle) {
log::error!("Failed to initialize app state: {e}"); log::error!("Failed to initialize app state: {e}");
@@ -201,11 +204,11 @@ pub fn run() {
setup_background_update_checker(app_handle); setup_background_update_checker(app_handle);
if let Some(window) = app.get_webview_window("main") { if let Some(window) = app.get_webview_window("main") {
if let Some(settings) = app_state.get_settings() { if show_window {
if !settings.app.show_window_on_startup.unwrap_or(false) { let _ = window.show();
let _ = window.hide(); log::info!("Main window shown on startup based on user preference");
log::info!("Main window hidden on startup based on user preference"); } else {
} log::info!("Main window hidden on startup based on user preference");
} }
let app_handle_clone = app_handle.clone(); let app_handle_clone = app_handle.clone();

View File

@@ -19,7 +19,8 @@
"minHeight": 400, "minHeight": 400,
"resizable": true, "resizable": true,
"center": true, "center": true,
"decorations": false "decorations": false,
"visible": false
} }
], ],
"security": { "security": {