Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/UI/
Notification.rs

1#![allow(non_snake_case, unused_variables)]
2//! Notification toast handlers. Both the plain-message and the
3//! progress-bar variants go through here; each emits on an
4//! `SkyEvent::Notification*` channel so Sky's toast stack renders
5//! without a round-trip back through Mountain.
6//!
7//! Note: these are the Wind-facing IPC invocations (called from the
8//! renderer's `INotificationService`). The Cocoon-side notification
9//! path for extensions lives in `Vine::Server::Notification::*`.
10
11use serde_json::{Value, json};
12use tauri::AppHandle;
13use CommonLibrary::IPC::SkyEvent::SkyEvent;
14
15fn NewId(Prefix:&str) -> String {
16	use std::sync::atomic::{AtomicU64, Ordering};
17
18	static SEQ:AtomicU64 = AtomicU64::new(1);
19
20	format!("{}-{}", Prefix, SEQ.fetch_add(1, Ordering::Relaxed))
21}
22
23pub async fn NotificationShow(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
24	use tauri::Emitter;
25
26	let Message = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
27
28	let Severity = Arguments.get(1).and_then(|V| V.as_str()).unwrap_or("info").to_string();
29
30	let Actions = Arguments.get(2).cloned().unwrap_or(json!([]));
31
32	let Id = NewId("notification");
33
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
52	let Cancellable = Arguments.get(1).and_then(|V| V.as_bool()).unwrap_or(false);
53
54	let Id = NewId("progress");
55
56	let _ = ApplicationHandle.emit(
57		SkyEvent::NotificationProgressBegin.AsStr(),
58		json!({
59			"id": Id,
60			"title": Title,
61			"cancellable": Cancellable,
62		}),
63	);
64
65	Ok(json!(Id))
66}
67
68pub async fn NotificationUpdateProgress(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
69	use tauri::Emitter;
70
71	let Id = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
72
73	let Increment = Arguments.get(1).and_then(|V| V.as_f64()).unwrap_or(0.0);
74
75	let Message = Arguments.get(2).and_then(|V| V.as_str()).unwrap_or("").to_string();
76
77	let _ = ApplicationHandle.emit(
78		SkyEvent::NotificationProgressUpdate.AsStr(),
79		json!({
80			"id": Id,
81			"increment": Increment,
82			"message": Message,
83		}),
84	);
85
86	Ok(Value::Null)
87}
88
89pub async fn NotificationEndProgress(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
90	use tauri::Emitter;
91
92	let Id = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
93
94	let _ = ApplicationHandle.emit(SkyEvent::NotificationProgressEnd.AsStr(), json!({ "id": Id }));
95
96	Ok(Value::Null)
97}