Add: just commands for release build

This commit is contained in:
DaZuo0122
2026-02-13 11:22:46 +08:00
parent 3c3ca342c9
commit 55fe53235d
21 changed files with 253 additions and 97 deletions

View File

@@ -35,14 +35,16 @@ impl RuntimeCore {
pub fn new_with_config(
config_path: PathBuf,
config_value: AppConfig,
mut config_value: AppConfig,
capabilities: CapabilityFlags,
) -> Result<Self, RuntimeCoreError> {
let click_through_was_enabled = config_value.window.click_through;
config_value.window.click_through = false;
let mut snapshot = FrontendStateSnapshot::idle(capabilities);
snapshot.x = config_value.window.x;
snapshot.y = config_value.window.y;
snapshot.scale = config_value.window.scale;
snapshot.flags.click_through = config_value.window.click_through;
snapshot.flags.click_through = false;
snapshot.flags.always_on_top = config_value.window.always_on_top;
snapshot.flags.visible = config_value.window.visible;
snapshot.active_sprite_pack = config_value.sprite.selected_pack.clone();
@@ -50,14 +52,18 @@ impl RuntimeCore {
let api_config = ApiConfig::default_with_token(config_value.api.auth_token.clone());
let (command_tx, command_rx) = mpsc::channel(1_024);
Ok(Self {
let core = Self {
config_path,
config: Arc::new(RwLock::new(config_value)),
snapshot: Arc::new(RwLock::new(snapshot)),
api_config,
command_tx,
command_rx: Arc::new(Mutex::new(command_rx)),
})
};
if click_through_was_enabled {
core.persist_config()?;
}
Ok(core)
}
pub fn snapshot(&self) -> Arc<RwLock<FrontendStateSnapshot>> {
@@ -169,7 +175,7 @@ impl RuntimeCore {
self.persist_config()?;
}
FrontendCommand::SetFlags {
click_through,
click_through: _click_through,
always_on_top,
visible,
} => {
@@ -178,9 +184,7 @@ impl RuntimeCore {
.snapshot
.write()
.map_err(|_| RuntimeCoreError::SnapshotPoisoned)?;
if let Some(value) = click_through {
snapshot.flags.click_through = *value;
}
snapshot.flags.click_through = false;
if let Some(value) = always_on_top {
snapshot.flags.always_on_top = *value;
}
@@ -194,9 +198,7 @@ impl RuntimeCore {
.config
.write()
.map_err(|_| RuntimeCoreError::ConfigPoisoned)?;
if let Some(value) = click_through {
config.window.click_through = *value;
}
config.window.click_through = false;
if let Some(value) = always_on_top {
config.window.always_on_top = *value;
}
@@ -259,4 +261,26 @@ mod tests {
assert_eq!(snapshot.state, FrontendState::Active);
assert_eq!(snapshot.current_animation, "active");
}
#[test]
fn click_through_flag_is_ignored_and_forced_false() {
let temp = TempDir::new().expect("tempdir");
let path = temp.path().join("config.toml");
let mut config = AppConfig::default();
config.window.click_through = true;
let core = RuntimeCore::new_with_config(path, config, CapabilityFlags::default())
.expect("core init");
core.apply_command(&FrontendCommand::SetFlags {
click_through: Some(true),
always_on_top: None,
visible: None,
})
.expect("apply");
let snapshot = core.snapshot().read().expect("snapshot lock").clone();
assert!(!snapshot.flags.click_through);
let config = core.config().read().expect("config lock").clone();
assert!(!config.window.click_through);
}
}