mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-10 09:49:34 +08:00
🎨 工作空间多开,主题设置互补干扰
This commit is contained in:
parent
af2d3ade5e
commit
19b7e3aad6
@ -20,7 +20,6 @@ const {
|
|||||||
shell,
|
shell,
|
||||||
Menu,
|
Menu,
|
||||||
screen,
|
screen,
|
||||||
nativeTheme,
|
|
||||||
ipcMain,
|
ipcMain,
|
||||||
globalShortcut,
|
globalShortcut,
|
||||||
Tray,
|
Tray,
|
||||||
@ -642,9 +641,6 @@ app.whenReady().then(() => {
|
|||||||
}
|
}
|
||||||
mainWindow.focus()
|
mainWindow.focus()
|
||||||
})
|
})
|
||||||
ipcMain.on('siyuan-config-theme', (event, theme) => {
|
|
||||||
nativeTheme.themeSource = theme
|
|
||||||
})
|
|
||||||
ipcMain.on('siyuan-config-tray', (event, data) => {
|
ipcMain.on('siyuan-config-tray', (event, data) => {
|
||||||
workspaces.find(item => {
|
workspaces.find(item => {
|
||||||
if (item.id === data.id) {
|
if (item.id === data.id) {
|
||||||
|
@ -188,18 +188,22 @@ export const appearance = {
|
|||||||
nativeEmoji: (appearance.element.querySelector("#nativeEmoji") as HTMLInputElement).checked,
|
nativeEmoji: (appearance.element.querySelector("#nativeEmoji") as HTMLInputElement).checked,
|
||||||
hideStatusBar: (appearance.element.querySelector("#hideStatusBar") as HTMLInputElement).checked,
|
hideStatusBar: (appearance.element.querySelector("#hideStatusBar") as HTMLInputElement).checked,
|
||||||
}, response => {
|
}, response => {
|
||||||
if ((
|
if (window.siyuan.config.appearance.themeJS) {
|
||||||
window.siyuan.config.appearance.themeJS &&
|
if (!response.data.modeOS && (
|
||||||
(
|
response.data.mode !== window.siyuan.config.appearance.mode ||
|
||||||
response.data.mode !== window.siyuan.config.appearance.mode ||
|
window.siyuan.config.appearance.themeLight !== response.data.themeLight ||
|
||||||
window.siyuan.config.appearance.themeLight !== response.data.themeLight ||
|
window.siyuan.config.appearance.themeDark !== response.data.themeDark
|
||||||
window.siyuan.config.appearance.themeDark !== response.data.themeDark
|
)) {
|
||||||
)
|
exportLayout(true);
|
||||||
) ||
|
return;
|
||||||
(response.data.modeOS && !window.siyuan.config.appearance.modeOS)
|
}
|
||||||
) {
|
const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
||||||
exportLayout(true);
|
if (response.data.modeOS && (
|
||||||
return;
|
(response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark")
|
||||||
|
)) {
|
||||||
|
exportLayout(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
appearance.onSetappearance(response.data);
|
appearance.onSetappearance(response.data);
|
||||||
if (response.data.hideStatusBar) {
|
if (response.data.hideStatusBar) {
|
||||||
@ -244,7 +248,7 @@ export const appearance = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onSetappearance(data: IAppearance, needLoadAsset = true) {
|
onSetappearance(data: IAppearance) {
|
||||||
if (data.lang !== window.siyuan.config.appearance.lang || data.nativeEmoji !== window.siyuan.config.appearance.nativeEmoji) {
|
if (data.lang !== window.siyuan.config.appearance.lang || data.nativeEmoji !== window.siyuan.config.appearance.nativeEmoji) {
|
||||||
exportLayout(true);
|
exportLayout(true);
|
||||||
return;
|
return;
|
||||||
@ -272,12 +276,7 @@ export const appearance = {
|
|||||||
iconElement.innerHTML = genOptions(window.siyuan.config.appearance.icons, window.siyuan.config.appearance.icon);
|
iconElement.innerHTML = genOptions(window.siyuan.config.appearance.icons, window.siyuan.config.appearance.icon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// #if !BROWSER
|
loadAssets(data);
|
||||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_THEME, data.modeOS ? "system" : (data.mode === 1 ? "dark" : "light"));
|
|
||||||
/// #endif
|
|
||||||
if (needLoadAsset) {
|
|
||||||
loadAssets(data);
|
|
||||||
}
|
|
||||||
document.querySelector("#barMode use").setAttribute("xlink:href", `#icon${window.siyuan.config.appearance.modeOS ? "Mode" : (window.siyuan.config.appearance.mode === 0 ? "Light" : "Dark")}`);
|
document.querySelector("#barMode use").setAttribute("xlink:href", `#icon${window.siyuan.config.appearance.modeOS ? "Mode" : (window.siyuan.config.appearance.mode === 0 ? "Light" : "Dark")}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,6 @@ export abstract class Constants {
|
|||||||
|
|
||||||
// 渲染进程调主进程
|
// 渲染进程调主进程
|
||||||
public static readonly SIYUAN_SHOW: string = "siyuan-show";
|
public static readonly SIYUAN_SHOW: string = "siyuan-show";
|
||||||
public static readonly SIYUAN_CONFIG_THEME: string = "siyuan-config-theme";
|
|
||||||
public static readonly SIYUAN_CONFIG_TRAY: string = "siyuan-config-tray";
|
public static readonly SIYUAN_CONFIG_TRAY: string = "siyuan-config-tray";
|
||||||
public static readonly SIYUAN_OPEN_WORKSPACE: string = "siyuan-open-workspace";
|
public static readonly SIYUAN_OPEN_WORKSPACE: string = "siyuan-open-workspace";
|
||||||
public static readonly SIYUAN_QUIT: string = "siyuan-quit";
|
public static readonly SIYUAN_QUIT: string = "siyuan-quit";
|
||||||
|
@ -2,12 +2,12 @@ import {Constants} from "../constants";
|
|||||||
import {addScript} from "../protyle/util/addScript";
|
import {addScript} from "../protyle/util/addScript";
|
||||||
import {addStyle} from "../protyle/util/addStyle";
|
import {addStyle} from "../protyle/util/addStyle";
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
import {ipcRenderer} from "electron";
|
|
||||||
import {getAllModels} from "../layout/getAll";
|
import {getAllModels} from "../layout/getAll";
|
||||||
import {exportLayout} from "../layout/util";
|
import {exportLayout} from "../layout/util";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {isBrowser, isMobile} from "./functions";
|
import {isMobile} from "./functions";
|
||||||
import {fetchPost} from "./fetch";
|
import {fetchPost} from "./fetch";
|
||||||
|
import {appearance} from "../config/appearance";
|
||||||
|
|
||||||
const loadThirdIcon = (iconURL: string, data: IAppearance) => {
|
const loadThirdIcon = (iconURL: string, data: IAppearance) => {
|
||||||
addScript(iconURL, "iconDefaultScript").then(() => {
|
addScript(iconURL, "iconDefaultScript").then(() => {
|
||||||
@ -22,6 +22,15 @@ const loadThirdIcon = (iconURL: string, data: IAppearance) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const loadAssets = (data: IAppearance) => {
|
export const loadAssets = (data: IAppearance) => {
|
||||||
|
const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
||||||
|
if (window.siyuan.config.appearance.modeOS && (
|
||||||
|
(window.siyuan.config.appearance.mode === 1 && OSTheme === "light") ||
|
||||||
|
(window.siyuan.config.appearance.mode === 0 && OSTheme === "dark")
|
||||||
|
)) {
|
||||||
|
fetchPost("/api/system/setAppearanceMode", {mode: OSTheme === "light" ? 0 : 1});
|
||||||
|
window.siyuan.config.appearance.mode = (OSTheme === "light" ? 0 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
const defaultStyleElement = document.getElementById("themeDefaultStyle");
|
const defaultStyleElement = document.getElementById("themeDefaultStyle");
|
||||||
let defaultThemeAddress = `/appearance/themes/${data.mode === 1 ? "midnight" : "daylight"}/${data.customCSS ? "custom" : "theme"}.css?v=${data.customCSS ? new Date().getTime() : Constants.SIYUAN_VERSION}`;
|
let defaultThemeAddress = `/appearance/themes/${data.mode === 1 ? "midnight" : "daylight"}/${data.customCSS ? "custom" : "theme"}.css?v=${data.customCSS ? new Date().getTime() : Constants.SIYUAN_VERSION}`;
|
||||||
if ((data.mode === 1 && data.themeDark !== "midnight") || (data.mode === 0 && data.themeLight !== "daylight")) {
|
if ((data.mode === 1 && data.themeDark !== "midnight") || (data.mode === 0 && data.themeLight !== "daylight")) {
|
||||||
@ -115,9 +124,31 @@ export const initAssets = () => {
|
|||||||
loadingElement.remove();
|
loadingElement.remove();
|
||||||
}, 160);
|
}, 160);
|
||||||
}
|
}
|
||||||
watchTheme({init: true, OSTheme: window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"});
|
updateMobileTheme(window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
|
||||||
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", event => {
|
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", event => {
|
||||||
watchTheme({init: false, OSTheme: event.matches ? "dark" : "light"});
|
const OSTheme = event.matches ? "dark" : "light"
|
||||||
|
updateMobileTheme(OSTheme);
|
||||||
|
if (!window.siyuan.config.appearance.modeOS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((window.siyuan.config.appearance.mode === 0 && OSTheme === "light") ||
|
||||||
|
(window.siyuan.config.appearance.mode === 1 && OSTheme === "dark")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fetchPost("/api/system/setAppearanceMode", {
|
||||||
|
mode: OSTheme === "light" ? 0 : 1
|
||||||
|
}, response => {
|
||||||
|
if (window.siyuan.config.appearance.themeJS) {
|
||||||
|
/// #if !MOBILE
|
||||||
|
exportLayout(true);
|
||||||
|
/// #else
|
||||||
|
window.location.reload();
|
||||||
|
/// #endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.siyuan.config.appearance = response.data.appearance;
|
||||||
|
loadAssets(response.data.appearance);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -218,38 +249,36 @@ export const setMode = (modeElementValue: number) => {
|
|||||||
mode: modeElementValue === 2 ? window.siyuan.config.appearance.mode : modeElementValue,
|
mode: modeElementValue === 2 ? window.siyuan.config.appearance.mode : modeElementValue,
|
||||||
modeOS: modeElementValue === 2,
|
modeOS: modeElementValue === 2,
|
||||||
}), response => {
|
}), response => {
|
||||||
if ((
|
if (window.siyuan.config.appearance.themeJS) {
|
||||||
window.siyuan.config.appearance.themeJS && !response.data.modeOS &&
|
if (!response.data.modeOS && (
|
||||||
(
|
response.data.mode !== window.siyuan.config.appearance.mode ||
|
||||||
response.data.mode !== window.siyuan.config.appearance.mode ||
|
window.siyuan.config.appearance.themeLight !== response.data.themeLight ||
|
||||||
window.siyuan.config.appearance.themeLight !== response.data.themeLight ||
|
window.siyuan.config.appearance.themeDark !== response.data.themeDark
|
||||||
window.siyuan.config.appearance.themeDark !== response.data.themeDark
|
)) {
|
||||||
)
|
exportLayout(true);
|
||||||
) ||
|
return;
|
||||||
// Electron 中 ipcRenderer 会触发 nativeTheme.themeSource 从而触发 window.matchMedia 中的 watchTheme
|
}
|
||||||
(response.data.modeOS && !window.siyuan.config.appearance.modeOS && isBrowser())
|
const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
||||||
) {
|
if (response.data.modeOS && (
|
||||||
exportLayout(true);
|
(response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark")
|
||||||
return;
|
)) {
|
||||||
|
exportLayout(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
window.siyuan.config.appearance = response.data;
|
appearance.onSetappearance(response.data);
|
||||||
/// #if !BROWSER
|
|
||||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_THEME, response.data.modeOS ? "system" : (response.data.mode === 1 ? "dark" : "light"));
|
|
||||||
/// #endif
|
|
||||||
loadAssets(response.data);
|
|
||||||
document.querySelector("#barMode use").setAttribute("xlink:href", `#icon${window.siyuan.config.appearance.modeOS ? "Mode" : (window.siyuan.config.appearance.mode === 0 ? "Light" : "Dark")}`);
|
|
||||||
});
|
});
|
||||||
/// #endif
|
/// #endif
|
||||||
};
|
};
|
||||||
|
|
||||||
const watchTheme = (data: { init: boolean, OSTheme: string }) => {
|
const updateMobileTheme = (OSTheme: string) => {
|
||||||
if ((window.siyuan.config.system.container === "ios" && window.webkit?.messageHandlers) ||
|
if ((window.siyuan.config.system.container === "ios" && window.webkit?.messageHandlers) ||
|
||||||
(window.siyuan.config.system.container === "android" && window.JSAndroid)) {
|
(window.siyuan.config.system.container === "android" && window.JSAndroid)) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const backgroundColor = getComputedStyle(document.body).getPropertyValue("--b3-theme-background");
|
const backgroundColor = getComputedStyle(document.body).getPropertyValue("--b3-theme-background");
|
||||||
let mode = window.siyuan.config.appearance.mode;
|
let mode = window.siyuan.config.appearance.mode;
|
||||||
if (window.siyuan.config.appearance.modeOS) {
|
if (window.siyuan.config.appearance.modeOS) {
|
||||||
if (data.OSTheme === "dark") {
|
if (OSTheme === "dark") {
|
||||||
mode = 1;
|
mode = 1;
|
||||||
} else {
|
} else {
|
||||||
mode = 0;
|
mode = 0;
|
||||||
@ -262,41 +291,4 @@ const watchTheme = (data: { init: boolean, OSTheme: string }) => {
|
|||||||
}
|
}
|
||||||
}, 500); // 移动端需要加载完才可以获取到颜色
|
}, 500); // 移动端需要加载完才可以获取到颜色
|
||||||
}
|
}
|
||||||
if (data.init) {
|
|
||||||
if (window.siyuan.config.appearance.modeOS && (
|
|
||||||
(window.siyuan.config.appearance.mode === 1 && data.OSTheme === "light") ||
|
|
||||||
(window.siyuan.config.appearance.mode === 0 && data.OSTheme === "dark")
|
|
||||||
)) {
|
|
||||||
fetchPost("/api/system/setAppearanceMode", {
|
|
||||||
mode: data.OSTheme === "light" ? 0 : 1
|
|
||||||
}, response => {
|
|
||||||
window.siyuan.config.appearance = response.data.appearance;
|
|
||||||
loadAssets(response.data.appearance);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
loadAssets(window.siyuan.config.appearance);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!window.siyuan.config.appearance.modeOS) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ((window.siyuan.config.appearance.mode === 0 && data.OSTheme === "light") ||
|
|
||||||
(window.siyuan.config.appearance.mode === 1 && data.OSTheme === "dark")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fetchPost("/api/system/setAppearanceMode", {
|
|
||||||
mode: data.OSTheme === "light" ? 0 : 1
|
|
||||||
}, response => {
|
|
||||||
if (window.siyuan.config.appearance.themeJS) {
|
|
||||||
/// #if !MOBILE
|
|
||||||
exportLayout(true);
|
|
||||||
/// #else
|
|
||||||
window.location.reload();
|
|
||||||
/// #endif
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
window.siyuan.config.appearance = response.data.appearance;
|
|
||||||
loadAssets(response.data.appearance);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
@ -162,7 +162,7 @@ export const onGetConfig = (isStart: boolean) => {
|
|||||||
initBar();
|
initBar();
|
||||||
initStatus();
|
initStatus();
|
||||||
initWindow();
|
initWindow();
|
||||||
appearance.onSetappearance(window.siyuan.config.appearance, false);
|
appearance.onSetappearance(window.siyuan.config.appearance);
|
||||||
initAssets();
|
initAssets();
|
||||||
renderSnippet();
|
renderSnippet();
|
||||||
setInlineStyle();
|
setInlineStyle();
|
||||||
|
Loading…
Reference in New Issue
Block a user