-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmisc.rs
62 lines (50 loc) · 1.84 KB
/
misc.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use super::{ContextAndPayloadEvent, ContextEvent, PayloadEvent};
use tauri::{api::shell::open, Manager};
use serde::Deserialize;
#[derive(Deserialize)]
pub struct OpenUrlEvent {
pub url: String,
}
#[derive(Deserialize)]
pub struct LogMessageEvent {
pub message: String,
}
pub async fn open_url(event: PayloadEvent<OpenUrlEvent>) -> Result<(), anyhow::Error> {
let app_handle = crate::APP_HANDLE.get().unwrap();
open(&app_handle.shell_scope(), event.payload.url, None)?;
Ok(())
}
pub async fn log_message(event: PayloadEvent<LogMessageEvent>) -> Result<(), anyhow::Error> {
log::info!("{}", event.payload.message.trim());
Ok(())
}
pub async fn send_to_property_inspector(event: ContextAndPayloadEvent<serde_json::Value>) -> Result<(), anyhow::Error> {
crate::events::outbound::property_inspector::send_to_property_inspector(event.context, event.payload).await?;
Ok(())
}
pub async fn send_to_plugin(event: ContextAndPayloadEvent<serde_json::Value>) -> Result<(), anyhow::Error> {
crate::events::outbound::property_inspector::send_to_plugin(event.context, event.payload).await?;
Ok(())
}
pub async fn show_alert(event: ContextEvent) -> Result<(), anyhow::Error> {
let app = crate::APP_HANDLE.get().unwrap();
let window = app.get_window("main").unwrap();
window.emit("show_alert", event.context)?;
Ok(())
}
pub async fn show_ok(event: ContextEvent) -> Result<(), anyhow::Error> {
let app = crate::APP_HANDLE.get().unwrap();
let window = app.get_window("main").unwrap();
window.emit("show_ok", event.context)?;
Ok(())
}
#[derive(Clone, serde::Serialize, Deserialize)]
pub struct SwitchProfileEvent {
device: String,
profile: String,
}
pub async fn switch_profile(event: SwitchProfileEvent) -> Result<(), anyhow::Error> {
let app_handle = crate::APP_HANDLE.get().unwrap();
app_handle.get_window("main").unwrap().emit("switch_profile", event)?;
Ok(())
}