mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-05 05:39:33 +08:00
fix(desktop): sync macOS shell colors with the app theme
This commit is contained in:
@@ -108,6 +108,7 @@ function coreVersion() {
|
||||
}
|
||||
|
||||
function currentChromeBackground() {
|
||||
if (process.platform === 'darwin') return ui.theme === 'dark' ? '#202023' : '#f5f5f7';
|
||||
if (!WINDOWS) return ui.theme === 'dark' ? '#161618' : '#ffffff';
|
||||
return ui.chromeBg || PALETTE_BACKGROUND[ui.palette] || PALETTE_BACKGROUND.snow;
|
||||
}
|
||||
@@ -172,10 +173,20 @@ function resolveChromeTheme(preference) {
|
||||
return palette === 'dark' || palette === 'glass' ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
function resolveMacTheme(preference) {
|
||||
const source = preference === 'system' ? 'system' : resolveChromeTheme(preference);
|
||||
if (nativeTheme.themeSource !== source) nativeTheme.themeSource = source;
|
||||
return nativeTheme.shouldUseDarkColors ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
async function readInterface() {
|
||||
let saved;
|
||||
try { saved = await readJSON(interfaceFile) ?? {}; }
|
||||
catch { return ui; } // A half-written or hand-edited file keeps the current choice.
|
||||
if (process.platform === 'darwin') {
|
||||
const themePreference = normalizeThemePreference(saved.theme);
|
||||
return { ...ui, language: resolveLanguage(saved.language), themePreference, theme: resolveMacTheme(themePreference) };
|
||||
}
|
||||
if (!WINDOWS) {
|
||||
const dark = saved.theme === 'dark' || (saved.theme === 'system' && nativeTheme.shouldUseDarkColors);
|
||||
return { ...ui, language: resolveLanguage(saved.language), theme: dark ? 'dark' : 'light' };
|
||||
@@ -205,7 +216,10 @@ function applyThemeChrome() {
|
||||
}
|
||||
|
||||
async function refreshInterface() {
|
||||
const next = await readInterface();
|
||||
updateInterface(await readInterface());
|
||||
}
|
||||
|
||||
function updateInterface(next) {
|
||||
const paletteChanged = next.palette !== ui.palette;
|
||||
if (
|
||||
next.language === ui.language
|
||||
@@ -360,8 +374,8 @@ async function applyLanguagePreference(nextLanguage) {
|
||||
|
||||
async function applyThemePreference(nextPreference) {
|
||||
const themePreference = normalizeThemePreference(nextPreference);
|
||||
const theme = process.platform === 'darwin' ? resolveMacTheme(themePreference) : resolveChromeTheme(themePreference);
|
||||
const palette = resolvePalette(themePreference);
|
||||
const theme = resolveChromeTheme(themePreference);
|
||||
ui = { ...ui, themePreference, palette, theme, chromeBg: null };
|
||||
buildMenu();
|
||||
applyThemeChrome();
|
||||
@@ -858,7 +872,14 @@ else {
|
||||
// at module scope or the packaged application deadlocks before its first window.
|
||||
app.whenReady().then(async () => {
|
||||
ui = await readInterface();
|
||||
nativeTheme.on('updated', () => void refreshInterface());
|
||||
nativeTheme.on('updated', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
void refreshInterface();
|
||||
} else if (ui.themePreference === 'system' && nativeTheme.themeSource === 'system') {
|
||||
// An appearance event can also come from setting themeSource before the preference is saved.
|
||||
updateInterface({ ...ui, theme: nativeTheme.shouldUseDarkColors ? 'dark' : 'light' });
|
||||
}
|
||||
});
|
||||
const coreSession = session.fromPartition('persist:deeptutor');
|
||||
// The web UI reads this marker to name the client, e.g. "Open DeepTutor for MacOS with Apple Silicon".
|
||||
coreSession.setUserAgent(`${coreSession.getUserAgent()} ${agentMarker(app.getVersion())}`);
|
||||
|
||||
@@ -139,10 +139,10 @@ function apply(state) {
|
||||
root.dataset.theme = state.theme || 'light';
|
||||
root.dataset.phase = phase;
|
||||
root.dataset.content = state.contentVisible ? 'visible' : 'hidden';
|
||||
if (state.chromeBg) root.style.setProperty('--bg', state.chromeBg);
|
||||
else root.style.removeProperty('--bg');
|
||||
if (window.desktop.platform === 'win32') {
|
||||
root.dataset.palette = state.palette;
|
||||
if (state.chromeBg) root.style.setProperty('--bg', state.chromeBg);
|
||||
else root.style.removeProperty('--bg');
|
||||
renderMenus(state.menus);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user