Files
imeai-aKode/akode-rs/tui/src/system_motion.rs
andrea.difonzo 7c1c6dfa8d Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
  nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 12:37:52 +01:00

84 lines
2.7 KiB
Rust

//! Reads the TUI host's accessibility preference once at launch.
//!
//! Detection never changes persisted configuration or consults the app server. An unavailable
//! preference preserves configured behavior; an explicit request for less motion suppresses all
//! effects governed by `tui.animations`. Restart the TUI after changing the OS preference.
use std::sync::OnceLock;
use crate::motion::MotionMode;
static SYSTEM_MOTION: OnceLock<MotionMode> = OnceLock::new();
pub(crate) async fn initialize() {
let mode = detect().await.unwrap_or(MotionMode::Animated);
let _ = SYSTEM_MOTION.set(mode);
}
pub(crate) fn mode() -> MotionMode {
SYSTEM_MOTION.get().copied().unwrap_or(MotionMode::Animated)
}
#[cfg(target_os = "macos")]
async fn detect() -> Option<MotionMode> {
let workspace = objc2_app_kit::NSWorkspace::sharedWorkspace();
Some(if workspace.accessibilityDisplayShouldReduceMotion() {
MotionMode::Reduced
} else {
MotionMode::Animated
})
}
#[cfg(windows)]
async fn detect() -> Option<MotionMode> {
use windows_sys::Win32::UI::WindowsAndMessaging::SPI_GETCLIENTAREAANIMATION;
use windows_sys::Win32::UI::WindowsAndMessaging::SystemParametersInfoW;
let mut enabled: windows_sys::core::BOOL = 0;
// SAFETY: SPI_GETCLIENTAREAANIMATION writes one BOOL to this valid, aligned pointer.
let success = unsafe {
SystemParametersInfoW(
SPI_GETCLIENTAREAANIMATION,
/*uiparam*/ 0,
(&mut enabled as *mut windows_sys::core::BOOL).cast(),
/*fwinini*/ 0,
)
};
(success != 0).then(|| MotionMode::from_animations_enabled(enabled != 0))
}
#[cfg(target_os = "linux")]
async fn detect() -> Option<MotionMode> {
// A missing or unresponsive session bus must not hold up terminal startup.
tokio::time::timeout(std::time::Duration::from_millis(/*millis*/ 250), async {
let connection = zbus::Connection::session().await.ok()?;
let proxy = zbus::Proxy::new(
&connection,
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.Settings",
)
.await
.ok()?;
let value: zbus::zvariant::OwnedValue = proxy
.call("ReadOne", &("org.freedesktop.appearance", "reduced-motion"))
.await
.ok()?;
let value = u32::try_from(value).ok()?;
// The portal specifies that unknown values mean no preference.
Some(if value == 1 {
MotionMode::Reduced
} else {
MotionMode::Animated
})
})
.await
.ok()
.flatten()
}
#[cfg(not(any(target_os = "macos", target_os = "linux", windows)))]
async fn detect() -> Option<MotionMode> {
None
}