use std::sync::Arc;
use services_core::AppPathsProvider;
use crate::prefs::UserPrefs;
use super::{FRAME_BUDGET, HW_KEEPALIVE_INTERVAL};
pub(super) struct FramePacer {
pub(super) renderer_keepalive: bool,
pub(super) focused: bool,
pub(super) last_input: web_time::Instant,
pub(super) last_frame: web_time::Instant,
pub(super) last_tick: web_time::Instant,
pub(super) last_submit: web_time::Instant,
}
impl Default for FramePacer {
fn default() -> Self {
let now = web_time::Instant::now();
Self {
renderer_keepalive: false,
focused: true,
last_input: now,
last_frame: now,
last_tick: now.checked_sub(FRAME_BUDGET).unwrap_or(now),
last_submit: now.checked_sub(HW_KEEPALIVE_INTERVAL).unwrap_or(now),
}
}
}
pub(super) struct AppEnv {
pub(super) app_name: String,
pub(super) paths: Arc<dyn AppPathsProvider>,
pub(super) prefs: UserPrefs,
}
impl AppEnv {
pub(super) fn save_prefs(&self) {
if let Err(e) = self.prefs.save(&self.app_name, self.paths.as_ref()) {
tracing::warn!("failed to save prefs: {e}");
}
}
}