Skip to main content

Mountain/RunTime/Shutdown/
Shutdown.rs

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