Files
Clipboard/renderer/theme-boot.js
2026-09-12 13:59:12 +08:00

22 lines
954 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
/**
* 首屏主题预应用:在首次绘制前从 localStorage 读取上次的主题/强调色,
* 避免等 IPC 返回期间的白屏闪烁。
*
* 必须是「外部脚本」——页面 CSP 为 default-src 'self',未开 script-src 'unsafe-inline'
* 内联 <script> 会被直接拒绝执行。
*/
try {
const cached = JSON.parse(localStorage.getItem('clipboard-theme') || 'null');
if (cached) {
// 优先用 effectiveTheme「跟随系统」开时它就是上次实际显示的主题
// 直接套上去能省一次闪。旧版缓存里只有 theme旧版在 followSystem
// 开时存的是 raw会闪一下这里向后兼容。
const theme = cached.effectiveTheme || cached.theme;
if (theme) {
document.documentElement.setAttribute('data-theme', theme);
document.documentElement.setAttribute('data-accent', cached.accent || 'purple');
}
}
} catch (e) { /* 静默 */ }