Add: config for controlling debug overlay visibility of tauri
This commit is contained in:
@@ -158,12 +158,14 @@ pub enum FrontendBackend {
|
||||
#[serde(default)]
|
||||
pub struct FrontendConfig {
|
||||
pub backend: FrontendBackend,
|
||||
pub debug_overlay_visible: bool,
|
||||
}
|
||||
|
||||
impl Default for FrontendConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
backend: FrontendBackend::Bevy,
|
||||
debug_overlay_visible: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,10 +224,12 @@ mod tests {
|
||||
let mut config = AppConfig::default();
|
||||
config.window.x = 42.0;
|
||||
config.frontend.backend = super::FrontendBackend::Tauri;
|
||||
config.frontend.debug_overlay_visible = true;
|
||||
|
||||
save(&path, &config).expect("save");
|
||||
let (_, loaded) = load_or_create_at(&path).expect("reload");
|
||||
assert!((loaded.window.x - 42.0).abs() < f32::EPSILON);
|
||||
assert_eq!(loaded.frontend.backend, super::FrontendBackend::Tauri);
|
||||
assert!(loaded.frontend.debug_overlay_visible);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,28 @@ impl RuntimeCore {
|
||||
self.command_tx.clone()
|
||||
}
|
||||
|
||||
pub fn frontend_debug_overlay_visible(&self) -> Result<bool, RuntimeCoreError> {
|
||||
let guard = self
|
||||
.config
|
||||
.read()
|
||||
.map_err(|_| RuntimeCoreError::ConfigPoisoned)?;
|
||||
Ok(guard.frontend.debug_overlay_visible)
|
||||
}
|
||||
|
||||
pub fn set_frontend_debug_overlay_visible(
|
||||
&self,
|
||||
visible: bool,
|
||||
) -> Result<(), RuntimeCoreError> {
|
||||
{
|
||||
let mut guard = self
|
||||
.config
|
||||
.write()
|
||||
.map_err(|_| RuntimeCoreError::ConfigPoisoned)?;
|
||||
guard.frontend.debug_overlay_visible = visible;
|
||||
}
|
||||
self.persist_config()
|
||||
}
|
||||
|
||||
pub fn api_config(&self) -> ApiConfig {
|
||||
self.api_config.clone()
|
||||
}
|
||||
@@ -283,4 +305,14 @@ mod tests {
|
||||
let config = core.config().read().expect("config lock").clone();
|
||||
assert!(!config.window.click_through);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frontend_debug_overlay_visibility_roundtrips() {
|
||||
let temp = TempDir::new().expect("tempdir");
|
||||
let path = temp.path().join("config.toml");
|
||||
let core = RuntimeCore::new_with_config(path, AppConfig::default(), CapabilityFlags::default())
|
||||
.expect("core init");
|
||||
core.set_frontend_debug_overlay_visible(true).expect("set");
|
||||
assert!(core.frontend_debug_overlay_visible().expect("get"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +121,26 @@ fn load_active_sprite_pack(state: tauri::State<'_, AppState>) -> Result<UiSprite
|
||||
})
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn debug_overlay_visible(state: tauri::State<'_, AppState>) -> Result<bool, String> {
|
||||
state
|
||||
.runtime_core
|
||||
.frontend_debug_overlay_visible()
|
||||
.map_err(|err| err.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn set_debug_overlay_visible(
|
||||
state: tauri::State<'_, AppState>,
|
||||
visible: bool,
|
||||
) -> Result<bool, String> {
|
||||
state
|
||||
.runtime_core
|
||||
.set_frontend_debug_overlay_visible(visible)
|
||||
.map_err(|err| err.to_string())?;
|
||||
Ok(visible)
|
||||
}
|
||||
|
||||
fn main() -> Result<(), AppError> {
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter("sprimo=info")
|
||||
@@ -141,7 +161,12 @@ fn main() -> Result<(), AppError> {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
|
||||
.manage(state)
|
||||
.invoke_handler(tauri::generate_handler![current_state, load_active_sprite_pack])
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
current_state,
|
||||
load_active_sprite_pack,
|
||||
debug_overlay_visible,
|
||||
set_debug_overlay_visible
|
||||
])
|
||||
.setup(|app| {
|
||||
let app_state: tauri::State<'_, AppState> = app.state();
|
||||
let runtime_core = Arc::clone(&app_state.runtime_core);
|
||||
|
||||
Reference in New Issue
Block a user