mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 00:38:49 +01:00
This commit is contained in:
parent
7a7933d201
commit
67bca6c5bd
3 changed files with 29 additions and 31 deletions
|
|
@ -171,9 +171,10 @@ export const appearance = {
|
|||
const themeLight = (appearance.element.querySelector("#themeLight") as HTMLSelectElement).value;
|
||||
const themeDark = (appearance.element.querySelector("#themeDark") as HTMLSelectElement).value;
|
||||
const modeElementValue = parseInt((appearance.element.querySelector("#mode") as HTMLSelectElement).value);
|
||||
const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
||||
fetchPost("/api/setting/setAppearance", {
|
||||
icon: (appearance.element.querySelector("#icon") as HTMLSelectElement).value,
|
||||
mode: modeElementValue === 2 ? window.siyuan.config.appearance.mode : modeElementValue,
|
||||
mode: modeElementValue === 2 ? (OSTheme === "light" ? 0 : 1) : modeElementValue,
|
||||
modeOS: modeElementValue === 2,
|
||||
codeBlockThemeDark: (appearance.element.querySelector("#codeBlockThemeDark") as HTMLSelectElement).value,
|
||||
codeBlockThemeLight: (appearance.element.querySelector("#codeBlockThemeLight") as HTMLSelectElement).value,
|
||||
|
|
@ -187,19 +188,21 @@ export const appearance = {
|
|||
hideStatusBar: (appearance.element.querySelector("#hideStatusBar") as HTMLInputElement).checked,
|
||||
}, async response => {
|
||||
if (window.siyuan.config.appearance.themeJS) {
|
||||
if (window.destroyTheme) {
|
||||
try {
|
||||
await window.destroyTheme();
|
||||
window.destroyTheme = undefined;
|
||||
} catch (e) {
|
||||
console.error("destroyTheme error: " + e);
|
||||
}
|
||||
} else {
|
||||
if (!response.data.modeOS && (
|
||||
response.data.mode !== window.siyuan.config.appearance.mode ||
|
||||
window.siyuan.config.appearance.themeLight !== response.data.themeLight ||
|
||||
window.siyuan.config.appearance.themeDark !== response.data.themeDark
|
||||
)) {
|
||||
if (response.data.mode !== window.siyuan.config.appearance.mode ||
|
||||
(response.data.mode === window.siyuan.config.appearance.mode && (
|
||||
(response.data.mode === 0 && window.siyuan.config.appearance.themeLight !== response.data.themeLight) ||
|
||||
(response.data.mode === 1 && window.siyuan.config.appearance.themeDark !== response.data.themeDark))
|
||||
)
|
||||
) {
|
||||
if (window.destroyTheme) {
|
||||
try {
|
||||
await window.destroyTheme();
|
||||
window.destroyTheme = undefined;
|
||||
document.getElementById("themeScript").remove();
|
||||
} catch (e) {
|
||||
console.error("destroyTheme error: " + e);
|
||||
}
|
||||
} else {
|
||||
exportLayout({
|
||||
errorExit: false,
|
||||
cb() {
|
||||
|
|
@ -208,18 +211,6 @@ export const appearance = {
|
|||
});
|
||||
return;
|
||||
}
|
||||
const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
||||
if (response.data.modeOS && (
|
||||
(response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark")
|
||||
)) {
|
||||
exportLayout({
|
||||
cb() {
|
||||
window.location.reload();
|
||||
},
|
||||
errorExit: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
appearance.onSetappearance(response.data);
|
||||
|
|
|
|||
|
|
@ -685,6 +685,7 @@ export const bazaar = {
|
|||
try {
|
||||
await window.destroyTheme();
|
||||
window.destroyTheme = undefined;
|
||||
document.getElementById("themeScript").remove();
|
||||
} catch (e) {
|
||||
console.error("destroyTheme error: " + e);
|
||||
}
|
||||
|
|
@ -775,11 +776,11 @@ export const bazaar = {
|
|||
try {
|
||||
await window.destroyTheme();
|
||||
window.destroyTheme = undefined;
|
||||
document.getElementById("themeScript").remove();
|
||||
addScript(`/appearance/themes/${currentTheme}/theme.js?v=${response.data.appearance.themeVer}`, "themeScript");
|
||||
} catch (e) {
|
||||
console.error("destroyTheme error: " + e);
|
||||
}
|
||||
document.getElementById("themeScript").remove();
|
||||
addScript(`/appearance/themes/${currentTheme}/theme.js?v=${response.data.appearance.themeVer}`, "themeScript");
|
||||
} else {
|
||||
exportLayout({
|
||||
cb() {
|
||||
|
|
@ -869,6 +870,7 @@ export const bazaar = {
|
|||
try {
|
||||
await window.destroyTheme();
|
||||
window.destroyTheme = undefined;
|
||||
document.getElementById("themeScript").remove();
|
||||
} catch (e) {
|
||||
console.error("destroyTheme error: " + e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,10 +90,13 @@ export const loadAssets = (data: Config.IAppearance) => {
|
|||
const themeScriptElement = document.getElementById("themeScript");
|
||||
const themeScriptAddress = `/appearance/themes/${data.mode === 1 ? data.themeDark : data.themeLight}/theme.js?v=${data.themeVer}`;
|
||||
if (themeScriptElement) {
|
||||
// https://github.com/siyuan-note/siyuan/issues/10341
|
||||
themeScriptElement.remove();
|
||||
if (!themeScriptElement.getAttribute("src").startsWith(themeScriptAddress)) {
|
||||
themeScriptElement.remove();
|
||||
addScript(themeScriptAddress, "themeScript");
|
||||
}
|
||||
} else {
|
||||
addScript(themeScriptAddress, "themeScript");
|
||||
}
|
||||
addScript(themeScriptAddress, "themeScript");
|
||||
|
||||
const iconDefaultScriptElement = document.getElementById("iconDefaultScript");
|
||||
// 不能使用 data.iconVer,因为其他主题也需要加载默认图标,此时 data.iconVer 为其他图标的版本号
|
||||
|
|
@ -140,6 +143,7 @@ export const initAssets = () => {
|
|||
try {
|
||||
await window.destroyTheme();
|
||||
window.destroyTheme = undefined;
|
||||
document.getElementById("themeScript").remove();
|
||||
} catch (e) {
|
||||
console.error("destroyTheme error: " + e);
|
||||
}
|
||||
|
|
@ -382,6 +386,7 @@ export const setMode = (modeElementValue: number) => {
|
|||
try {
|
||||
await window.destroyTheme();
|
||||
window.destroyTheme = undefined;
|
||||
document.getElementById("themeScript").remove();
|
||||
} catch (e) {
|
||||
console.error("destroyTheme error: " + e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue