Mountain/ApplicationState/State/FeatureState/LifecyclePhase/LifecyclePhaseState.rs
1use std::sync::{Arc, Mutex as StandardMutex};
2
3use crate::dev_log;
4
5/// Application lifecycle phases (mirrors VS Code LifecyclePhase).
6/// 1 = Starting, 2 = Ready, 3 = Restored, 4 = Eventually
7pub type Phase = u8;
8
9/// Tracks the current application lifecycle phase.
10/// Components poll this to defer work until the editor is fully initialised.
11#[derive(Clone)]
12pub struct LifecyclePhaseState {
13 CurrentPhase:Arc<StandardMutex<Phase>>,
14}
15
16impl Default for LifecyclePhaseState {
17 fn default() -> Self {
18 dev_log!(
19 "lifecycle",
20 "[LifecyclePhaseState] Initializing default lifecycle state (phase 1: Starting)..."
21 );
22 Self { CurrentPhase:Arc::new(StandardMutex::new(1)) }
23 }
24}
25
26impl LifecyclePhaseState {
27 /// Return the current lifecycle phase.
28 pub fn GetPhase(&self) -> Phase { self.CurrentPhase.lock().ok().map(|Guard| *Guard).unwrap_or(1) }
29
30 /// Advance the lifecycle phase. Only advances forward - never backwards.
31 pub fn SetPhase(&self, NewPhase:Phase) {
32 if let Ok(mut Guard) = self.CurrentPhase.lock() {
33 if NewPhase > *Guard {
34 dev_log!("lifecycle", "[LifecyclePhaseState] Phase advanced: {} → {}", *Guard, NewPhase);
35 *Guard = NewPhase;
36 }
37 }
38 }
39}