Mountain/IPC/WindServiceHandlers/UI/
Progress.rs1#![allow(non_snake_case, unused_variables)]
2use serde_json::{Value, json};
8use tauri::AppHandle;
9use CommonLibrary::IPC::SkyEvent::SkyEvent;
10
11fn NewProgressId() -> String {
12 format!(
13 "progress-{}",
14 std::time::SystemTime::now()
15 .duration_since(std::time::UNIX_EPOCH)
16 .map(|D| D.as_millis())
17 .unwrap_or(0)
18 )
19}
20
21pub async fn ProgressBegin(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
22 use tauri::Emitter;
23
24 let Location = Arguments.first().and_then(|V| V.as_str()).unwrap_or("notification").to_string();
25
26 let Title = Arguments.get(1).and_then(|V| V.as_str()).unwrap_or("").to_string();
27
28 let Cancellable = Arguments.get(2).and_then(|V| V.as_bool()).unwrap_or(false);
29
30 let Id = NewProgressId();
31
32 let _ = ApplicationHandle.emit(
33 SkyEvent::ProgressBegin.AsStr(),
34 json!({
35 "id": Id,
36 "location": Location,
37 "title": Title,
38 "cancellable": Cancellable,
39 }),
40 );
41
42 Ok(json!(Id))
43}
44
45pub async fn ProgressReport(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
46 use tauri::Emitter;
47
48 let Id = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
49
50 let Increment = Arguments.get(1).and_then(|V| V.as_f64()).unwrap_or(0.0);
51
52 let Message = Arguments.get(2).and_then(|V| V.as_str()).unwrap_or("").to_string();
53
54 let _ = ApplicationHandle.emit(
55 SkyEvent::ProgressReport.AsStr(),
56 json!({
57 "id": Id,
58 "increment": Increment,
59 "message": Message,
60 }),
61 );
62
63 Ok(Value::Null)
64}
65
66pub async fn ProgressEnd(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
71 let _ = ApplicationHandle.emit(SkyEvent::ProgressEnd.AsStr(), json!({ "id": Id }));
72
73 Ok(Value::Null)
74}