From b8c9511df58cca6d3685b3bdd9277988b39f549e Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sun, 5 Feb 2023 11:00:10 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/7259 --- app/src/protyle/export/index.ts | 8 +++++--- app/src/util/assets.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts index edf26c87c..aa6593d15 100644 --- a/app/src/protyle/export/index.ts +++ b/app/src/protyle/export/index.ts @@ -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 = ``; } - const html = ` + const html = ` + @@ -553,7 +554,8 @@ const onExport = (data: IWebSocketData, filePath: string, type: string, removeAs if (!isDefault) { themeStyle = ``; } - const html = ` + const html = ` + diff --git a/app/src/util/assets.ts b/app/src/util/assets.ts index 12b677e39..dd471eeb5 100644 --- a/app/src/util/assets.ts +++ b/app/src/util/assets.ts @@ -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"; + } +}