display setup errors

This commit is contained in:
2023-04-30 10:52:46 -07:00
parent 913148a75a
commit 871dedf0a3
5 changed files with 41 additions and 14 deletions

View File

@ -90,6 +90,7 @@ pub fn set_auto_launch(is_configured: bool) -> Result<(), SetupError> {
pub fn get_or_create_db_path() -> Result<PathBuf, DataDirError> {
// debug_assertions doesn't always mean we are running in dev
if cfg!(debug_assertions) && std::env::var("HOME").is_ok() {
return Ok(PathBuf::from("./creddy.db"));
}

View File

@ -3,7 +3,9 @@
windows_subsystem = "windows"
)]
use std::error::Error;
use std::sync::mpsc::channel;
use once_cell::sync::OnceCell;
use sqlx::{
SqlitePool,
sqlite::SqlitePoolOptions,
@ -15,7 +17,10 @@ use tauri::{
Manager,
async_runtime as rt,
};
use once_cell::sync::OnceCell;
use tauri::api::dialog::{
MessageDialogBuilder,
MessageDialogKind,
};
mod config;
mod errors;
@ -61,7 +66,7 @@ async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
}
fn main() {
fn run() -> tauri::Result<()> {
tauri::Builder::default()
.system_tray(tray::create())
.on_system_tray_event(tray::handle_event)
@ -74,8 +79,7 @@ fn main() {
ipc::save_config,
])
.setup(|app| rt::block_on(setup(app)))
.build(tauri::generate_context!())
.expect("error while running tauri application")
.build(tauri::generate_context!())?
.run(|app, run_event| match run_event {
tauri::RunEvent::WindowEvent { label, event, .. } => match event {
tauri::WindowEvent::CloseRequested { api, .. } => {
@ -85,7 +89,23 @@ fn main() {
_ => ()
}
_ => ()
})
});
Ok(())
}
fn main() {
if let Err(e) = run() {
let (tx, rx) = channel();
MessageDialogBuilder::new(
"Creddy failed to start",
format!("{e}")
)
.kind(MessageDialogKind::Error)
.show(move |_| tx.send(true).unwrap());
rx.recv().unwrap();
}
}