Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/UI/
Lifecycle.rs

1#![allow(non_snake_case, unused_variables)]
2
3//! Lifecycle handlers: phase get / wait / shutdown.
4//!
5//! `LifecycleWhenPhase` awaits `LifecyclePhaseState::PhaseNotify` instead
6//! of polling at 100 ms intervals. Each forward phase transition calls
7//! `notify_waiters()`, so callers wake exactly when the target phase arrives.
8
9use std::sync::Arc;
10
11use serde_json::{Value, json};
12use tauri::AppHandle;
13
14use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
15
16pub async fn LifecycleGetPhase(RunTime:Arc<ApplicationRunTime>) -> Result<Value, String> {
17	let Phase = RunTime.Environment.ApplicationState.Feature.Lifecycle.GetPhase();
18
19	Ok(json!(Phase))
20}
21
22pub async fn LifecycleWhenPhase(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
23	let RequestedPhase = Arguments.first().and_then(|V| V.as_u64()).unwrap_or(1) as u8;
24
25	let Lifecycle = &RunTime.Environment.ApplicationState.Feature.Lifecycle;
26
27	// Fast path: already at or past the requested phase.
28	if Lifecycle.GetPhase() >= RequestedPhase {
29		return Ok(Value::Null);
30	}
31
32	let Notify = Lifecycle.PhaseNotify.clone();
33
34	// Hard cap at 30 s so a stalled phase never deadlocks the workbench.
35	let _ = tokio::time::timeout(std::time::Duration::from_secs(30), async {
36		loop {
37			Notify.notified().await;
38
39			if Lifecycle.GetPhase() >= RequestedPhase {
40				break;
41			}
42		}
43	})
44	.await;
45
46	Ok(Value::Null)
47}
48
49pub async fn LifecycleRequestShutdown(ApplicationHandle:AppHandle) -> Result<Value, String> {
50	ApplicationHandle.exit(0);
51
52	Ok(Value::Null)
53}