This commit is contained in:
Vanessa 2023-02-05 11:00:10 +08:00
parent 5158ade004
commit b8c9511df5
2 changed files with 19 additions and 3 deletions

View file

@ -8,7 +8,7 @@ import * as path from "path";
import {afterExport} from "./util";
/// #endif
import {confirmDialog} from "../../dialog/confirmDialog";
import {setInlineStyle} from "../../util/assets";
import {getThemeMode, setInlineStyle} from "../../util/assets";
import {fetchPost} from "../../util/fetch";
import {Dialog} from "../../dialog";
import {lockFile} from "../../dialog/processSystem";
@ -79,7 +79,8 @@ const renderPDF = (id: string) => {
if (!isDefault) {
themeStyle = `<link rel="stylesheet" type="text/css" id="themeStyle" href="${servePath}/appearance/themes/${window.siyuan.config.appearance.themeLight}/${window.siyuan.config.appearance.customCSS ? "custom" : "theme"}.css?${Constants.SIYUAN_VERSION}"/>`;
}
const html = `<!DOCTYPE html><html>
const html = `<!DOCTYPE html>
<html lang="${window.siyuan.config.appearance.lang}" data-theme-mode="${getThemeMode()}" data-light-theme="${window.siyuan.config.appearance.themeLight}" data-dark-theme="${window.siyuan.config.appearance.themeDark}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@ -553,7 +554,8 @@ const onExport = (data: IWebSocketData, filePath: string, type: string, removeAs
if (!isDefault) {
themeStyle = `<link rel="stylesheet" type="text/css" id="themeStyle" href="appearance/themes/${themeName}/${window.siyuan.config.appearance.customCSS ? "custom" : "theme"}.css?${Constants.SIYUAN_VERSION}"/>`;
}
const html = `<!DOCTYPE html><html>
const html = `<!DOCTYPE html>
<html lang="${window.siyuan.config.appearance.lang}" data-theme-mode="${getThemeMode()}" data-light-theme="${window.siyuan.config.appearance.themeLight}" data-dark-theme="${window.siyuan.config.appearance.themeDark}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

View file

@ -22,6 +22,11 @@ const loadThirdIcon = (iconURL: string, data: IAppearance) => {
};
export const loadAssets = (data: IAppearance) => {
const htmlElement = document.getElementsByTagName("html")[0]
htmlElement.setAttribute("lang",window.siyuan.config.appearance.lang);
htmlElement.setAttribute("data-theme-mode",getThemeMode());
htmlElement.setAttribute("data-light-theme",window.siyuan.config.appearance.themeLight);
htmlElement.setAttribute("data-dark-theme",window.siyuan.config.appearance.themeDark);
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") ||
@ -292,3 +297,12 @@ const updateMobileTheme = (OSTheme: string) => {
}, 500); // 移动端需要加载完才可以获取到颜色
}
};
export const getThemeMode = () => {
const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
if (window.siyuan.config.appearance.modeOS) {
return OSTheme;
} else {
return window.siyuan.config.appearance.mode === 0 ? "light" : "dark";
}
}