2022-05-26 15:18:53 +08:00
|
|
|
/// #if !BROWSER
|
|
|
|
|
import * as path from "path";
|
|
|
|
|
/// #endif
|
|
|
|
|
import {Constants} from "../constants";
|
2022-10-30 09:37:46 +08:00
|
|
|
import {exportLayout, resetLayout} from "../layout/util";
|
2022-05-26 15:18:53 +08:00
|
|
|
import {isBrowser} from "../util/functions";
|
|
|
|
|
import {fetchPost} from "../util/fetch";
|
2024-05-01 16:10:07 +08:00
|
|
|
import {genLangOptions, genOptions} from "../util/genOptions";
|
2022-10-27 19:34:26 +08:00
|
|
|
import {openSnippets} from "./util/snippets";
|
2022-11-20 23:04:12 +08:00
|
|
|
import {loadAssets} from "../util/assets";
|
2023-02-11 21:21:13 +08:00
|
|
|
import {resetFloatDockSize} from "../layout/dock/util";
|
2024-05-29 22:08:44 +08:00
|
|
|
import {confirmDialog} from "../dialog/confirmDialog";
|
2025-05-22 12:33:11 +08:00
|
|
|
import {useShell} from "../util/pathName";
|
2025-12-17 11:48:02 +08:00
|
|
|
import {setStatusBar} from "./util/setStatusBar";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
export const appearance = {
|
|
|
|
|
element: undefined as Element,
|
|
|
|
|
genHTML: () => {
|
2023-12-19 12:20:25 +08:00
|
|
|
return `<div class="fn__flex b3-label config__item">
|
2022-05-26 15:18:53 +08:00
|
|
|
<div class="fn__flex-1">
|
|
|
|
|
${window.siyuan.languages.appearance4}
|
|
|
|
|
<div class="b3-label__text">${window.siyuan.languages.appearance5}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<select class="b3-select fn__flex-center fn__size200" id="mode">
|
2022-09-25 21:52:23 +08:00
|
|
|
<option value="0" ${(window.siyuan.config.appearance.mode === 0 && !window.siyuan.config.appearance.modeOS) ? "selected" : ""}>${window.siyuan.languages.themeLight}</option>
|
|
|
|
|
<option value="1" ${(window.siyuan.config.appearance.mode === 1 && !window.siyuan.config.appearance.modeOS) ? "selected" : ""}>${window.siyuan.languages.themeDark}</option>
|
2022-09-25 22:45:14 +08:00
|
|
|
<option value="2" ${window.siyuan.config.appearance.modeOS ? "selected" : ""}>${window.siyuan.languages.themeOS}</option>
|
2022-05-26 15:18:53 +08:00
|
|
|
</select>
|
2023-12-19 12:20:25 +08:00
|
|
|
</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
<div class="b3-label">
|
|
|
|
|
<div class="fn__flex">
|
2025-01-01 23:23:48 +08:00
|
|
|
<div class="fn__flex-center fn__flex-1">${window.siyuan.languages.theme}</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
<span class="fn__space"></span>
|
2025-01-01 23:23:48 +08:00
|
|
|
<button class="b3-button b3-button--outline fn__flex-center fn__size200${isBrowser() ? " fn__none" : ""}" id="appearanceOpenTheme">
|
|
|
|
|
<svg><use xlink:href="#iconFolder"></use></svg>
|
|
|
|
|
${window.siyuan.languages.appearance9}
|
|
|
|
|
</button>
|
2022-05-26 15:18:53 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="fn__hr"></div>
|
2023-12-19 12:20:25 +08:00
|
|
|
<div class="fn__flex config__item">
|
2022-05-26 15:18:53 +08:00
|
|
|
<div class="fn__flex-center fn__flex-1 ft__on-surface">
|
|
|
|
|
${window.siyuan.languages.theme11}
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<select class="b3-select fn__flex-center fn__size200" id="themeLight">
|
2022-06-30 18:15:13 +08:00
|
|
|
${genOptions(window.siyuan.config.appearance.lightThemes, window.siyuan.config.appearance.themeLight)}
|
2022-05-26 15:18:53 +08:00
|
|
|
</select>
|
2023-12-19 12:20:25 +08:00
|
|
|
</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
<div class="fn__hr"></div>
|
2023-12-19 12:20:25 +08:00
|
|
|
<div class="fn__flex config__item">
|
2022-05-26 15:18:53 +08:00
|
|
|
<div class="fn__flex-center fn__flex-1 ft__on-surface">
|
|
|
|
|
${window.siyuan.languages.theme12}
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<select class="b3-select fn__flex-center fn__size200" id="themeDark">
|
2022-06-30 18:15:13 +08:00
|
|
|
${genOptions(window.siyuan.config.appearance.darkThemes, window.siyuan.config.appearance.themeDark)}
|
2022-05-26 15:18:53 +08:00
|
|
|
</select>
|
2023-12-19 12:20:25 +08:00
|
|
|
</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
</div>
|
2025-01-01 23:23:48 +08:00
|
|
|
<div class="b3-label">
|
|
|
|
|
<div class="fn__flex config__item">
|
|
|
|
|
<div class="fn__flex-center fn__flex-1">
|
2022-05-26 15:18:53 +08:00
|
|
|
${window.siyuan.languages.icon}
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
2025-01-01 23:23:48 +08:00
|
|
|
<button class="b3-button b3-button--outline fn__flex-center fn__size200${isBrowser() ? " fn__none" : ""}" id="appearanceOpenIcon">
|
|
|
|
|
<svg><use xlink:href="#iconFolder"></use></svg>
|
|
|
|
|
${window.siyuan.languages.appearance8}
|
|
|
|
|
</button>
|
2023-12-19 12:20:25 +08:00
|
|
|
</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
<div class="fn__hr"></div>
|
2023-12-19 12:20:25 +08:00
|
|
|
<div class="fn__flex config__item">
|
2025-01-01 23:23:48 +08:00
|
|
|
<div class="fn__flex-center fn__flex-1 ft__on-surface">${window.siyuan.languages.theme2}</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
<span class="fn__space"></span>
|
2025-01-01 23:23:48 +08:00
|
|
|
<select class="b3-select fn__flex-center fn__size200" id="icon">
|
|
|
|
|
${genOptions(window.siyuan.config.appearance.icons, window.siyuan.config.appearance.icon)}
|
2022-05-26 15:18:53 +08:00
|
|
|
</select>
|
2023-12-19 12:20:25 +08:00
|
|
|
</div>
|
2025-01-01 23:23:48 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="b3-label fn__flex">
|
|
|
|
|
<div class="fn__block">
|
|
|
|
|
<div>
|
|
|
|
|
${window.siyuan.languages.appearance1}
|
|
|
|
|
</div>
|
|
|
|
|
<div class="fn__hr"></div>
|
|
|
|
|
<div class="fn__flex config__item">
|
|
|
|
|
<div class="fn__flex-center fn__flex-1 ft__on-surface">${window.siyuan.languages.appearance2}</div>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<select id="codeBlockThemeLight" class="b3-select fn__size200">
|
|
|
|
|
${genOptions(Constants.SIYUAN_CONFIG_APPEARANCE_LIGHT_CODE, window.siyuan.config.appearance.codeBlockThemeLight)}
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="fn__hr"></div>
|
|
|
|
|
<div class="fn__flex config__item">
|
|
|
|
|
<div class="fn__flex-center fn__flex-1 ft__on-surface">${window.siyuan.languages.appearance3}</div>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<select id="codeBlockThemeDark" class="b3-select fn__size200">
|
|
|
|
|
${genOptions(Constants.SIYUAN_CONFIG_APPEARANCE_DARK_CODE, window.siyuan.config.appearance.codeBlockThemeDark)}
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2023-12-19 12:20:25 +08:00
|
|
|
<div class="fn__flex b3-label config__item">
|
2022-05-26 15:18:53 +08:00
|
|
|
<div class="fn__flex-1">
|
|
|
|
|
${window.siyuan.languages.language}
|
|
|
|
|
<div class="b3-label__text">${window.siyuan.languages.language1}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
2024-05-01 16:10:07 +08:00
|
|
|
<select id="lang" class="b3-select fn__flex-center fn__size200">${genLangOptions(window.siyuan.config.langs, window.siyuan.config.appearance.lang)}</select>
|
2023-12-19 12:20:25 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="b3-label config__item${isBrowser() ? " fn__none" : " fn__flex"}">
|
2022-10-18 00:03:34 +08:00
|
|
|
<div class="fn__flex-1">
|
|
|
|
|
${window.siyuan.languages.customEmoji}
|
|
|
|
|
<div class="b3-label__text">${window.siyuan.languages.customEmojiTip}</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
</div>
|
2022-10-18 00:03:34 +08:00
|
|
|
<span class="fn__space"></span>
|
2024-06-18 22:50:22 +08:00
|
|
|
<button class="b3-button b3-button--outline fn__flex-center fn__size200" id="appearanceOpenEmoji">
|
|
|
|
|
<svg><use xlink:href="#iconFolder"></use></svg>
|
|
|
|
|
${window.siyuan.languages.showInFolder}
|
2022-10-18 00:03:34 +08:00
|
|
|
</button>
|
2023-12-19 12:20:25 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="b3-label fn__flex config__item">
|
2022-10-27 09:53:13 +08:00
|
|
|
<div class="fn__flex-1">
|
|
|
|
|
${window.siyuan.languages.resetLayout}
|
|
|
|
|
<div class="b3-label__text">${window.siyuan.languages.appearance6}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<button class="b3-button b3-button--outline fn__flex-center fn__size200" id="resetLayout">
|
|
|
|
|
<svg><use xlink:href="#iconUndo"></use></svg>${window.siyuan.languages.reset}
|
|
|
|
|
</button>
|
2023-12-19 12:20:25 +08:00
|
|
|
</div>
|
2025-01-01 23:23:48 +08:00
|
|
|
<div class="b3-label">
|
|
|
|
|
<div class="fn__flex config__item">
|
|
|
|
|
<div class="fn__flex-1 fn__flex-center">
|
|
|
|
|
${window.siyuan.languages.codeSnippet}
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<a class="b3-button b3-button--outline fn__flex-center fn__size200${"zh_CN" !== window.siyuan.config.lang ? " fn__none" : ""}" target="_blank" href="https://ld246.com/tag/code-snippet">
|
|
|
|
|
<svg><use xlink:href="#iconUpload"></use></svg>${window.siyuan.languages.visitCommunityShare}
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="fn__hr"></div>
|
|
|
|
|
<div class="fn__flex config__item">
|
|
|
|
|
<div class="fn__flex-center fn__flex-1 ft__on-surface">
|
|
|
|
|
${window.siyuan.languages.codeSnippetTip}
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<button class="b3-button b3-button--outline fn__flex-center fn__size200" id="codeSnippet">
|
|
|
|
|
<svg><use xlink:href="#iconSettings"></use></svg>${window.siyuan.languages.config}
|
|
|
|
|
</button>
|
2022-10-27 22:16:33 +08:00
|
|
|
</div>
|
2023-12-19 12:20:25 +08:00
|
|
|
</div>
|
2025-11-12 23:47:37 +08:00
|
|
|
<div class="b3-label">
|
|
|
|
|
${window.siyuan.languages.appearance16}
|
|
|
|
|
<div class="fn__hr"></div>
|
|
|
|
|
<label class="fn__flex">
|
|
|
|
|
<div class="fn__flex-center fn__flex-1 ft__on-surface">
|
|
|
|
|
${window.siyuan.languages.appearance17}
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<input class="b3-switch fn__flex-center" id="hideStatusBar" type="checkbox"${window.siyuan.config.appearance.hideStatusBar ? " checked" : ""}>
|
|
|
|
|
</label>
|
|
|
|
|
<div class="fn__hr"></div>
|
|
|
|
|
<div class="fn__flex config__item">
|
|
|
|
|
<div class="fn__flex-center fn__flex-1 ft__on-surface">
|
|
|
|
|
${window.siyuan.languages.appearance18}
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<button class="b3-button b3-button--outline fn__flex-center fn__size200" id="statusBarSetting">
|
|
|
|
|
<svg><use xlink:href="#iconSettings"></use></svg>${window.siyuan.languages.config}
|
|
|
|
|
</button>
|
2022-06-26 22:27:18 +08:00
|
|
|
</div>
|
2025-11-12 23:47:37 +08:00
|
|
|
</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
<label class="fn__flex b3-label">
|
|
|
|
|
<div class="fn__flex-1">
|
|
|
|
|
${window.siyuan.languages.appearance10}
|
|
|
|
|
<div class="b3-label__text">${window.siyuan.languages.appearance11}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<input class="b3-switch fn__flex-center" id="closeButtonBehavior" type="checkbox"${window.siyuan.config.appearance.closeButtonBehavior === 0 ? "" : " checked"}>
|
|
|
|
|
</label>`;
|
|
|
|
|
},
|
2025-12-17 11:48:02 +08:00
|
|
|
_send: () => {
|
2022-05-26 15:18:53 +08:00
|
|
|
const themeLight = (appearance.element.querySelector("#themeLight") as HTMLSelectElement).value;
|
|
|
|
|
const themeDark = (appearance.element.querySelector("#themeDark") as HTMLSelectElement).value;
|
2022-09-27 00:13:11 +08:00
|
|
|
const modeElementValue = parseInt((appearance.element.querySelector("#mode") as HTMLSelectElement).value);
|
2025-02-23 14:55:43 +08:00
|
|
|
const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
2022-05-26 15:18:53 +08:00
|
|
|
fetchPost("/api/setting/setAppearance", {
|
|
|
|
|
icon: (appearance.element.querySelector("#icon") as HTMLSelectElement).value,
|
2025-02-23 14:55:43 +08:00
|
|
|
mode: modeElementValue === 2 ? (OSTheme === "light" ? 0 : 1) : modeElementValue,
|
2022-09-25 21:52:23 +08:00
|
|
|
modeOS: modeElementValue === 2,
|
2022-05-26 15:18:53 +08:00
|
|
|
codeBlockThemeDark: (appearance.element.querySelector("#codeBlockThemeDark") as HTMLSelectElement).value,
|
|
|
|
|
codeBlockThemeLight: (appearance.element.querySelector("#codeBlockThemeLight") as HTMLSelectElement).value,
|
|
|
|
|
themeDark,
|
|
|
|
|
themeLight,
|
|
|
|
|
darkThemes: window.siyuan.config.appearance.darkThemes,
|
|
|
|
|
lightThemes: window.siyuan.config.appearance.lightThemes,
|
|
|
|
|
icons: window.siyuan.config.appearance.icons,
|
|
|
|
|
lang: (appearance.element.querySelector("#lang") as HTMLSelectElement).value,
|
|
|
|
|
closeButtonBehavior: (appearance.element.querySelector("#closeButtonBehavior") as HTMLInputElement).checked ? 1 : 0,
|
2022-06-26 22:27:18 +08:00
|
|
|
hideStatusBar: (appearance.element.querySelector("#hideStatusBar") as HTMLInputElement).checked,
|
2025-11-12 23:47:37 +08:00
|
|
|
statusBar: {
|
2025-12-17 11:48:02 +08:00
|
|
|
msgTaskDatabaseIndexCommitDisabled: window.siyuan.config.appearance.statusBar.msgTaskDatabaseIndexCommitDisabled,
|
|
|
|
|
msgTaskHistoryDatabaseIndexCommitDisabled: window.siyuan.config.appearance.statusBar.msgTaskHistoryDatabaseIndexCommitDisabled,
|
|
|
|
|
msgTaskAssetDatabaseIndexCommitDisabled: window.siyuan.config.appearance.statusBar.msgTaskAssetDatabaseIndexCommitDisabled,
|
|
|
|
|
msgTaskHistoryGenerateFileDisabled: window.siyuan.config.appearance.statusBar.msgTaskHistoryGenerateFileDisabled,
|
2025-11-12 23:47:37 +08:00
|
|
|
}
|
2025-11-23 18:47:47 +08:00
|
|
|
}, () => {
|
2023-02-11 21:21:13 +08:00
|
|
|
resetFloatDockSize();
|
2022-05-26 15:18:53 +08:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
bindEvent: () => {
|
2025-12-17 11:48:02 +08:00
|
|
|
setStatusBar(appearance.element.querySelector("#statusBarSetting"));
|
2022-10-27 19:34:26 +08:00
|
|
|
appearance.element.querySelector("#codeSnippet").addEventListener("click", () => {
|
2022-10-27 23:06:50 +08:00
|
|
|
openSnippets();
|
2022-10-27 11:34:34 +08:00
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
appearance.element.querySelector("#resetLayout").addEventListener("click", () => {
|
2024-05-29 22:08:44 +08:00
|
|
|
confirmDialog("⚠️ " + window.siyuan.languages.reset, window.siyuan.languages.appearance6, () => {
|
|
|
|
|
resetLayout();
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
});
|
|
|
|
|
/// #if !BROWSER
|
|
|
|
|
appearance.element.querySelector("#appearanceOpenIcon").addEventListener("click", () => {
|
2025-05-22 12:33:11 +08:00
|
|
|
useShell("openPath", path.join(window.siyuan.config.system.confDir, "appearance", "icons"));
|
2022-05-26 15:18:53 +08:00
|
|
|
});
|
|
|
|
|
appearance.element.querySelector("#appearanceOpenTheme").addEventListener("click", () => {
|
2025-05-22 12:33:11 +08:00
|
|
|
useShell("openPath", path.join(window.siyuan.config.system.confDir, "appearance", "themes"));
|
2022-05-26 15:18:53 +08:00
|
|
|
});
|
|
|
|
|
appearance.element.querySelector("#appearanceOpenEmoji").addEventListener("click", () => {
|
2025-05-22 12:33:11 +08:00
|
|
|
useShell("openPath", path.join(window.siyuan.config.system.dataDir, "emojis"));
|
2022-05-26 15:18:53 +08:00
|
|
|
});
|
|
|
|
|
/// #endif
|
|
|
|
|
appearance.element.querySelectorAll("select").forEach(item => {
|
|
|
|
|
item.addEventListener("change", () => {
|
2022-09-25 21:52:23 +08:00
|
|
|
appearance._send();
|
2022-05-26 15:18:53 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
appearance.element.querySelectorAll(".b3-switch").forEach((item) => {
|
|
|
|
|
item.addEventListener("change", () => {
|
|
|
|
|
appearance._send();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
2025-06-29 23:07:26 +08:00
|
|
|
onSetAppearance(data: Config.IAppearance) {
|
2023-06-01 21:04:58 +08:00
|
|
|
if (data.lang !== window.siyuan.config.appearance.lang) {
|
2023-05-11 12:22:53 +08:00
|
|
|
exportLayout({
|
2023-12-31 16:51:31 +08:00
|
|
|
cb() {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
},
|
2023-05-11 12:22:53 +08:00
|
|
|
errorExit: false,
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2025-07-29 21:33:40 +08:00
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
window.siyuan.config.appearance = data;
|
|
|
|
|
if (appearance.element) {
|
2022-09-25 21:52:23 +08:00
|
|
|
const modeElement = appearance.element.querySelector("#mode") as HTMLSelectElement;
|
2022-05-26 15:18:53 +08:00
|
|
|
if (modeElement) {
|
2022-09-25 21:52:23 +08:00
|
|
|
if (data.modeOS) {
|
|
|
|
|
modeElement.value = "2";
|
|
|
|
|
} else {
|
|
|
|
|
modeElement.value = data.mode === 0 ? "0" : "1";
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
const themeLightElement = appearance.element.querySelector("#themeLight") as HTMLSelectElement;
|
|
|
|
|
if (themeLightElement) {
|
2022-09-27 00:13:11 +08:00
|
|
|
themeLightElement.innerHTML = genOptions(window.siyuan.config.appearance.lightThemes, window.siyuan.config.appearance.themeLight);
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
const themeDarkElement = appearance.element.querySelector("#themeDark") as HTMLSelectElement;
|
|
|
|
|
if (themeDarkElement) {
|
2022-09-27 00:13:11 +08:00
|
|
|
themeDarkElement.innerHTML = genOptions(window.siyuan.config.appearance.darkThemes, window.siyuan.config.appearance.themeDark);
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
const iconElement = appearance.element.querySelector("#icon") as HTMLSelectElement;
|
|
|
|
|
if (iconElement) {
|
2022-09-27 00:13:11 +08:00
|
|
|
iconElement.innerHTML = genOptions(window.siyuan.config.appearance.icons, window.siyuan.config.appearance.icon);
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-06 22:50:11 +08:00
|
|
|
loadAssets(data);
|
2023-01-26 18:53:57 +08:00
|
|
|
document.querySelector("#barMode use")?.setAttribute("xlink:href", `#icon${window.siyuan.config.appearance.modeOS ? "Mode" : (window.siyuan.config.appearance.mode === 0 ? "Light" : "Dark")}`);
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
};
|