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/about"; import {exportLayout} from "../layout/util"; import {exitSiYuan, processSync} from "../dialog/processSystem"; import {isInAndroid, isInHarmony, isInIOS, isIPad, isMac, openByMobile, writeText} from "../protyle/util/compatibility"; import {showMessage} from "../dialog/message"; import {Dialog} from "../dialog"; import {confirmDialog} from "../dialog/confirmDialog"; import {setKey} from "../sync/syncGuide"; import {useShell} from "../util/pathName"; import {hasClosestByClassName} from "../protyle/util/hasClosest"; export const about = { element: undefined as Element, genHTML: () => { const checkUpdateHTML = window.siyuan.config.system.isMicrosoftStore ? `
${window.siyuan.languages.currentVer} v${Constants.SIYUAN_VERSION}
${window.siyuan.languages.isMsStoreVerTip}
` : `
${window.siyuan.languages.currentVer} v${Constants.SIYUAN_VERSION}
${window.siyuan.languages.downloadLatestVer}
`; return `
${window.siyuan.languages.autoLaunch}
${window.siyuan.languages.autoLaunchTip}
${window.siyuan.languages.exportCACert}
${window.siyuan.languages.exportCACertTip}
${window.siyuan.languages.exportCABundle}
${window.siyuan.languages.exportCABundleTip}
${window.siyuan.languages.importCABundle}
${window.siyuan.languages.importCABundleTip}
${window.siyuan.languages.about5}
${window.siyuan.languages.about6}
${window.siyuan.languages.about2}
${window.siyuan.languages.about3.replace("${port}", location.port)}
${(() => { const serverAddrs: string[] = []; for (const serverAddr of window.siyuan.config.serverAddrs) { if (!serverAddr.trim()) { break; } serverAddrs.push(`${serverAddr}`); } return `
${serverAddrs.join(" ")}
`; })()}
${window.siyuan.languages.about18}
${window.siyuan.languages.dataRepoKey}
${window.siyuan.languages.dataRepoKeyTip1}
${window.siyuan.languages.dataRepoKeyTip2}
${window.siyuan.languages.dataRepoPurge}
${window.siyuan.languages.dataRepoPurgeTip}
${window.siyuan.languages.dataRepoAutoPurgeIndexRetentionDays}
${window.siyuan.languages.dataRepoAutoPurgeRetentionIndexesDaily}
${window.siyuan.languages.vacuumDataIndex}
${window.siyuan.languages.vacuumDataIndexTip}
${window.siyuan.languages.rebuildDataIndex}
${window.siyuan.languages.rebuildDataIndexTip}
${window.siyuan.languages.clearTempFiles}
${window.siyuan.languages.clearTempFilesTip}
${window.siyuan.languages.systemLog}
${window.siyuan.languages.systemLogTip}
${checkUpdateHTML}
${window.siyuan.languages.about13}
${window.siyuan.languages.about14.replace("${token}", window.siyuan.config.api.token)}
${window.siyuan.languages.networkProxy}
${window.siyuan.languages.about17}
${window.siyuan.languages.about1} ${"harmony" === window.siyuan.config.system.container ? " • " + window.siyuan.languages.feedback + " 845765@qq.com" : ""}
`; }, bindEvent: () => { if (window.siyuan.config.system.isInsider) { about.element.querySelector("#isInsider").innerHTML = "Insider Preview"; } const indexRetentionDaysElement = about.element.querySelector("#indexRetentionDays") as HTMLInputElement; indexRetentionDaysElement.addEventListener("change", () => { fetchPost("/api/repo/setRepoIndexRetentionDays", {days: parseInt(indexRetentionDaysElement.value)}, () => { window.siyuan.config.repo.indexRetentionDays = parseInt(indexRetentionDaysElement.value); }); }); const retentionIndexesDailyElement = about.element.querySelector("#retentionIndexesDaily") as HTMLInputElement; retentionIndexesDailyElement.addEventListener("change", () => { fetchPost("/api/repo/setRetentionIndexesDaily", {indexes: parseInt(retentionIndexesDailyElement.value)}, () => { window.siyuan.config.repo.retentionIndexesDaily = parseInt(retentionIndexesDailyElement.value); }); }); const tokenElement = about.element.querySelector("#token") as HTMLInputElement; tokenElement.addEventListener("click", () => { tokenElement.select(); }); tokenElement.addEventListener("change", () => { fetchPost("/api/system/setAPIToken", {token: tokenElement.value}, () => { window.siyuan.config.api.token = tokenElement.value; about.element.querySelector("#tokenTip").innerHTML = window.siyuan.languages.about14.replace("${token}", window.siyuan.config.api.token); }); }); about.element.querySelector("#vacuumDataIndex").addEventListener("click", () => { fetchPost("/api/system/vacuumDataIndex", {}, () => { }); }); about.element.querySelector("#rebuildDataIndex").addEventListener("click", () => { fetchPost("/api/system/rebuildDataIndex", {}, () => { }); }); about.element.querySelector("#clearTempFiles").addEventListener("click", () => { fetchPost("/api/system/clearTempFiles", {}, () => { }); }); about.element.querySelector("#exportLog").addEventListener("click", () => { fetchPost("/api/system/exportLog", {}, (response) => { openByMobile(response.data.zip); }); }); 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}`; }); }); about.element.querySelectorAll('[data-type="open"]').forEach(item => { item.addEventListener("click", () => { const url = item.getAttribute("data-url"); /// #if !BROWSER if (url.startsWith("http")) { shell.openExternal(url); } else { useShell("openPath", url); } /// #else window.open(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", }); passwordDialog.element.setAttribute("data-key", Constants.DIALOG_PASSWORD); 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}, (response) => { window.siyuan.config.repo.key = response.data.key; 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", () => { setKey(false, () => { 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; const networkServeTLSElement = about.element.querySelector("#networkServeTLS") as HTMLInputElement; const networkServeContainElement = hasClosestByClassName(networkServeElement, "b3-label") as HTMLElement; networkServeElement.addEventListener("change", () => { networkServeTLSElement.disabled = !networkServeElement.checked; if (!networkServeElement.checked) { networkServeTLSElement.checked = false; } Array.from(networkServeContainElement.children).forEach((item: HTMLElement, index) => { if (index === 1) { if (networkServeElement.checked) { item.classList.remove("fn__none"); } else { item.classList.add("fn__none"); } } else if (index > 1) { if (networkServeTLSElement.checked) { item.classList.remove("fn__none"); } else { item.classList.add("fn__none"); } } }); fetchPost("/api/system/setNetworkServe", {networkServe: networkServeElement.checked}, () => { exportLayout({ errorExit: true, cb: exitSiYuan }); }); }); networkServeTLSElement.addEventListener("change", () => { Array.from(networkServeContainElement.children).forEach((item: HTMLElement, index) => { if (index > 1) { if (networkServeTLSElement.checked) { item.classList.remove("fn__none"); } else { item.classList.add("fn__none"); } } }); fetchPost("/api/system/setNetworkServeTLS", {networkServeTLS: networkServeTLSElement.checked}, () => { exportLayout({ errorExit: true, cb: exitSiYuan }); }); }); about.element.querySelector("#exportCACert")?.addEventListener("click", () => { fetchPost("/api/system/exportTLSCACert", {}, (response) => { openByMobile(response.data.path); }); }); about.element.querySelector("#exportCABundle")?.addEventListener("click", () => { fetchPost("/api/system/exportTLSCABundle", {}, (response) => { openByMobile(response.data.path); }); }); about.element.querySelector("#importCABundle")?.addEventListener("click", () => { const input = document.createElement("input"); input.type = "file"; input.accept = ".zip"; input.onchange = () => { if (input.files && input.files[0]) { const formData = new FormData(); formData.append("file", input.files[0]); fetch("/api/system/importTLSCABundle", { method: "POST", body: formData, }).then(res => res.json()).then((response) => { if (response.code === 0) { showMessage(window.siyuan.languages.importCABundleSuccess); } else { showMessage(response.msg, 6000, "error"); } }); } }; input.click(); }); const lockScreenModeElement = about.element.querySelector("#lockScreenMode") as HTMLInputElement; lockScreenModeElement.addEventListener("change", () => { fetchPost("/api/system/setFollowSystemLockScreen", {lockScreenMode: lockScreenModeElement.checked ? 1 : 0}, () => { window.siyuan.config.system.lockScreenMode = lockScreenModeElement.checked ? 1 : 0; }); }); 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", () => { const autoLaunchMode = parseInt(autoLaunchElement.value); fetchPost("/api/system/setAutoLaunch", {autoLaunch: autoLaunchMode}, () => { window.siyuan.config.system.autoLaunch2 = autoLaunchMode; ipcRenderer.send(Constants.SIYUAN_AUTO_LAUNCH, { openAtLogin: 0 !== autoLaunchMode, openAsHidden: 2 === autoLaunchMode }); }); }); /// #endif about.element.querySelector("#aboutConfirm").addEventListener("click", () => { const scheme = (about.element.querySelector("#aboutScheme") as HTMLInputElement).value as Config.TSystemNetworkProxyScheme; 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}, async () => { window.siyuan.config.system.networkProxy.scheme = scheme; window.siyuan.config.system.networkProxy.host = host; window.siyuan.config.system.networkProxy.port = port; /// #if !BROWSER ipcRenderer.invoke(Constants.SIYUAN_GET, { cmd: "setProxy", proxyURL: `${window.siyuan.config.system.networkProxy.scheme}://${window.siyuan.config.system.networkProxy.host}:${window.siyuan.config.system.networkProxy.port}`, }).then(() => { exportLayout({ errorExit: false, cb() { window.location.reload(); }, }); }); /// #endif }); }); } };