From a4dce5e64df4c3a87153e2979863a063f7d41b1f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 21 Feb 2026 18:15:44 +0000 Subject: [PATCH] Optimize startup by loading config asynchronously --- src/app/mod.rs | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index 9ef3072..610ba0d 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -124,18 +124,7 @@ impl cosmic::Application for AppModel { nav, key_binds: HashMap::new(), // Optional configuration file for an application. - config: cosmic_config::Config::new(Self::APP_ID, Config::VERSION) - .map(|context| match Config::get_entry(&context) { - Ok(config) => config, - Err((errors, config)) => { - for why in errors { - tracing::error!(%why, "error loading app config"); - } - - config - } - }) - .unwrap_or_default(), + config: Config::default(), status: fl!("status-connecting"), device_path: None, device_proxy: None, @@ -170,7 +159,34 @@ impl cosmic::Application for AppModel { cosmic::Action::App, ); - (app, command.chain(connect_task)) + let config_task = Task::perform( + async move { + let config = tokio::task::spawn_blocking(move || { + cosmic_config::Config::new(Self::APP_ID, Config::VERSION) + .map(|context| match Config::get_entry(&context) { + Ok(config) => config, + Err((errors, config)) => { + for why in errors { + tracing::error!(%why, "error loading app config"); + } + + config + } + }) + .unwrap_or_default() + }) + .await + .unwrap_or_else(|e| { + tracing::error!("Config task join error: {}", e); + Config::default() + }); + + Message::UpdateConfig(config) + }, + cosmic::Action::App, + ); + + (app, Task::batch(vec![command, connect_task, config_task])) } /// Elements to pack at the start of the header bar.