mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-19 10:30:45 +08:00
This commit is contained in:
parent
c76b1f3252
commit
28e8675a21
@ -161,32 +161,12 @@ export const appearance = {
|
|||||||
lang: (appearance.element.querySelector("#lang") as HTMLSelectElement).value,
|
lang: (appearance.element.querySelector("#lang") as HTMLSelectElement).value,
|
||||||
closeButtonBehavior: (appearance.element.querySelector("#closeButtonBehavior") as HTMLInputElement).checked ? 1 : 0,
|
closeButtonBehavior: (appearance.element.querySelector("#closeButtonBehavior") as HTMLInputElement).checked ? 1 : 0,
|
||||||
hideStatusBar: (appearance.element.querySelector("#hideStatusBar") as HTMLInputElement).checked,
|
hideStatusBar: (appearance.element.querySelector("#hideStatusBar") as HTMLInputElement).checked,
|
||||||
}, response => {
|
}, async response => {
|
||||||
if (window.siyuan.config.appearance.themeJS) {
|
if (window.siyuan.config.appearance.themeJS && window.destroyTheme) {
|
||||||
if (!response.data.modeOS && (
|
try {
|
||||||
response.data.mode !== window.siyuan.config.appearance.mode ||
|
await window.destroyTheme();
|
||||||
window.siyuan.config.appearance.themeLight !== response.data.themeLight ||
|
} catch (e) {
|
||||||
window.siyuan.config.appearance.themeDark !== response.data.themeDark
|
console.error("destroyTheme error: " + e);
|
||||||
)) {
|
|
||||||
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);
|
appearance.onSetappearance(response.data);
|
||||||
|
@ -17,6 +17,8 @@ import {App} from "../index";
|
|||||||
import {escapeAttr} from "../util/escape";
|
import {escapeAttr} from "../util/escape";
|
||||||
import {uninstall} from "../plugin/uninstall";
|
import {uninstall} from "../plugin/uninstall";
|
||||||
import {afterLoadPlugin, loadPlugin, loadPlugins} from "../plugin/loader";
|
import {afterLoadPlugin, loadPlugin, loadPlugins} from "../plugin/loader";
|
||||||
|
import {loadAssets} from "../util/assets";
|
||||||
|
import {addScript} from "../protyle/util/addScript";
|
||||||
|
|
||||||
export const bazaar = {
|
export const bazaar = {
|
||||||
element: undefined as Element,
|
element: undefined as Element,
|
||||||
@ -623,15 +625,22 @@ export const bazaar = {
|
|||||||
repoHash: dataObj.repoHash,
|
repoHash: dataObj.repoHash,
|
||||||
mode: dataObj.themeMode === "dark" ? 1 : 0,
|
mode: dataObj.themeMode === "dark" ? 1 : 0,
|
||||||
frontend: getFrontend()
|
frontend: getFrontend()
|
||||||
}, response => {
|
}, async response => {
|
||||||
if (window.siyuan.config.appearance.themeJS && bazaarType === "themes") {
|
if (window.siyuan.config.appearance.themeJS && bazaarType === "themes") {
|
||||||
exportLayout({
|
if (window.destroyTheme) {
|
||||||
cb() {
|
try {
|
||||||
window.location.reload();
|
await window.destroyTheme();
|
||||||
},
|
} catch (e) {
|
||||||
errorExit: false,
|
console.error("destroyTheme error: " + e);
|
||||||
});
|
}
|
||||||
return;
|
}
|
||||||
|
window.siyuan.config.appearance.mode = dataObj.themeMode === "dark" ? 1 : 0;
|
||||||
|
if (dataObj.themeMode === "dark") {
|
||||||
|
window.siyuan.config.appearance.themeDark = dataObj.name;
|
||||||
|
} else {
|
||||||
|
window.siyuan.config.appearance.themeLight = dataObj.name;
|
||||||
|
}
|
||||||
|
loadAssets(window.siyuan.config.appearance);
|
||||||
}
|
}
|
||||||
bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));
|
bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));
|
||||||
bazaar._genMyHTML(bazaarType, app);
|
bazaar._genMyHTML(bazaarType, app);
|
||||||
@ -676,7 +685,7 @@ export const bazaar = {
|
|||||||
mode: dataObj.themeMode === "dark" ? 1 : 0,
|
mode: dataObj.themeMode === "dark" ? 1 : 0,
|
||||||
update: true,
|
update: true,
|
||||||
frontend: getFrontend()
|
frontend: getFrontend()
|
||||||
}, response => {
|
}, async response => {
|
||||||
// 更新主题后不需要对该主题进行切换 https://github.com/siyuan-note/siyuan/issues/4966
|
// 更新主题后不需要对该主题进行切换 https://github.com/siyuan-note/siyuan/issues/4966
|
||||||
this._genMyHTML(bazaarType, app);
|
this._genMyHTML(bazaarType, app);
|
||||||
bazaar._onBazaar(response, bazaarType, ["icons"].includes(bazaarType));
|
bazaar._onBazaar(response, bazaarType, ["icons"].includes(bazaarType));
|
||||||
@ -686,17 +695,20 @@ export const bazaar = {
|
|||||||
(window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === dataObj.name)
|
(window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === dataObj.name)
|
||||||
)) {
|
)) {
|
||||||
if (window.siyuan.config.appearance.themeJS) {
|
if (window.siyuan.config.appearance.themeJS) {
|
||||||
exportLayout({
|
if (window.destroyTheme) {
|
||||||
cb() {
|
try {
|
||||||
window.location.reload();
|
await window.destroyTheme();
|
||||||
},
|
} catch (e) {
|
||||||
errorExit: false,
|
console.error("destroyTheme error: " + e);
|
||||||
});
|
}
|
||||||
} else {
|
}
|
||||||
|
const themeScriptElement = document.getElementById("themeScript") as HTMLScriptElement;
|
||||||
|
themeScriptElement.remove();
|
||||||
|
addScript(themeScriptElement.src + "1", "themeScript");
|
||||||
|
}
|
||||||
const linkElement = (document.getElementById("themeDefaultStyle") as HTMLLinkElement);
|
const linkElement = (document.getElementById("themeDefaultStyle") as HTMLLinkElement);
|
||||||
linkElement.href = linkElement.href + "1";
|
linkElement.href = linkElement.href + "1";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -759,25 +771,32 @@ export const bazaar = {
|
|||||||
modeOS: false,
|
modeOS: false,
|
||||||
themeDark: mode === 1 ? packageName : window.siyuan.config.appearance.themeDark,
|
themeDark: mode === 1 ? packageName : window.siyuan.config.appearance.themeDark,
|
||||||
themeLight: mode === 0 ? packageName : window.siyuan.config.appearance.themeLight,
|
themeLight: mode === 0 ? packageName : window.siyuan.config.appearance.themeLight,
|
||||||
}), (appearanceResponse) => {
|
}), async (appearanceResponse) => {
|
||||||
if ((mode !== window.siyuan.config.appearance.mode ||
|
if ((mode !== window.siyuan.config.appearance.mode ||
|
||||||
(mode === 1 && window.siyuan.config.appearance.themeDark !== packageName) ||
|
(mode === 1 && window.siyuan.config.appearance.themeDark !== packageName) ||
|
||||||
(mode === 0 && window.siyuan.config.appearance.themeLight !== packageName)) &&
|
(mode === 0 && window.siyuan.config.appearance.themeLight !== packageName)) &&
|
||||||
window.siyuan.config.appearance.themeJS) {
|
window.siyuan.config.appearance.themeJS) {
|
||||||
exportLayout({
|
if (window.destroyTheme) {
|
||||||
cb() {
|
try {
|
||||||
window.location.reload();
|
await window.destroyTheme();
|
||||||
},
|
} catch (e) {
|
||||||
errorExit: false,
|
console.error("destroyTheme error: " + e);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
window.siyuan.config.appearance.mode = mode;
|
||||||
|
if (mode === 1) {
|
||||||
|
window.siyuan.config.appearance.themeDark = dataObj.name;
|
||||||
} else {
|
} else {
|
||||||
|
window.siyuan.config.appearance.themeLight = dataObj.name;
|
||||||
|
}
|
||||||
|
loadAssets(window.siyuan.config.appearance);
|
||||||
|
}
|
||||||
this._genMyHTML("themes", app);
|
this._genMyHTML("themes", app);
|
||||||
fetchPost("/api/bazaar/getBazaarTheme", {}, response => {
|
fetchPost("/api/bazaar/getBazaarTheme", {}, response => {
|
||||||
response.data.appearance = appearanceResponse.data;
|
response.data.appearance = appearanceResponse.data;
|
||||||
bazaar._onBazaar(response, "themes", true);
|
bazaar._onBazaar(response, "themes", true);
|
||||||
bazaar._data.themes = response.data.packages;
|
bazaar._data.themes = response.data.packages;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
2
app/src/types/index.d.ts
vendored
2
app/src/types/index.d.ts
vendored
@ -183,6 +183,8 @@ interface Window {
|
|||||||
hideKeyboardToolbar(): void
|
hideKeyboardToolbar(): void
|
||||||
|
|
||||||
openFileByURL(URL: string): boolean
|
openFileByURL(URL: string): boolean
|
||||||
|
|
||||||
|
destroyTheme(): Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IPosition {
|
interface IPosition {
|
||||||
|
@ -37,10 +37,7 @@ export const loadAssets = (data: IAppearance) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const defaultStyleElement = document.getElementById("themeDefaultStyle");
|
const defaultStyleElement = document.getElementById("themeDefaultStyle");
|
||||||
let defaultThemeAddress = `/appearance/themes/${data.mode === 1 ? "midnight" : "daylight"}/theme.css?v=${Constants.SIYUAN_VERSION}`;
|
const defaultThemeAddress = `/appearance/themes/${data.mode === 1 ? "midnight" : "daylight"}/theme.css?v=${Constants.SIYUAN_VERSION}`;
|
||||||
if ((data.mode === 1 && data.themeDark !== "midnight") || (data.mode === 0 && data.themeLight !== "daylight")) {
|
|
||||||
defaultThemeAddress = `/appearance/themes/${data.mode === 1 ? "midnight" : "daylight"}/theme.css?v=${Constants.SIYUAN_VERSION}`;
|
|
||||||
}
|
|
||||||
if (defaultStyleElement) {
|
if (defaultStyleElement) {
|
||||||
if (!defaultStyleElement.getAttribute("href").startsWith(defaultThemeAddress)) {
|
if (!defaultStyleElement.getAttribute("href").startsWith(defaultThemeAddress)) {
|
||||||
defaultStyleElement.remove();
|
defaultStyleElement.remove();
|
||||||
@ -135,19 +132,13 @@ export const initAssets = () => {
|
|||||||
}
|
}
|
||||||
fetchPost("/api/system/setAppearanceMode", {
|
fetchPost("/api/system/setAppearanceMode", {
|
||||||
mode: OSTheme === "light" ? 0 : 1
|
mode: OSTheme === "light" ? 0 : 1
|
||||||
}, response => {
|
}, async response => {
|
||||||
if (window.siyuan.config.appearance.themeJS) {
|
if (window.siyuan.config.appearance.themeJS && window.destroyTheme) {
|
||||||
/// #if !MOBILE
|
try {
|
||||||
exportLayout({
|
await window.destroyTheme();
|
||||||
cb() {
|
} catch (e) {
|
||||||
window.location.reload();
|
console.error("destroyTheme error: " + e);
|
||||||
},
|
}
|
||||||
errorExit: false,
|
|
||||||
});
|
|
||||||
/// #else
|
|
||||||
window.location.reload();
|
|
||||||
/// #endif
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
window.siyuan.config.appearance = response.data.appearance;
|
window.siyuan.config.appearance = response.data.appearance;
|
||||||
loadAssets(response.data.appearance);
|
loadAssets(response.data.appearance);
|
||||||
@ -264,32 +255,12 @@ export const setMode = (modeElementValue: number) => {
|
|||||||
fetchPost("/api/setting/setAppearance", Object.assign({}, window.siyuan.config.appearance, {
|
fetchPost("/api/setting/setAppearance", Object.assign({}, window.siyuan.config.appearance, {
|
||||||
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 => {
|
}), async response => {
|
||||||
if (window.siyuan.config.appearance.themeJS) {
|
if (window.siyuan.config.appearance.themeJS && window.destroyTheme) {
|
||||||
if (!response.data.modeOS && (
|
try {
|
||||||
response.data.mode !== window.siyuan.config.appearance.mode ||
|
await window.destroyTheme();
|
||||||
window.siyuan.config.appearance.themeLight !== response.data.themeLight ||
|
} catch (e) {
|
||||||
window.siyuan.config.appearance.themeDark !== response.data.themeDark
|
console.error("destroyTheme error: " + e);
|
||||||
)) {
|
|
||||||
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);
|
appearance.onSetappearance(response.data);
|
||||||
|
Loading…
Reference in New Issue
Block a user