Mountain/IPC/WindServiceHandler/
Notification.rs1#![allow(non_snake_case)]
2
3use serde_json::{Value, json};
6use tauri::AppHandle;
7
8pub async fn handle_notification_show(AppHandle:AppHandle, Args:Vec<Value>) -> Result<Value, String> {
11 use tauri::Emitter;
12
13 let Message = Args.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
14 let Severity = Args.get(1).and_then(|V| V.as_str()).unwrap_or("info").to_string();
15 let Actions = Args.get(2).cloned().unwrap_or(json!([]));
16
17 let Id = format!(
18 "notification-{}",
19 std::time::SystemTime::now()
20 .duration_since(std::time::UNIX_EPOCH)
21 .map(|D| D.as_millis())
22 .unwrap_or(0)
23 );
24
25 let _ = AppHandle.emit(
26 "sky://notification/show",
27 json!({
28 "id": Id,
29 "message": Message,
30 "severity": Severity,
31 "actions": Actions,
32 }),
33 );
34
35 Ok(json!(Id))
36}
37
38pub async fn handle_notification_show_progress(AppHandle:AppHandle, Args:Vec<Value>) -> Result<Value, String> {
40 use tauri::Emitter;
41
42 let Title = Args.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
43 let Cancellable = Args.get(1).and_then(|V| V.as_bool()).unwrap_or(false);
44
45 let Id = format!(
46 "progress-{}",
47 std::time::SystemTime::now()
48 .duration_since(std::time::UNIX_EPOCH)
49 .map(|D| D.as_millis())
50 .unwrap_or(0)
51 );
52
53 let _ = AppHandle.emit(
54 "sky://notification/progress-begin",
55 json!({
56 "id": Id,
57 "title": Title,
58 "cancellable": Cancellable,
59 }),
60 );
61
62 Ok(json!(Id))
63}
64
65pub async fn handle_notification_update_progress(AppHandle:AppHandle, Args:Vec<Value>) -> Result<Value, String> {
67 use tauri::Emitter;
68
69 let Id = Args.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
70 let Increment = Args.get(1).and_then(|V| V.as_f64()).unwrap_or(0.0);
71 let Message = Args.get(2).and_then(|V| V.as_str()).unwrap_or("").to_string();
72
73 let _ = AppHandle.emit(
74 "sky://notification/progress-update",
75 json!({
76 "id": Id,
77 "increment": Increment,
78 "message": Message,
79 }),
80 );
81
82 Ok(Value::Null)
83}
84
85pub async fn handle_notification_end_progress(AppHandle:AppHandle, Args:Vec<Value>) -> Result<Value, String> {
87 use tauri::Emitter;
88
89 let Id = Args.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
90
91 let _ = AppHandle.emit("sky://notification/progress-end", json!({ "id": Id }));
92
93 Ok(Value::Null)
94}