1
0
mirror of https://github.com/0O0o0oOoO00/Alas.git synced 2026-05-22 03:29:28 +08:00
Files
Alas/webapp/packages/renderer/src/settings/themeSetting.ts

33 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-04-24 11:35:20 +08:00
import type {ThemeVal} from '/#/config';
export function setupThemeSetting(theme?: ThemeVal) {
2023-04-25 18:55:23 +08:00
if (!theme && window.matchMedia('(prefers-color-scheme: dark)').matches) {
setTheme('dark');
return;
} else if (!theme && !window.matchMedia('(prefers-color-scheme: dark)').matches) {
setTheme('light');
return;
}
if (theme && theme === 'dark') {
setTheme('dark');
window.__electron_preload__ipcRendererSend('electron-theme', 'dark');
} else {
setTheme('light');
window.__electron_preload__ipcRendererSend('electron-theme', 'light');
}
}
function setTheme(theme: ThemeVal) {
if (theme === 'dark') {
document.documentElement.classList.remove('light');
document.documentElement.classList.add('dark');
// Set to dark theme
document.body.setAttribute('arco-theme', 'dark');
} else {
document.documentElement.classList.remove('dark');
document.documentElement.classList.add('light');
// Restore the light color theme
document.body.setAttribute('arco-theme', 'light');
}
}