Add: just commands for release build
This commit is contained in:
@@ -26,6 +26,7 @@ use tracing::{error, info, warn};
|
||||
const APP_NAME: &str = "sprimo";
|
||||
const DEFAULT_PACK: &str = "default";
|
||||
const WINDOW_PADDING: f32 = 16.0;
|
||||
const STARTUP_WINDOW_SIZE: f32 = 416.0;
|
||||
const MAGENTA_KEY: [u8; 3] = [255, 0, 255];
|
||||
const CHROMA_KEY_TOLERANCE: u8 = 24;
|
||||
const CHROMA_KEY_FORCE_RATIO: f32 = 0.15;
|
||||
@@ -180,7 +181,13 @@ fn main() -> Result<(), AppError> {
|
||||
.compact()
|
||||
.init();
|
||||
|
||||
let (config_path, config) = sprimo_config::load_or_create(APP_NAME)?;
|
||||
let (config_path, mut config) = sprimo_config::load_or_create(APP_NAME)?;
|
||||
if config.window.click_through {
|
||||
config.window.click_through = false;
|
||||
if let Err(err) = save(&config_path, &config) {
|
||||
warn!(%err, "failed to persist click-through disable at startup");
|
||||
}
|
||||
}
|
||||
let platform: Arc<dyn PlatformAdapter> = create_adapter().into();
|
||||
let capabilities = platform.capabilities();
|
||||
|
||||
@@ -188,7 +195,7 @@ fn main() -> Result<(), AppError> {
|
||||
snapshot.x = config.window.x;
|
||||
snapshot.y = config.window.y;
|
||||
snapshot.scale = config.window.scale;
|
||||
snapshot.flags.click_through = config.window.click_through;
|
||||
snapshot.flags.click_through = false;
|
||||
snapshot.flags.always_on_top = config.window.always_on_top;
|
||||
snapshot.flags.visible = config.window.visible;
|
||||
snapshot.active_sprite_pack = config.sprite.selected_pack.clone();
|
||||
@@ -223,7 +230,10 @@ fn main() -> Result<(), AppError> {
|
||||
decorations: false,
|
||||
resizable: false,
|
||||
window_level: WindowLevel::AlwaysOnTop,
|
||||
resolution: bevy::window::WindowResolution::new(544.0, 544.0),
|
||||
resolution: bevy::window::WindowResolution::new(
|
||||
STARTUP_WINDOW_SIZE,
|
||||
STARTUP_WINDOW_SIZE,
|
||||
),
|
||||
position: WindowPosition::At(IVec2::new(
|
||||
config.window.x.round() as i32,
|
||||
config.window.y.round() as i32,
|
||||
@@ -721,7 +731,6 @@ fn attach_window_handle_once(
|
||||
.read()
|
||||
.expect("frontend snapshot lock poisoned");
|
||||
let _ = platform.0.set_always_on_top(guard.flags.always_on_top);
|
||||
let _ = platform.0.set_click_through(guard.flags.click_through);
|
||||
let _ = platform.0.set_visible(guard.flags.visible);
|
||||
let _ = platform.0.set_window_position(guard.x, guard.y);
|
||||
*attached = true;
|
||||
@@ -746,14 +755,14 @@ fn poll_hotkey_recovery(
|
||||
) {
|
||||
while ingress.0.try_recv().is_ok() {
|
||||
info!("recovery hotkey received");
|
||||
let _ = platform.0.set_click_through(false);
|
||||
let _ = platform.0.set_always_on_top(true);
|
||||
let _ = platform.0.set_visible(true);
|
||||
|
||||
if let Ok(mut visibility) = pet_query.get_single_mut() {
|
||||
*visibility = Visibility::Visible;
|
||||
}
|
||||
|
||||
config.config.window.click_through = false;
|
||||
config.config.window.always_on_top = true;
|
||||
config.config.window.visible = true;
|
||||
if let Err(err) = save(&config.path, &config.config) {
|
||||
warn!(%err, "failed to persist config after hotkey recovery");
|
||||
@@ -761,6 +770,7 @@ fn poll_hotkey_recovery(
|
||||
|
||||
if let Ok(mut guard) = snapshot.0.write() {
|
||||
guard.flags.click_through = false;
|
||||
guard.flags.always_on_top = true;
|
||||
guard.flags.visible = true;
|
||||
guard.last_error = None;
|
||||
}
|
||||
@@ -927,9 +937,8 @@ fn poll_backend_commands(
|
||||
always_on_top,
|
||||
visible,
|
||||
} => {
|
||||
if let Some(value) = click_through {
|
||||
let _ = platform.0.set_click_through(value);
|
||||
config.config.window.click_through = value;
|
||||
if click_through.is_some() {
|
||||
config.config.window.click_through = false;
|
||||
}
|
||||
if let Some(value) = always_on_top {
|
||||
let _ = platform.0.set_always_on_top(value);
|
||||
@@ -949,9 +958,7 @@ fn poll_backend_commands(
|
||||
warn!(%err, "failed to persist flag config");
|
||||
}
|
||||
if let Ok(mut guard) = snapshot.0.write() {
|
||||
if let Some(value) = click_through {
|
||||
guard.flags.click_through = value;
|
||||
}
|
||||
guard.flags.click_through = false;
|
||||
if let Some(value) = always_on_top {
|
||||
guard.flags.always_on_top = value;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ mod windows {
|
||||
impl PlatformAdapter for WindowsAdapter {
|
||||
fn capabilities(&self) -> CapabilityFlags {
|
||||
CapabilityFlags {
|
||||
supports_click_through: true,
|
||||
supports_click_through: false,
|
||||
supports_transparency: true,
|
||||
supports_tray: false,
|
||||
supports_global_hotkey: true,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"windows": ["*"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"core:window:allow-start-dragging",
|
||||
"core:event:allow-listen",
|
||||
"core:event:allow-unlisten"
|
||||
]
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"default":{"identifier":"default","description":"Default capability for sprimo-tauri main window runtime APIs.","local":true,"windows":["*"],"permissions":["core:default","core:event:allow-listen","core:event:allow-unlisten"]}}
|
||||
{"default":{"identifier":"default","description":"Default capability for sprimo-tauri main window runtime APIs.","local":true,"windows":["*"],"permissions":["core:default","core:window:allow-start-dragging","core:event:allow-listen","core:event:allow-unlisten"]}}
|
||||
@@ -153,6 +153,8 @@ fn main() -> Result<(), AppError> {
|
||||
}
|
||||
|
||||
let command_rx = runtime_core.command_receiver();
|
||||
let runtime_core_for_commands = Arc::clone(&runtime_core);
|
||||
let app_handle_for_commands = app_handle.clone();
|
||||
runtime.spawn(async move {
|
||||
loop {
|
||||
let next = {
|
||||
@@ -163,24 +165,45 @@ fn main() -> Result<(), AppError> {
|
||||
break;
|
||||
};
|
||||
|
||||
if let Err(err) = runtime_core.apply_command(&envelope.command) {
|
||||
if let Err(err) = runtime_core_for_commands.apply_command(&envelope.command) {
|
||||
warn!(%err, "failed to apply command in tauri runtime");
|
||||
continue;
|
||||
}
|
||||
|
||||
let payload = {
|
||||
let snapshot = runtime_core.snapshot();
|
||||
let snapshot = runtime_core_for_commands.snapshot();
|
||||
match snapshot.read() {
|
||||
Ok(s) => Some(to_ui_snapshot(&s)),
|
||||
Err(_) => None,
|
||||
}
|
||||
};
|
||||
if let Some(value) = payload {
|
||||
let _ = app_handle.emit("runtime:snapshot", value);
|
||||
let _ = app_handle_for_commands.emit("runtime:snapshot", value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
let runtime_core = Arc::clone(&runtime_core);
|
||||
let app_handle = app_handle.clone();
|
||||
window.on_window_event(move |event| {
|
||||
if let tauri::WindowEvent::Moved(position) = event {
|
||||
let command = sprimo_protocol::v1::FrontendCommand::SetTransform {
|
||||
x: Some(position.x as f32),
|
||||
y: Some(position.y as f32),
|
||||
anchor: None,
|
||||
scale: None,
|
||||
opacity: None,
|
||||
};
|
||||
if runtime_core.apply_command(&command).is_ok() {
|
||||
if let Ok(snapshot) = runtime_core.snapshot().read() {
|
||||
let _ = app_handle.emit("runtime:snapshot", to_ui_snapshot(&snapshot));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let _ = app;
|
||||
Ok(())
|
||||
})
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
"windows": [
|
||||
{
|
||||
"title": "sprimo-tauri",
|
||||
"width": 640,
|
||||
"height": 640,
|
||||
"width": 416,
|
||||
"height": 416,
|
||||
"decorations": false,
|
||||
"transparent": true,
|
||||
"alwaysOnTop": true,
|
||||
|
||||
Reference in New Issue
Block a user