Vanessa 2024-01-28 23:50:23 +08:00
parent 2165596783
commit b839c2fbc3
3 changed files with 120 additions and 30 deletions

View file

@ -162,11 +162,40 @@ export const appearance = {
closeButtonBehavior: (appearance.element.querySelector("#closeButtonBehavior") as HTMLInputElement).checked ? 1 : 0,
hideStatusBar: (appearance.element.querySelector("#hideStatusBar") as HTMLInputElement).checked,
}, async response => {
if (window.siyuan.config.appearance.themeJS && window.destroyTheme) {
try {
await window.destroyTheme();
} catch (e) {
console.error("destroyTheme error: " + e);
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
)) {
exportLayout({
errorExit: false,
cb() {
window.location.reload();
},
});
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);

View file

@ -630,17 +630,21 @@ export const bazaar = {
if (window.destroyTheme) {
try {
await window.destroyTheme();
window.destroyTheme = undefined;
} catch (e) {
console.error("destroyTheme error: " + e);
}
}
window.siyuan.config.appearance.mode = dataObj.themeMode === "dark" ? 1 : 0;
if (dataObj.themeMode === "dark") {
window.siyuan.config.appearance.themeDark = dataObj.name;
window.siyuan.config.appearance = response.data.appearance
loadAssets(window.siyuan.config.appearance);
} else {
window.siyuan.config.appearance.themeLight = dataObj.name;
exportLayout({
cb() {
window.location.reload();
},
errorExit: false,
});
return;
}
loadAssets(window.siyuan.config.appearance);
}
bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));
bazaar._genMyHTML(bazaarType, app);
@ -698,13 +702,22 @@ export const bazaar = {
if (window.destroyTheme) {
try {
await window.destroyTheme();
window.destroyTheme = undefined;
} catch (e) {
console.error("destroyTheme error: " + e);
}
const themeScriptElement = document.getElementById("themeScript") as HTMLScriptElement;
themeScriptElement.remove();
addScript(themeScriptElement.src + "1", "themeScript");
} else {
exportLayout({
cb() {
window.location.reload();
},
errorExit: false,
});
return;
}
const themeScriptElement = document.getElementById("themeScript") as HTMLScriptElement;
themeScriptElement.remove();
addScript(themeScriptElement.src + "1", "themeScript");
}
const linkElement = (document.getElementById("themeDefaultStyle") as HTMLLinkElement);
linkElement.href = linkElement.href + "1";
@ -779,17 +792,21 @@ export const bazaar = {
if (window.destroyTheme) {
try {
await window.destroyTheme();
window.destroyTheme = undefined;
} catch (e) {
console.error("destroyTheme error: " + e);
}
}
window.siyuan.config.appearance.mode = mode;
if (mode === 1) {
window.siyuan.config.appearance.themeDark = dataObj.name;
window.siyuan.config.appearance = appearanceResponse.data
loadAssets(window.siyuan.config.appearance);
} else {
window.siyuan.config.appearance.themeLight = dataObj.name;
exportLayout({
cb() {
window.location.reload();
},
errorExit: false,
});
return;
}
loadAssets(window.siyuan.config.appearance);
}
this._genMyHTML("themes", app);
fetchPost("/api/bazaar/getBazaarTheme", {}, response => {

View file

@ -133,11 +133,26 @@ export const initAssets = () => {
fetchPost("/api/system/setAppearanceMode", {
mode: OSTheme === "light" ? 0 : 1
}, async response => {
if (window.siyuan.config.appearance.themeJS && window.destroyTheme) {
try {
await window.destroyTheme();
} catch (e) {
console.error("destroyTheme error: " + e);
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 !MOBILE
exportLayout({
cb() {
window.location.reload();
},
errorExit: false,
});
/// #else
window.location.reload();
/// #endif
return;
}
}
window.siyuan.config.appearance = response.data.appearance;
@ -256,11 +271,40 @@ export const setMode = (modeElementValue: number) => {
mode: modeElementValue === 2 ? window.siyuan.config.appearance.mode : modeElementValue,
modeOS: modeElementValue === 2,
}), async response => {
if (window.siyuan.config.appearance.themeJS && window.destroyTheme) {
try {
await window.destroyTheme();
} catch (e) {
console.error("destroyTheme error: " + e);
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
)) {
exportLayout({
cb() {
window.location.reload();
},
errorExit: false,
});
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);