2022-05-26 15:18:53 +08:00
|
|
|
import {fetchPost} from "../../util/fetch";
|
|
|
|
|
import {setInlineStyle} from "../../util/assets";
|
2022-06-30 18:15:13 +08:00
|
|
|
import {genOptions} from "../../util/genOptions";
|
2022-08-31 12:57:38 +08:00
|
|
|
import {reloadProtyle} from "../../protyle/util/reload";
|
2023-03-27 09:48:11 +08:00
|
|
|
import {openModel} from "../util/model";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
2023-03-27 09:48:11 +08:00
|
|
|
export const initAppearance = () => {
|
|
|
|
|
openModel({
|
|
|
|
|
title: window.siyuan.languages.appearance,
|
|
|
|
|
icon:"iconTheme",
|
|
|
|
|
html: `<div class="b3-label">
|
2022-05-26 15:18:53 +08:00
|
|
|
${window.siyuan.languages.appearance4}
|
|
|
|
|
<div class="fn__hr"></div>
|
|
|
|
|
<select class="b3-select fn__block" id="mode">
|
2022-11-16 10:09:44 +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>
|
|
|
|
|
<option value="2" ${window.siyuan.config.appearance.modeOS ? "selected" : ""}>${window.siyuan.languages.themeOS}</option>
|
2022-05-26 15:18:53 +08:00
|
|
|
</select>
|
2022-08-12 12:08:16 +08:00
|
|
|
<div class="b3-label__text">${window.siyuan.languages.appearance5}</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="b3-label">
|
|
|
|
|
${window.siyuan.languages.theme}
|
|
|
|
|
<div class="fn__hr"></div>
|
|
|
|
|
<select class="b3-select fn__block" 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>
|
2022-08-12 12:08:16 +08:00
|
|
|
<div class="b3-label__text">${window.siyuan.languages.theme11}</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
<div class="fn__hr"></div>
|
|
|
|
|
<select class="b3-select fn__block" 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>
|
2022-08-12 12:08:16 +08:00
|
|
|
<div class="b3-label__text">${window.siyuan.languages.theme12}</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="b3-label">
|
|
|
|
|
${window.siyuan.languages.icon}
|
|
|
|
|
<div class="fn__hr"></div>
|
|
|
|
|
<select class="b3-select fn__block" id="icon">
|
2022-06-30 18:15:13 +08:00
|
|
|
${genOptions(window.siyuan.config.appearance.icons, window.siyuan.config.appearance.icon)}
|
2022-05-26 15:18:53 +08:00
|
|
|
</select>
|
2022-08-12 12:08:16 +08:00
|
|
|
<div class="b3-label__text">${window.siyuan.languages.theme2}</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="b3-label">
|
|
|
|
|
${window.siyuan.languages.language}
|
|
|
|
|
<div class="fn__hr"></div>
|
2022-06-30 18:15:13 +08:00
|
|
|
<select id="lang" class="b3-select fn__block">${genOptions(window.siyuan.config.langs, window.siyuan.config.appearance.lang)}</select>
|
2022-08-12 12:08:16 +08:00
|
|
|
<div class="b3-label__text">${window.siyuan.languages.language1}</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="b3-label">
|
|
|
|
|
${window.siyuan.languages.fontSize} <span id="fontSize" class="ft__on-surface">${window.siyuan.config.editor.fontSize}px</span>
|
|
|
|
|
<div class="fn__hr"></div>
|
|
|
|
|
<input class="b3-slider fn__block" max="72" min="9" step="1" type="range" value="${window.siyuan.config.editor.fontSize}">
|
2022-08-12 12:08:16 +08:00
|
|
|
<div class="b3-label__text">${window.siyuan.languages.fontSizeTip}</div>
|
2023-03-27 09:48:11 +08:00
|
|
|
</div>`,
|
|
|
|
|
bindEvent(modelMainElement: HTMLElement) {
|
|
|
|
|
modelMainElement.querySelector(".b3-slider").addEventListener("input", (event: InputEvent & {
|
|
|
|
|
target: HTMLInputElement
|
|
|
|
|
}) => {
|
|
|
|
|
modelMainElement.querySelector("#fontSize").textContent = event.target.value + "px";
|
|
|
|
|
window.siyuan.config.editor.fontSize = parseInt(event.target.value);
|
|
|
|
|
fetchPost("/api/setting/setEditor", window.siyuan.config.editor, (response) => {
|
|
|
|
|
window.siyuan.config.editor = response.data;
|
|
|
|
|
reloadProtyle(window.siyuan.mobile.editor.protyle);
|
|
|
|
|
setInlineStyle();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
modelMainElement.querySelectorAll("select").forEach(item => {
|
|
|
|
|
item.addEventListener("change", () => {
|
|
|
|
|
const modeElementValue = parseInt((modelMainElement.querySelector("#mode") as HTMLSelectElement).value);
|
|
|
|
|
fetchPost("/api/setting/setAppearance", Object.assign({}, window.siyuan.config.appearance, {
|
|
|
|
|
icon: (modelMainElement.querySelector("#icon") as HTMLSelectElement).value,
|
|
|
|
|
mode: modeElementValue === 2 ? window.siyuan.config.appearance.mode : modeElementValue,
|
|
|
|
|
modeOS: modeElementValue === 2,
|
|
|
|
|
themeDark: (modelMainElement.querySelector("#themeDark") as HTMLSelectElement).value,
|
|
|
|
|
themeLight: (modelMainElement.querySelector("#themeLight") as HTMLSelectElement).value,
|
|
|
|
|
lang: (modelMainElement.querySelector("#lang") as HTMLSelectElement).value,
|
|
|
|
|
}), () => {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
});
|
2023-03-27 09:48:11 +08:00
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
});
|
|
|
|
|
};
|