show non-fatal setup errors on home screen instead of in popup

This commit is contained in:
Joseph Montanaro
2023-09-14 15:04:25 -07:00
parent 12f0f187a6
commit 992d2a4d06
11 changed files with 62 additions and 12 deletions

View File

@ -43,6 +43,7 @@ pub fn run() -> tauri::Result<()> {
ipc::get_config,
ipc::save_config,
ipc::launch_terminal,
ipc::get_setup_errors,
])
.setup(|app| rt::block_on(setup(app)))
.build(tauri::generate_context!())?
@ -77,14 +78,15 @@ async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
// get_or_create_db_path doesn't create the actual db file, just the directory
let is_first_launch = !config::get_or_create_db_path()?.exists();
let pool = connect_db().await?;
let mut setup_errors: Vec<String> = vec![];
let conf = match AppConfig::load(&pool).await {
Ok(c) => c,
Err(SetupError::ConfigParseError(_)) => {
Err("Could not load configuration from database. Reverting to defaults.")
.error_popup("Setup error");
setup_errors.push(
"Could not load configuration from database. Reverting to defaults.".into()
);
AppConfig::default()
},
err => err?,
@ -94,7 +96,12 @@ async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
let srv = Server::new(conf.listen_addr, conf.listen_port, app.handle()).await?;
config::set_auto_launch(conf.start_on_login)?;
config::register_hotkeys(&conf.hotkeys).error_popup("Setup error");
if let Err(_e) = config::set_auto_launch(conf.start_on_login) {
setup_errors.push("Error: Failed to manage autolaunch.".into());
}
if let Err(e) = config::register_hotkeys(&conf.hotkeys) {
setup_errors.push(format!("{e}"));
}
// if session is empty, this is probably the first launch, so don't autohide
if !conf.start_minimized || is_first_launch {
@ -103,7 +110,7 @@ async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
.show()?;
}
let state = AppState::new(conf, session, srv, pool);
let state = AppState::new(conf, session, srv, pool, setup_errors);
app.manage(state);
Ok(())
}