import {Constants} from "../constants";
/// #if !BROWSER
import {ipcRenderer, shell} from "electron";
/// #endif
import {isBrowser} from "../util/functions";
import {fetchPost} from "../util/fetch";
import {setAccessAuthCode} from "./util/setAccessAuthCode";
import {exportLayout} from "../layout/util";
import {exitSiYuan, processSync} from "../dialog/processSystem";
import {openByMobile, writeText} from "../protyle/util/compatibility";
import {showMessage} from "../dialog/message";
import {Dialog} from "../dialog";
import {confirmDialog} from "../dialog/confirmDialog";
import {setProxy} from "./util/setProxy";
export const about = {
element: undefined as Element,
genHTML: () => {
return `
${window.siyuan.languages.dataRepoKey}
${window.siyuan.languages.dataRepoKeyTip1}
${window.siyuan.languages.dataRepoKeyTip2}
${window.siyuan.languages.siyuanNote}
${window.siyuan.languages.slogan}
会泽百家 至公天下
${window.siyuan.languages.about1}
`;
},
bindEvent: () => {
if (window.siyuan.config.system.isInsider) {
about.element.querySelector("#isInsider").innerHTML = "Insider Preview";
}
const tokenElement = about.element.querySelector("#token") as HTMLInputElement;
tokenElement.addEventListener("click", () => {
tokenElement.select();
});
about.element.querySelector("#exportLog").addEventListener("click", () => {
fetchPost("/api/system/exportLog", {}, (response) => {
openByMobile(response.data.zip);
});
});
about.element.querySelector("#menuSafeQuit").addEventListener("click", () => {
exitSiYuan();
});
const updateElement = about.element.querySelector("#checkUpdateBtn");
updateElement.addEventListener("click", () => {
if (updateElement.firstElementChild.classList.contains("fn__rotate")) {
return;
}
updateElement.innerHTML = `${window.siyuan.languages.checkUpdate}`;
fetchPost("/api/system/checkUpdate", {showMsg: true}, () => {
updateElement.innerHTML = `${window.siyuan.languages.checkUpdate}`;
});
});
/// #if !BROWSER
about.element.querySelectorAll('[data-type="open"]').forEach(item => {
item.addEventListener("click", () => {
const url = item.getAttribute("data-url");
if (url.startsWith("http")) {
shell.openExternal(url);
} else {
shell.openPath(url);
}
});
});
/// #endif
about.element.querySelector("#authCode").addEventListener("click", () => {
setAccessAuthCode();
});
const importKeyElement = about.element.querySelector("#importKey");
importKeyElement.addEventListener("click", () => {
const passwordDialog = new Dialog({
title: "🔑 " + window.siyuan.languages.key,
content: `
`,
width: "520px",
});
const textAreaElement = passwordDialog.element.querySelector("textarea");
textAreaElement.focus();
const btnsElement = passwordDialog.element.querySelectorAll(".b3-button");
btnsElement[0].addEventListener("click", () => {
passwordDialog.destroy();
});
btnsElement[1].addEventListener("click", () => {
fetchPost("/api/repo/importRepoKey", {key: textAreaElement.value}, () => {
window.siyuan.config.repo.key = textAreaElement.value;
importKeyElement.parentElement.classList.add("fn__none");
importKeyElement.parentElement.nextElementSibling.classList.remove("fn__none");
passwordDialog.destroy();
});
});
});
about.element.querySelector("#initKey").addEventListener("click", () => {
confirmDialog("🔑 " + window.siyuan.languages.genKey, window.siyuan.languages.initRepoKeyTip, () => {
fetchPost("/api/repo/initRepoKey", {}, (response) => {
window.siyuan.config.repo.key = response.data.key;
importKeyElement.parentElement.classList.add("fn__none");
importKeyElement.parentElement.nextElementSibling.classList.remove("fn__none");
});
});
});
about.element.querySelector("#initKeyByPW").addEventListener("click", () => {
const initDialog = new Dialog({
title: "🔑 " + window.siyuan.languages.genKeyByPW,
content: `
`,
width: "520px",
});
const inputElement = initDialog.element.querySelector(".b3-text-field") as HTMLInputElement;
inputElement.focus();
const btnsElement = initDialog.element.querySelectorAll(".b3-button");
initDialog.bindInput(inputElement, () => {
(btnsElement[1] as HTMLButtonElement).click();
});
btnsElement[0].addEventListener("click", () => {
initDialog.destroy();
});
btnsElement[1].addEventListener("click", () => {
if (!inputElement.value) {
showMessage(window.siyuan.languages._kernel[142]);
return;
}
confirmDialog("🔑 " + window.siyuan.languages.genKeyByPW, window.siyuan.languages.initRepoKeyTip, () => {
initDialog.destroy();
fetchPost("/api/repo/initRepoKeyFromPassphrase", {pass: inputElement.value}, (response) => {
window.siyuan.config.repo.key = response.data.key;
importKeyElement.parentElement.classList.add("fn__none");
importKeyElement.parentElement.nextElementSibling.classList.remove("fn__none");
});
});
});
});
about.element.querySelector("#copyKey").addEventListener("click", () => {
showMessage(window.siyuan.languages.copied);
writeText(window.siyuan.config.repo.key);
});
about.element.querySelector("#resetRepo").addEventListener("click", () => {
confirmDialog("⚠️ " + window.siyuan.languages.resetRepo, window.siyuan.languages.resetRepoTip, () => {
fetchPost("/api/repo/resetRepo", {}, () => {
window.siyuan.config.repo.key = "";
window.siyuan.config.sync.enabled = false;
processSync();
importKeyElement.parentElement.classList.remove("fn__none");
importKeyElement.parentElement.nextElementSibling.classList.add("fn__none");
});
});
});
about.element.querySelector("#purgeRepo").addEventListener("click", () => {
confirmDialog("♻️ " + window.siyuan.languages.dataRepoPurge, window.siyuan.languages.dataRepoPurgeConfirm, () => {
fetchPost("/api/repo/purgeRepo");
});
});
const networkServeElement = about.element.querySelector("#networkServe") as HTMLInputElement;
networkServeElement.addEventListener("change", () => {
fetchPost("/api/system/setNetworkServe", {networkServe: networkServeElement.checked}, () => {
exportLayout({
reload: false,
onlyData: false,
errorExit: true,
cb: exitSiYuan
});
});
});
const googleAnalyticsElement = about.element.querySelector("#googleAnalytics") as HTMLInputElement;
googleAnalyticsElement.addEventListener("change", () => {
fetchPost("/api/system/setGoogleAnalytics", {googleAnalytics: googleAnalyticsElement.checked}, () => {
exportLayout({
reload: true,
onlyData: false,
errorExit: false,
});
});
});
const uploadErrLogElement = about.element.querySelector("#uploadErrLog") as HTMLInputElement;
uploadErrLogElement.addEventListener("change", () => {
fetchPost("/api/system/setUploadErrLog", {uploadErrLog: uploadErrLogElement.checked}, () => {
exportLayout({
reload: false,
onlyData: false,
errorExit: true,
cb: exitSiYuan
});
});
});
const downloadInstallPkgElement = about.element.querySelector("#downloadInstallPkg") as HTMLInputElement;
downloadInstallPkgElement.addEventListener("change", () => {
fetchPost("/api/system/setDownloadInstallPkg", {downloadInstallPkg: downloadInstallPkgElement.checked}, () => {
window.siyuan.config.system.downloadInstallPkg = downloadInstallPkgElement.checked;
});
});
/// #if !BROWSER
const autoLaunchElement = about.element.querySelector("#autoLaunch") as HTMLInputElement;
autoLaunchElement.addEventListener("change", () => {
fetchPost("/api/system/setAutoLaunch", {autoLaunch: autoLaunchElement.checked}, () => {
window.siyuan.config.system.autoLaunch = autoLaunchElement.checked;
ipcRenderer.send(Constants.SIYUAN_AUTO_LAUNCH, {openAtLogin: autoLaunchElement.checked});
});
});
/// #endif
about.element.querySelector("#aboutConfirm").addEventListener("click", () => {
const scheme = (about.element.querySelector("#aboutScheme") as HTMLInputElement).value;
const host = (about.element.querySelector("#aboutHost") as HTMLInputElement).value;
const port = (about.element.querySelector("#aboutPort") as HTMLInputElement).value;
fetchPost("/api/system/setNetworkProxy", {scheme, host, port}, () => {
window.siyuan.config.system.networkProxy.scheme = scheme;
window.siyuan.config.system.networkProxy.host = host;
window.siyuan.config.system.networkProxy.port = port;
setProxy();
});
});
}
};