move error dialog to trait

This commit is contained in:
2023-04-30 14:10:21 -07:00
parent 871dedf0a3
commit 55775b6b05
4 changed files with 677 additions and 292 deletions

View File

@ -3,7 +3,6 @@
windows_subsystem = "windows"
)]
use std::error::Error;
use std::sync::mpsc::channel;
use once_cell::sync::OnceCell;
use sqlx::{
@ -17,10 +16,6 @@ use tauri::{
Manager,
async_runtime as rt,
};
use tauri::api::dialog::{
MessageDialogBuilder,
MessageDialogKind,
};
mod config;
mod errors;
@ -68,6 +63,10 @@ async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
fn run() -> tauri::Result<()> {
tauri::Builder::default()
.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| {
app.get_window("main")
.map(|w| w.show().error_popup("Failed to show main window"));
}))
.system_tray(tray::create())
.on_system_tray_event(tray::handle_event)
.invoke_handler(tauri::generate_handler![
@ -96,16 +95,7 @@ fn run() -> tauri::Result<()> {
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();
}
run().error_popup("Creddy failed to start");
}