mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
feat(themes): warn about animated themes on high-CPU setups (#1020)
* feat(themes): warn about animated themes on high-CPU setups Show a warning icon + tooltip on animated themes (those defining @keyframes) in the store and in Your Themes, on Linux setups where animation is costly — the Nvidia WebKit quirk is active or compositing is forced off. The Nvidia detection already runs once at startup; its result is recorded (theme_animation.rs) and read via a new theme_animation_risk command — no GPU re-probe. Display-only; never shown off Linux. The animated flag comes from the registry (store) or the theme CSS (Your Themes). * docs(themes): note the animated-theme warning PR in the Theme Store entry
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { IS_LINUX } from '../utils/platform';
|
||||
|
||||
/**
|
||||
* Whether animated themes may raise CPU load on this setup — Linux with the
|
||||
* Nvidia WebKit quirk active (recorded at startup) or compositing forced off.
|
||||
* The store / theme cards show a warning on animated themes when this is true.
|
||||
*
|
||||
* Fetched once and cached for the process (read-once, per the Tauri-boundary
|
||||
* rule). Always false off Linux, so the `invoke` is skipped there.
|
||||
*/
|
||||
let cached: boolean | null = null;
|
||||
|
||||
export function useThemeAnimationRisk(): boolean {
|
||||
const [risk, setRisk] = useState(cached ?? false);
|
||||
|
||||
useEffect(() => {
|
||||
if (cached !== null) {
|
||||
setRisk(cached);
|
||||
return;
|
||||
}
|
||||
if (!IS_LINUX) {
|
||||
cached = false;
|
||||
return;
|
||||
}
|
||||
let alive = true;
|
||||
const p = invoke<boolean>('theme_animation_risk');
|
||||
// Guard the mocked-in-tests case where invoke isn't a real promise.
|
||||
if (p && typeof (p as Promise<boolean>).then === 'function') {
|
||||
(p as Promise<boolean>)
|
||||
.then((v) => {
|
||||
cached = !!v;
|
||||
if (alive) setRisk(cached);
|
||||
})
|
||||
.catch(() => {
|
||||
cached = false;
|
||||
});
|
||||
}
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return risk;
|
||||
}
|
||||
Reference in New Issue
Block a user