Files
AtreidesAssetsFree/client/ui/blur.js
T

56 lines
1.7 KiB
JavaScript
Raw Normal View History

2026-10-29 11:57:29 +01:00
// Generated, do not edit. sha256:3f4bf112e28f009a738272dd18bef14d5e6736a31c2f3e1f6e434733f909d6ea
import { appSetting, setAppSetting } from '../app-settings.js';
import { t } from '../i18n/index.js';
import { EYE, EYE_OFF } from './icons.js';
import { CONFIG } from '../../shared/config.js';
let idleTimer = null;
let btn = null;
function isOn() { return appSetting('blur') === 1; }
export const isBlurred = () => isOn();
export const unblur = () => setOn(false);
function apply(on) {
document.documentElement.dataset.blur = on ? 'on' : 'off';
if (btn) {
btn.innerHTML = on ? EYE_OFF : EYE;
btn.classList.toggle('is-on', on);
}
document.dispatchEvent(new CustomEvent('blur-changed', { detail: { on } }));
}
function armIdle() {
clearTimeout(idleTimer);
const min = appSetting('auto_blur_min');
if (min >= CONFIG.AUTO_BLUR.NEVER_MIN) return;
idleTimer = setTimeout(() => { setOn(true); }, min * 60 * 1000);
}
async function setOn(on) {
apply(on);
try { await setAppSetting('blur', on ? 1 : 0); } catch { }
if (on) clearTimeout(idleTimer); else armIdle();
}
function onActivity() { if (!isOn()) armIdle(); }
export function initPrivacyBlur(hostEl) {
btn = document.createElement('button');
btn.type = 'button';
btn.className = 'statusbar-eye';
btn.title = t('blur.toggle');
btn.setAttribute('aria-label', t('blur.toggle'));
btn.onclick = () => { setOn(!isOn()); };
hostEl.appendChild(btn);
apply(isOn());
armIdle();
for (const ev of ['pointerdown', 'keydown', 'wheel', 'touchstart']) {
document.addEventListener(ev, onActivity, { passive: true });
}
document.addEventListener('settings-changed', () => { if (!isOn()) armIdle(); });
}