fix error popup on startup

This commit is contained in:
2024-06-03 01:21:43 -04:00
parent 816bd7db00
commit 0491cb5790
9 changed files with 74 additions and 103 deletions

View File

@@ -11,13 +11,13 @@ use aws_sdk_sts::{
};
use rfd::{
AsyncMessageDialog,
MessageDialog,
MessageLevel,
};
use sqlx::{
error::Error as SqlxError,
migrate::MigrateError,
};
use tauri::async_runtime as rt;
use tauri_plugin_global_shortcut::Error as ShortcutError;
use tokio::sync::oneshot::error::RecvError;
use serde::{
@@ -28,66 +28,26 @@ use serde::{
};
#[allow(async_fn_in_trait)]
pub trait ShowError<T>
pub trait ShowError<T, E>
{
async fn error_popup(self, title: &str);
async fn error_popup_passthrough(self, title: &str) -> Result<T, ()>;
fn blocking_error_popup(self, title: &str);
fn error_popup(self, title: &str);
fn error_print(self);
fn error_print_prefix(self, prefix: &str);
}
impl<T, E> ShowError<T> for Result<T, E>
impl<T, E> ShowError<T, E> for Result<T, E>
where E: std::fmt::Display
{
async fn error_popup(self, title: &str) {
fn error_popup(self, title: &str) {
if let Err(e) = self {
AsyncMessageDialog::new()
let dialog = AsyncMessageDialog::new()
.set_level(MessageLevel::Error)
.set_title(title)
.set_description(format!("{e}"))
.show()
.await;
.set_description(format!("{e}"));
rt::spawn(async move {dialog.show().await});
}
}
fn blocking_error_popup(self, title: &str) {
if let Err(e) = self {
MessageDialog::new()
.set_level(MessageLevel::Error)
.set_title(title)
.set_description(format!("{e}"))
.show();
}
}
async fn error_popup_passthrough(self, title: &str) -> Result<T, ()> {
match self {
Ok(v) => Ok(v),
Err(e) => {
AsyncMessageDialog::new()
.set_level(MessageLevel::Error)
.set_title(title)
.set_description(format!("{e}"))
.show()
.await;
Err(())
}
}
}
// fn error_popup_nowait(self, title: &str) {
// if let Err(e) = self {
// let app = app::APP.get().expect("Error popup failed, app handle not available");
// app.dialog()
// .message(format!("{e}"))
// .kind(MessageDialogKind::Error)
// .title(title)
// .show(|_| {})
// }
// }
fn error_print(self) {
if let Err(e) = self {
eprintln!("{e}");