Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/UI/
ProgressBegin.rs

1//! Wire method: `progress:begin`.
2
3use serde_json::{Value, json};
4use tauri::{AppHandle, Emitter};
5use CommonLibrary::IPC::SkyEvent::SkyEvent;
6
7use crate::IPC::WindServiceHandlers::Utilities::JsonValueHelpers::{arg_bool, arg_string, arg_string_or};
8
9fn NewProgressId() -> String {
10	format!(
11		"progress-{}",
12		std::time::SystemTime::now()
13			.duration_since(std::time::UNIX_EPOCH)
14			.map(|D| D.as_millis())
15			.unwrap_or(0)
16	)
17}
18
19pub async fn Fn(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
20	let Location = arg_string_or(&Arguments, 0, "notification");
21
22	let Title = arg_string(&Arguments, 1);
23
24	let Cancellable = arg_bool(&Arguments, 2);
25
26	let Id = NewProgressId();
27
28	let _ = ApplicationHandle.emit(
29		SkyEvent::ProgressBegin.AsStr(),
30		json!({
31			"id": Id,
32			"location": Location,
33			"title": Title,
34			"cancellable": Cancellable,
35		}),
36	);
37
38	Ok(json!(Id))
39}