This commit is contained in:
parent
ed58765121
commit
2b0b28b286
3 changed files with 31 additions and 18 deletions
|
@ -53,16 +53,11 @@ class App {
|
|||
document.title = window.siyuan.languages.siyuanNote;
|
||||
bootSync();
|
||||
loadAssets(confResponse.data.conf.appearance);
|
||||
initMessage();
|
||||
initAssets();
|
||||
fetchPost("/api/system/getEmojiConf", {}, emojiResponse => {
|
||||
window.siyuan.emojis = emojiResponse.data as IEmoji[];
|
||||
initFramework();
|
||||
if (window.siyuan.config.system.container === "ios" && window.webkit?.messageHandlers) {
|
||||
window.webkit.messageHandlers.changeStatusBar.postMessage(getComputedStyle(document.body).getPropertyValue("--b3-theme-background") + " " + window.siyuan.config.appearance.mode);
|
||||
} else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {
|
||||
window.JSAndroid.changeStatusBarColor(getComputedStyle(document.body).getPropertyValue("--b3-theme-background"), window.siyuan.config.appearance.mode);
|
||||
}
|
||||
initMessage();
|
||||
});
|
||||
addGA();
|
||||
});
|
||||
|
|
|
@ -120,9 +120,9 @@ export const initAssets = () => {
|
|||
loadingElement.remove();
|
||||
}, 160);
|
||||
}
|
||||
watchTheme({init: true, theme: window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"});
|
||||
watchTheme({init: true, OSTheme: window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"});
|
||||
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", event => {
|
||||
watchTheme({init: false, theme: event.matches ? "dark" : "light"});
|
||||
watchTheme({init: false, OSTheme: event.matches ? "dark" : "light"});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -246,15 +246,33 @@ export const setMode = (modeElementValue: number) => {
|
|||
/// #endif
|
||||
};
|
||||
|
||||
|
||||
export const watchTheme = (data: { init: boolean, theme: string }) => {
|
||||
const watchTheme = (data: { init: boolean, OSTheme: string }) => {
|
||||
if ((window.siyuan.config.system.container === "ios" && window.webkit?.messageHandlers) ||
|
||||
(window.siyuan.config.system.container === "android" && window.JSAndroid)) {
|
||||
setTimeout(() => {
|
||||
const backgroundColor = getComputedStyle(document.body).getPropertyValue("--b3-theme-background")
|
||||
let mode = window.siyuan.config.appearance.mode;
|
||||
if (window.siyuan.config.appearance.modeOS) {
|
||||
if (data.OSTheme === "dark") {
|
||||
mode = 1;
|
||||
} else {
|
||||
mode = 0;
|
||||
}
|
||||
}
|
||||
if (window.siyuan.config.system.container === "ios" && window.webkit?.messageHandlers) {
|
||||
window.webkit.messageHandlers.changeStatusBar.postMessage(backgroundColor + " " + mode);
|
||||
} else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {
|
||||
window.JSAndroid.changeStatusBarColor(backgroundColor, mode);
|
||||
}
|
||||
}, Constants.TIMEOUT_BLOCKLOAD); // 移动端需要加载完才可以获取到颜色
|
||||
}
|
||||
if (data.init) {
|
||||
if (window.siyuan.config.appearance.modeOS && (
|
||||
(window.siyuan.config.appearance.mode === 1 && data.theme === "light") ||
|
||||
(window.siyuan.config.appearance.mode === 0 && data.theme === "dark")
|
||||
(window.siyuan.config.appearance.mode === 1 && data.OSTheme === "light") ||
|
||||
(window.siyuan.config.appearance.mode === 0 && data.OSTheme === "dark")
|
||||
)) {
|
||||
fetchPost("/api/system/setAppearanceMode", {
|
||||
mode: data.theme === "light" ? 0 : 1
|
||||
mode: data.OSTheme === "light" ? 0 : 1
|
||||
}, response => {
|
||||
window.siyuan.config.appearance = response.data.appearance;
|
||||
loadAssets(response.data.appearance);
|
||||
|
@ -267,12 +285,12 @@ export const watchTheme = (data: { init: boolean, theme: string }) => {
|
|||
if (!window.siyuan.config.appearance.modeOS) {
|
||||
return;
|
||||
}
|
||||
if ((window.siyuan.config.appearance.mode === 0 && data.theme === "light") ||
|
||||
(window.siyuan.config.appearance.mode === 1 && data.theme === "dark")) {
|
||||
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.theme === "light" ? 0 : 1
|
||||
mode: data.OSTheme === "light" ? 0 : 1
|
||||
}, response => {
|
||||
if (window.siyuan.config.appearance.themeJS) {
|
||||
/// #if !MOBILE
|
||||
|
|
|
@ -15,14 +15,14 @@ import {globalShortcut} from "./globalShortcut";
|
|||
import {fetchPost} from "./fetch";
|
||||
import {mountHelp, newDailyNote} from "./mount";
|
||||
import {MenuItem} from "../menus/Menu";
|
||||
import {addGA, initAssets, loadAssets, setInlineStyle, setMode, watchTheme} from "./assets";
|
||||
import {addGA, initAssets, setInlineStyle, setMode} from "./assets";
|
||||
import {renderSnippet} from "../config/util/snippets";
|
||||
import {getOpenNotebookCount} from "./pathName";
|
||||
import {openFileById} from "../editor/util";
|
||||
import {focusByRange} from "../protyle/util/selection";
|
||||
import {exitSiYuan} from "../dialog/processSystem";
|
||||
import {openSetting} from "../config";
|
||||
import {getSearch, isBrowser} from "./functions";
|
||||
import {getSearch} from "./functions";
|
||||
import {openHistory} from "./history";
|
||||
import {initStatus} from "../layout/status";
|
||||
import {syncGuide} from "../sync/syncGuide";
|
||||
|
|
Loading…
Add table
Reference in a new issue