mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-08 08:52:12 +00:00
Solarized Light/Dark and One Light/Dark ship as theme plugins (plugins/theme-solarized, plugins/theme-one) with complete UI tokens, editor schemes and terminal colours, and the original palettes' MIT notices. Installing a plugin now also copies its LICENSE/NOTICE/COPYING. Theme handling that benefits every plugin theme: - The last plugin theme is restored before first paint (splash, workbench); the native window background follows the theme. - HSL / color-mix() / var() colours are resolved to RGB for native windows, the Settings window and Mermaid. - Mermaid, the terminal and editor schemes follow switches between two themes of the same kind. - An explicitly chosen editor scheme wins over a plugin theme's editor colours. Supersedes #85. Co-authored-by: bghtyu <[email protected]> Claude-Session: https://claude.ai/code/session_01VUYsdXA2nkF5v6zsC93dpn
39 lines
1.9 KiB
JavaScript
39 lines
1.9 KiB
JavaScript
/* global document, localStorage, window */
|
|
// Runs before the app's CSS loads: restores the last theme (theme.ts stores it)
|
|
// so a new window starts in it instead of flashing the light default.
|
|
// An external file because the CSP forbids inline scripts.
|
|
try {
|
|
const root = document.documentElement;
|
|
const addStyle = (id, css) => {
|
|
const style = document.createElement("style");
|
|
style.id = id;
|
|
style.textContent = css;
|
|
document.head.appendChild(style);
|
|
};
|
|
const last = JSON.parse(localStorage.getItem("openidea.theme") ?? "null");
|
|
if (last?.theme) root.dataset.theme = last.theme;
|
|
if (last?.contrast) root.dataset.contrast = last.contrast;
|
|
// A plugin theme's stylesheet (plugins/bridge.ts), so the workbench doesn't
|
|
// show the built-in theme until the plugin host answers.
|
|
const plugin = JSON.parse(localStorage.getItem("openidea.pluginTheme") ?? "null");
|
|
if (typeof plugin?.id === "string" && typeof plugin.css === "string" && !/[<\\]|url\(/i.test(plugin.css)) {
|
|
addStyle("openidea-plugin-theme", plugin.css);
|
|
root.dataset.pluginTheme = plugin.id;
|
|
root.dataset.pluginThemeKind = root.dataset.theme = plugin.kind === "light" ? "light" : "dark";
|
|
delete root.dataset.contrast;
|
|
}
|
|
// The splash's frame, text and accent colours, resolved by theme.ts (splash.css).
|
|
const colors = [
|
|
["--boot-frame", last?.frame],
|
|
["--boot-fg", last?.fg],
|
|
["--boot-accent", last?.accent],
|
|
].filter(([, v]) => typeof v === "string" && /^#[0-9a-f]{3,8}$/i.test(v));
|
|
if (colors.length) addStyle("openidea-boot-colors", `:root { ${colors.map(([k, v]) => `${k}: ${v};`).join(" ")} }`);
|
|
} catch {
|
|
/* storage unavailable */
|
|
}
|
|
// Settings windows (`settings-<parent>`) load this page too: splash.css drops the logo for them.
|
|
if (window.__TAURI_INTERNALS__?.metadata?.currentWindow?.label?.startsWith("settings-")) {
|
|
document.documentElement.dataset.window = "settings";
|
|
}
|