refactor: single source of truth for lock state

This commit is contained in:
drendog 2026-01-18 02:47:06 +01:00
parent 4be98d3ba5
commit 7f5828f35d
Signed by: dwenya
GPG key ID: 8DD77074645332D0

View file

@ -10,7 +10,7 @@ use layer_shika_domain::value_objects::lock_config::LockConfig;
use layer_shika_domain::value_objects::lock_state::LockState; use layer_shika_domain::value_objects::lock_state::LockState;
use layer_shika_domain::value_objects::margins::Margins; use layer_shika_domain::value_objects::margins::Margins;
use layer_shika_domain::value_objects::output_policy::OutputPolicy; use layer_shika_domain::value_objects::output_policy::OutputPolicy;
use std::cell::{Cell, RefCell}; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use std::rc::Weak; use std::rc::Weak;
@ -18,7 +18,6 @@ pub struct SessionLock {
system: Weak<RefCell<dyn WaylandSystemOps>>, system: Weak<RefCell<dyn WaylandSystemOps>>,
component_name: String, component_name: String,
config: LockConfig, config: LockConfig,
state: Cell<LockState>,
command_sender: channel::Sender<ShellCommand>, command_sender: channel::Sender<ShellCommand>,
} }
@ -33,7 +32,6 @@ impl SessionLock {
system, system,
component_name, component_name,
config, config,
state: Cell::new(LockState::Inactive),
command_sender, command_sender,
} }
} }
@ -99,14 +97,15 @@ impl SessionLock {
#[must_use] #[must_use]
pub fn state(&self) -> LockState { pub fn state(&self) -> LockState {
if let Some(system) = self.system.upgrade() { let Some(system) = self.system.upgrade() else {
if let Ok(borrowed) = system.try_borrow() { return LockState::Inactive;
if let Some(state) = borrowed.session_lock_state() { };
self.state.set(state);
} let Ok(borrowed) = system.try_borrow() else {
} return LockState::Inactive;
} };
self.state.get()
borrowed.session_lock_state().unwrap_or(LockState::Inactive)
} }
#[must_use] #[must_use]