move error dialog to trait
This commit is contained in:
parent
871dedf0a3
commit
55775b6b05
905
src-tauri/Cargo.lock
generated
905
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,8 @@ tauri-build = { version = "1.0.4", features = [] }
|
||||
[dependencies]
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tauri = { version = "1.0.5", features = ["api-all", "dialog", "system-tray"] }
|
||||
tauri = { version = "1.2", features = ["api-all", "dialog", "system-tray"] }
|
||||
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
|
||||
sodiumoxide = "0.2.7"
|
||||
tokio = { version = ">=1.19", features = ["full"] }
|
||||
sqlx = { version = "0.6.2", features = ["sqlite", "runtime-tokio-rustls"] }
|
||||
|
@ -1,9 +1,9 @@
|
||||
use std::error::Error;
|
||||
use std::convert::AsRef;
|
||||
use std::sync::mpsc;
|
||||
use strum_macros::AsRefStr;
|
||||
|
||||
use thiserror::Error as ThisError;
|
||||
|
||||
use aws_sdk_sts::{
|
||||
types::SdkError as AwsSdkError,
|
||||
error::GetSessionTokenError,
|
||||
@ -12,32 +12,29 @@ use sqlx::{
|
||||
error::Error as SqlxError,
|
||||
migrate::MigrateError,
|
||||
};
|
||||
|
||||
use tauri::api::dialog::{
|
||||
MessageDialogBuilder,
|
||||
MessageDialogKind,
|
||||
};
|
||||
use serde::{Serialize, Serializer, ser::SerializeMap};
|
||||
|
||||
|
||||
// pub struct SerializeError<E> {
|
||||
// pub err: E,
|
||||
// }
|
||||
pub trait ErrorPopup {
|
||||
fn error_popup(self, title: &str);
|
||||
}
|
||||
|
||||
// impl<E: std::error::Error> Serialize for SerializeError<E>
|
||||
// {
|
||||
// fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
// let mut map = serializer.serialize_map(None)?;
|
||||
// map.serialize_entry("msg", &format!("{}", self.err))?;
|
||||
// if let Some(src) = self.err.source() {
|
||||
// let ser_src = SerializeError { err: src };
|
||||
// map.serialize_entry("source", &ser_src)?;
|
||||
// }
|
||||
// map.end()
|
||||
// }
|
||||
// }
|
||||
impl<E: Error> ErrorPopup for Result<(), E> {
|
||||
fn error_popup(self, title: &str) {
|
||||
if let Err(e) = self {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
MessageDialogBuilder::new(title, format!("{e}"))
|
||||
.kind(MessageDialogKind::Error)
|
||||
.show(move |_| tx.send(true).unwrap());
|
||||
|
||||
// impl<E: std::error::Error> From<E> for SerializeError<E> {
|
||||
// fn from(err: E) -> Self {
|
||||
// SerializeError { err }
|
||||
// }
|
||||
// }
|
||||
rx.recv().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn serialize_basic_err<E, S>(err: &E, serializer: S) -> Result<S::Ok, S::Error>
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user