mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2026-01-22 07:05:56 +00:00
refactor: single source of truth for lock state
This commit is contained in:
parent
4be98d3ba5
commit
7f5828f35d
1 changed files with 10 additions and 11 deletions
|
|
@ -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::margins::Margins;
|
||||
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::Weak;
|
||||
|
||||
|
|
@ -18,7 +18,6 @@ pub struct SessionLock {
|
|||
system: Weak<RefCell<dyn WaylandSystemOps>>,
|
||||
component_name: String,
|
||||
config: LockConfig,
|
||||
state: Cell<LockState>,
|
||||
command_sender: channel::Sender<ShellCommand>,
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +32,6 @@ impl SessionLock {
|
|||
system,
|
||||
component_name,
|
||||
config,
|
||||
state: Cell::new(LockState::Inactive),
|
||||
command_sender,
|
||||
}
|
||||
}
|
||||
|
|
@ -99,14 +97,15 @@ impl SessionLock {
|
|||
|
||||
#[must_use]
|
||||
pub fn state(&self) -> LockState {
|
||||
if let Some(system) = self.system.upgrade() {
|
||||
if let Ok(borrowed) = system.try_borrow() {
|
||||
if let Some(state) = borrowed.session_lock_state() {
|
||||
self.state.set(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.state.get()
|
||||
let Some(system) = self.system.upgrade() else {
|
||||
return LockState::Inactive;
|
||||
};
|
||||
|
||||
let Ok(borrowed) = system.try_borrow() else {
|
||||
return LockState::Inactive;
|
||||
};
|
||||
|
||||
borrowed.session_lock_state().unwrap_or(LockState::Inactive)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue