diff --git a/app/src/config/about.ts b/app/src/config/about.ts index 0b1d5de18..b6a318cb3 100644 --- a/app/src/config/about.ts +++ b/app/src/config/about.ts @@ -3,11 +3,14 @@ import {Constants} from "../constants"; import {shell} from "electron"; import {dialog} from "@electron/remote"; /// #endif -import {isBrowser} from "../util/functions"; +import {isBrowser, isMobile} from "../util/functions"; import {fetchPost} from "../util/fetch"; import {setAccessAuthCode} from "./util"; import {exportLayout} from "../layout/util"; import {exitSiYuan} from "../dialog/processSystem"; +import {writeText} from "../protyle/util/compatibility"; +import {showMessage} from "../dialog/message"; +import {Dialog} from "../dialog"; export const about = { element: undefined as Element, @@ -81,14 +84,22 @@ export const about = {
-
+
${window.siyuan.languages.snapshotPassword}
${window.siyuan.languages.snapshotPasswordTip}
- +
+ + + +
@@ -188,10 +199,49 @@ export const about = { workspaceDirElement.value = window.siyuan.config.system.workspaceDir; }); /// #endif - const authCodeElement = about.element.querySelector("#authCode") as HTMLInputElement; - authCodeElement.addEventListener("click", () => { + about.element.querySelector("#authCode").addEventListener("click", () => { setAccessAuthCode(); }); + const importKeyElement = about.element.querySelector("#importKey") + importKeyElement.addEventListener("click", () => { + const passwordDialog = new Dialog({ + title: window.siyuan.languages.password, + content: `
+ +
+
+
+ +
`, + width: isMobile() ? "80vw" : "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.classList.add("fn__none"); + importKeyElement.previousElementSibling.classList.add("fn__none"); + importKeyElement.nextElementSibling.classList.remove("fn__none"); + }) + }); + }); + about.element.querySelector("#initKey").addEventListener("click", () => { + fetchPost("/api/repo/initRepoKey", {}, (response) => { + window.siyuan.config.repo.key = response.data.key + importKeyElement.classList.add("fn__none"); + importKeyElement.previousElementSibling.classList.add("fn__none"); + importKeyElement.nextElementSibling.classList.remove("fn__none"); + }) + }); + about.element.querySelector("#copyKey").addEventListener("click", () => { + showMessage(window.siyuan.languages.copied) + writeText(window.siyuan.config.repo.key) + }); const networkServeElement = about.element.querySelector("#networkServe") as HTMLInputElement; networkServeElement.addEventListener("change", () => { fetchPost("/api/system/setNetworkServe", {networkServe: networkServeElement.checked}, () => { diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 672ce2f47..7949fe022 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -238,6 +238,9 @@ declare interface IAccount { } declare interface IConfig { + repo: { + key: string + }, e2eePasswd: string e2eePasswdMode: number sync: {