-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add toast messages to provide information
- Loading branch information
Showing
18 changed files
with
322 additions
and
798 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::fmt::Display; | ||
|
||
use serde::Serialize; | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
HttpError(reqwest::Error), | ||
SerdeError(serde_json::Error), | ||
DiviError(divi::error::Error), | ||
} | ||
|
||
impl Display for Error { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Error::HttpError(err) => err.fmt(f), | ||
Error::SerdeError(err) => err.fmt(f), | ||
Error::DiviError(err) => err.fmt(f), | ||
} | ||
} | ||
} | ||
|
||
impl Serialize for Error { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
serializer.serialize_str(self.to_string().as_str()) | ||
} | ||
} | ||
|
||
impl From<reqwest::Error> for Error { | ||
fn from(value: reqwest::Error) -> Self { | ||
Error::HttpError(value) | ||
} | ||
} | ||
|
||
impl From<serde_json::Error> for Error { | ||
fn from(value: serde_json::Error) -> Self { | ||
Error::SerdeError(value) | ||
} | ||
} | ||
|
||
impl From<divi::error::Error> for Error { | ||
fn from(value: divi::error::Error) -> Self { | ||
Error::DiviError(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use tauri::Window; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] | ||
#[serde(tag = "type")] | ||
pub enum Event { | ||
#[serde(rename = "toast")] | ||
#[serde(alias = "toast")] | ||
Toast { | ||
variant: ToastVariant, | ||
message: String, | ||
}, | ||
#[serde(rename = "auth-url")] | ||
#[serde(alias = "auth-url")] | ||
AuthUrl { url: String }, | ||
} | ||
|
||
impl Event { | ||
pub fn emit(&self, window: &Window) { | ||
window.emit(&self.name(), &self).unwrap(); | ||
} | ||
|
||
pub fn name(&self) -> &str { | ||
match self { | ||
Event::Toast { | ||
variant: _, | ||
message: _, | ||
} => "toast", | ||
Event::AuthUrl { url: _ } => "auth-url", | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] | ||
pub enum ToastVariant { | ||
#[serde(rename = "info")] | ||
Info, | ||
#[serde(rename = "success")] | ||
Success, | ||
#[serde(rename = "neutral")] | ||
Neutral, | ||
#[serde(rename = "warning")] | ||
Warning, | ||
#[serde(rename = "danger")] | ||
Danger, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { EventCallback, listen } from '@tauri-apps/api/event'; | ||
import { ToastVariant } from './toast'; | ||
|
||
export interface RustEvents { | ||
'auth-url': { | ||
type: 'auth-url'; | ||
url: string; | ||
}; | ||
toast: { | ||
type: 'toast'; | ||
variant: ToastVariant; | ||
message: string; | ||
}; | ||
} | ||
|
||
export const addRustListener = <EventName extends keyof RustEvents>( | ||
name: EventName, | ||
handler: EventCallback<RustEvents[EventName]> | ||
) => { | ||
return listen(name, handler); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.