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 let Title = Arguments.get(1).and_then(|V| V.as_str()).unwrap_or("").to_string();
26 let Cancellable = Arguments.get(2).and_then(|V| V.as_bool()).unwrap_or(false);
27
28 let Id = NewProgressId();
29 let _ = ApplicationHandle.emit(
30 SkyEvent::ProgressBegin.AsStr(),
31 json!({
32 "id": Id,
33 "location": Location,
34 "title": Title,
35 "cancellable": Cancellable,
36 }),
37 );
38
39 Ok(json!(Id))
40}
41
42pub async fn ProgressReport(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
43 use tauri::Emitter;
44
45 let Id = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
46 let Increment = Arguments.get(1).and_then(|V| V.as_f64()).unwrap_or(0.0);
47 let Message = Arguments.get(2).and_then(|V| V.as_str()).unwrap_or("").to_string();
48
49 let _ = ApplicationHandle.emit(
50 SkyEvent::ProgressReport.AsStr(),
51 json!({
52 "id": Id,
53 "increment": Increment,
54 "message": Message,
55 }),
56 );
57
58 Ok(Value::Null)
59}
60
61pub async fn ProgressEnd(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
62 use tauri::Emitter;
63
64 let Id = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
65 let _ = ApplicationHandle.emit(SkyEvent::ProgressEnd.AsStr(), json!({ "id": Id }));
66 Ok(Value::Null)
67}