Add: global factor controlling fps base interval

This commit is contained in:
DaZuo0122
2026-02-15 09:40:51 +08:00
parent e5417b6799
commit f20ed1fd9d
12 changed files with 289 additions and 52 deletions

View File

@@ -8,6 +8,9 @@ use tokio::runtime::Runtime;
use tokio::sync::{mpsc, Mutex};
use tracing::warn;
const TAURI_ANIMATION_SLOWDOWN_FACTOR_MIN: u8 = 1;
const TAURI_ANIMATION_SLOWDOWN_FACTOR_MAX: u8 = 20;
#[derive(Debug, Error)]
pub enum RuntimeCoreError {
#[error("{0}")]
@@ -104,6 +107,32 @@ impl RuntimeCore {
self.persist_config()
}
pub fn frontend_tauri_animation_slowdown_factor(&self) -> Result<u8, RuntimeCoreError> {
let guard = self
.config
.read()
.map_err(|_| RuntimeCoreError::ConfigPoisoned)?;
Ok(clamp_tauri_animation_slowdown_factor(
guard.frontend.tauri_animation_slowdown_factor,
))
}
pub fn set_frontend_tauri_animation_slowdown_factor(
&self,
value: u8,
) -> Result<u8, RuntimeCoreError> {
let clamped = clamp_tauri_animation_slowdown_factor(value);
{
let mut guard = self
.config
.write()
.map_err(|_| RuntimeCoreError::ConfigPoisoned)?;
guard.frontend.tauri_animation_slowdown_factor = clamped;
}
self.persist_config()?;
Ok(clamped)
}
pub fn api_config(&self) -> ApiConfig {
self.api_config.clone()
}
@@ -257,6 +286,13 @@ fn default_animation_for_state(state: sprimo_protocol::v1::FrontendState) -> &'s
}
}
fn clamp_tauri_animation_slowdown_factor(value: u8) -> u8 {
value.clamp(
TAURI_ANIMATION_SLOWDOWN_FACTOR_MIN,
TAURI_ANIMATION_SLOWDOWN_FACTOR_MAX,
)
}
fn log_api_error(err: ApiServerError) {
warn!(%err, "runtime core api server exited");
}
@@ -331,4 +367,36 @@ mod tests {
core.set_frontend_debug_overlay_visible(true).expect("set");
assert!(core.frontend_debug_overlay_visible().expect("get"));
}
#[test]
fn frontend_tauri_animation_slowdown_factor_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");
let persisted = core
.set_frontend_tauri_animation_slowdown_factor(6)
.expect("set");
assert_eq!(persisted, 6);
assert_eq!(
core.frontend_tauri_animation_slowdown_factor().expect("get"),
6
);
}
#[test]
fn frontend_tauri_animation_slowdown_factor_clamps() {
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");
let persisted = core
.set_frontend_tauri_animation_slowdown_factor(0)
.expect("set");
assert_eq!(persisted, 1);
assert_eq!(
core.frontend_tauri_animation_slowdown_factor().expect("get"),
1
);
}
}