Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RunTime/Shutdown/
Shutdown.rs

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