Skip to main content

Mountain/RunTime/Shutdown/
Shutdown.rs

1#![allow(non_snake_case)]
2
3//! Top-level shutdown orchestrator. Emits the `sky://lifecycle/willShutdown`
4//! event so Wind/Sky can flush dirty editors, dispose sockets, and cancel
5//! async tasks before the runtime tears down. Then calls
6//! `ShutdownWithRecovery` and logs the outcome.
7
8use tauri::Emitter;
9
10use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
11
12impl ApplicationRunTime {
13	pub async fn Shutdown(&self) {
14		dev_log!("lifecycle", "[ApplicationRunTime] Initiating graceful shutdown of services...");
15
16		if let Err(Error) = self
17			.Environment
18			.ApplicationHandle
19			.emit("sky://lifecycle/willShutdown", serde_json::json!({ "reason": "quit" }))
20		{
21			dev_log!(
22				"lifecycle",
23				"warn: [ApplicationRunTime] sky://lifecycle/willShutdown emit failed: {}",
24				Error
25			);
26		}
27
28		match self.ShutdownWithRecovery().await {
29			Ok(()) => {
30				dev_log!(
31					"lifecycle",
32					"[ApplicationRunTime] Service shutdown tasks completed successfully."
33				)
34			},
35			Err(Error) => {
36				dev_log!(
37					"lifecycle",
38					"error: [ApplicationRunTime] Service shutdown completed with errors: {}",
39					Error
40				)
41			},
42		}
43	}
44}