Mountain/IPC/WindServiceHandlers/UI/
Notification.rs1#![allow(non_snake_case, unused_variables)]
2use serde_json::{Value, json};
12use tauri::AppHandle;
13use CommonLibrary::IPC::SkyEvent::SkyEvent;
14
15fn NewId(Prefix:&str) -> String {
16 format!(
17 "{}-{}",
18 Prefix,
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
26pub async fn NotificationShow(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
27 use tauri::Emitter;
28
29 let Message = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
30 let Severity = Arguments.get(1).and_then(|V| V.as_str()).unwrap_or("info").to_string();
31 let Actions = Arguments.get(2).cloned().unwrap_or(json!([]));
32
33 let Id = NewId("notification");
34 let _ = ApplicationHandle.emit(
35 SkyEvent::NotificationShow.AsStr(),
36 json!({
37 "id": Id,
38 "message": Message,
39 "severity": Severity,
40 "actions": Actions,
41 }),
42 );
43
44 Ok(json!(Id))
45}
46
47pub async fn NotificationShowProgress(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
48 use tauri::Emitter;
49
50 let Title = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
51 let Cancellable = Arguments.get(1).and_then(|V| V.as_bool()).unwrap_or(false);
52
53 let Id = NewId("progress");
54 let _ = ApplicationHandle.emit(
55 SkyEvent::NotificationProgressBegin.AsStr(),
56 json!({
57 "id": Id,
58 "title": Title,
59 "cancellable": Cancellable,
60 }),
61 );
62
63 Ok(json!(Id))
64}
65
66pub async fn NotificationUpdateProgress(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
67 use tauri::Emitter;
68
69 let Id = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
70 let Increment = Arguments.get(1).and_then(|V| V.as_f64()).unwrap_or(0.0);
71 let Message = Arguments.get(2).and_then(|V| V.as_str()).unwrap_or("").to_string();
72
73 let _ = ApplicationHandle.emit(
74 SkyEvent::NotificationProgressUpdate.AsStr(),
75 json!({
76 "id": Id,
77 "increment": Increment,
78 "message": Message,
79 }),
80 );
81
82 Ok(Value::Null)
83}
84
85pub async fn NotificationEndProgress(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
86 use tauri::Emitter;
87
88 let Id = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
89 let _ = ApplicationHandle.emit(SkyEvent::NotificationProgressEnd.AsStr(), json!({ "id": Id }));
90 Ok(Value::Null)
91}