Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/6965

Vanessa00eaf9b4b490
diff --git a/app/src/asset/index.ts b/app/src/asset/index.ts
index 6ba5113d64..5aeab591ad 100644
--- a/app/src/asset/index.ts
+++ b/app/src/asset/index.ts
@@ -9,6 +9,7 @@ import {webViewerLoad} from "./pdf/viewer";
import {webViewerPageNumberChanged} from "./pdf/app";
/// #endif
import {fetchPost} from "../util/fetch";
+import { setStorageVal } from "../protyle/util/compatibility";
export class Asset extends Model {
public path: string;
@@ -445,6 +446,7 @@ export class Asset extends Model {
this.element.firstElementChild.classList.remove("pdf__outer--dark");
lightElement.classList.add("toggled");
darkElement.classList.remove("toggled");
+ setStorageVal(Constants.LOCAL_PDFTHEME, window.siyuan.storage[Constants.LOCAL_PDFTHEME]);
});
darkElement.addEventListener("click", () => {
if (window.siyuan.config.appearance.mode === 0) {
@@ -455,6 +457,7 @@ export class Asset extends Model {
this.element.firstElementChild.classList.add("pdf__outer--dark");
lightElement.classList.remove("toggled");
darkElement.classList.add("toggled");
+ setStorageVal(Constants.LOCAL_PDFTHEME, window.siyuan.storage[Constants.LOCAL_PDFTHEME]);
});
// 初始化完成后需等待页签是否显示设置完成,才可以判断 pdf 是否能进行渲染
setTimeout(() => {
diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.ts
index c5a948c266..81f112cb7e 100644
--- a/app/src/config/bazaar.ts
+++ b/app/src/config/bazaar.ts
@@ -11,6 +11,7 @@ import {shell} from "electron";
import * as path from "path";
/// #endif
import {isBrowser} from "../util/functions";
+import {setStorageVal} from "../protyle/util/compatibility";
export const bazaar = {
element: undefined as Element,
@@ -626,6 +627,7 @@ export const bazaar = {
});
}
localSort[selectElement.parentElement.parentElement.getAttribute("data-type")] = selectElement.value;
+ setStorageVal(Constants.LOCAL_BAZAAR, window.siyuan.storage[Constants.LOCAL_BAZAAR]);
panelElement.querySelector(".b3-cards").innerHTML = html;
}
});
diff --git a/app/src/constants.ts b/app/src/constants.ts
index 848de39469..d0363fb363 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -61,6 +61,7 @@ export abstract class Constants {
public static readonly LOCAL_SEARCHEDATA = "local-searchedata";
public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys";
public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile
+ public static readonly LOCAL_SEARCHEKEY = "local-searchkey"; // only mobile
public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid"; // string
public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; // string
public static readonly LOCAL_CODELANG = "local-codelang"; // string
diff --git a/app/src/history/history.ts b/app/src/history/history.ts
index 3ee7badc99..7e91bdda7a 100644
--- a/app/src/history/history.ts
+++ b/app/src/history/history.ts
@@ -10,6 +10,7 @@ import {fetchPost} from "../util/fetch";
import {escapeHtml} from "../util/escape";
import {isMobile} from "../util/functions";
import {showDiff} from "./diff";
+import {setStorageVal} from "../protyle/util/compatibility";
let historyEditor: Protyle;
const renderDoc = (element: HTMLElement, currentPage: number) => {
@@ -26,6 +27,7 @@ const renderDoc = (element: HTMLElement, currentPage: number) => {
const typeElement = element.querySelector('.b3-select[data-type="typeselect"]') as HTMLSelectElement;
const notebookElement = element.querySelector('.b3-select[data-type="notebookselect"]') as HTMLSelectElement;
window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID] = notebookElement.value;
+ setStorageVal(Constants.LOCAL_HISTORYNOTEID, window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID]);
const docElement = element.querySelector('.history__text[data-type="docPanel"]');
const assetElement = element.querySelector('.history__text[data-type="assetPanel"]');
const mdElement = element.querySelector('.history__text[data-type="mdPanel"]') as HTMLTextAreaElement;
diff --git a/app/src/index.ts b/app/src/index.ts
index 4f1f2dfc15..4394c8708e 100644
--- a/app/src/index.ts
+++ b/app/src/index.ts
@@ -21,8 +21,8 @@ import {
import {promiseTransactions} from "./protyle/wysiwyg/transaction";
import {initMessage} from "./dialog/message";
import {resizeDrag} from "./layout/util";
-import {setLocalStorage} from "./protyle/util/compatibility";
import {getAllTabs} from "./layout/getAll";
+import {getLocalStorage} from "./protyle/util/compatibility";
class App {
constructor() {
@@ -47,8 +47,8 @@ class App {
case"progress":
progressLoading(data);
break;
- case"setLocalStorage":
- setLocalStorage(data);
+ case"setLocalStorageVal":
+ window.siyuan.storage[data.data.key] = data.data.val;
break;
case "rename":
getAllTabs().forEach((tab) => {
@@ -127,7 +127,7 @@ class App {
};
fetchPost("/api/system/getConf", {}, response => {
window.siyuan.config = response.data.conf;
- setLocalStorage();
+ getLocalStorage();
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
window.siyuan.languages = lauguages;
bootSync();
diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts
index da2f18397d..4a74f5fef0 100644
--- a/app/src/layout/util.ts
+++ b/app/src/layout/util.ts
@@ -10,7 +10,7 @@ import {setPadding} from "../protyle/ui/initUI";
import {newFile} from "../util/newFile";
import {Outline} from "./dock/Outline";
import {Bookmark} from "./dock/Bookmark";
-import {exportLocalStorage, updateHotkeyTip} from "../protyle/util/compatibility";
+import {updateHotkeyTip} from "../protyle/util/compatibility";
import {Tag} from "./dock/Tag";
import {getAllModels, getAllTabs} from "./getAll";
import {Asset} from "../asset";
@@ -138,9 +138,7 @@ const dockToJSON = (dock: Dock) => {
export const resetLayout = () => {
fetchPost("/api/system/setUILayout", {layout: {}}, () => {
- exportLocalStorage(() => {
- window.location.reload();
- });
+ window.location.reload();
});
};
@@ -159,13 +157,11 @@ export const exportLayout = (reload: boolean, cb?: () => void) => {
};
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
fetchPost("/api/system/setUILayout", {layout: layoutJSON, exit: typeof cb !== "undefined"}, () => {
- exportLocalStorage(() => {
if (reload) {
window.location.reload();
} else if (cb) {
cb();
}
- });
});
};
@@ -541,7 +537,7 @@ export const copyTab = (tab: Tab) => {
});
};
-export const getInstanceById = (id: string, layout =window.siyuan.layout.centerLayout) => {
+export const getInstanceById = (id: string, layout = window.siyuan.layout.centerLayout) => {
const _getInstanceById = (item: Layout | Wnd, id: string) => {
if (item.id === id) {
return item;
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index 8f7b98c568..7fa643f59f 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -25,7 +25,7 @@ import {transaction, updateTransaction} from "../protyle/wysiwyg/transaction";
import {openMenu} from "./commonMenuItem";
import {fetchPost} from "../util/fetch";
import {Constants} from "../constants";
-import {copyPlainText, readText, writeText} from "../protyle/util/compatibility";
+import {copyPlainText, readText, setStorageVal, writeText} from "../protyle/util/compatibility";
import {preventScroll} from "../protyle/scroll/preventScroll";
import {onGet} from "../protyle/util/onGet";
import {getAllModels} from "../layout/getAll";
@@ -459,6 +459,7 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB
id,
action: id === protyle.block.rootID ? [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT] : [Constants.CB_GET_ALL]
};
+ setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
if (isPushBack) {
pushBack();
}
diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts
index f3a01ff99a..c2e2fc642f 100644
--- a/app/src/mobile/editor.ts
+++ b/app/src/mobile/editor.ts
@@ -12,9 +12,11 @@ import {hasClosestByAttribute} from "../protyle/util/hasClosest";
import {setEditMode} from "../protyle/util/setEditMode";
import {hideElements} from "../protyle/ui/hideElements";
import {pushBack} from "./util/MobileBackFoward";
+import {setStorageVal} from "../protyle/util/compatibility";
export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) => {
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id, action};
+ setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
if (window.siyuan.mobileEditor) {
hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle);
if (window.siyuan.mobileEditor.protyle.contentElement.classList.contains("fn__none")) {
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index 132a55ae8d..817eb83f6e 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -16,7 +16,7 @@ import {bootSync} from "../dialog/processSystem";
import {initMessage} from "../dialog/message";
import {goBack} from "./util/MobileBackFoward";
import {hideKeyboardToolbar, showKeyboardToolbar} from "./util/showKeyboardToolbar";
-import {setLocalStorage} from "../protyle/util/compatibility";
+import {getLocalStorage} from "../protyle/util/compatibility";
class App {
constructor() {
@@ -47,7 +47,7 @@ class App {
fetchPost("/api/system/getConf", {}, confResponse => {
confResponse.data.conf.keymap = Constants.SIYUAN_KEYMAP;
window.siyuan.config = confResponse.data.conf;
- setLocalStorage();
+ getLocalStorage();
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
window.siyuan.languages = lauguages;
document.title = window.siyuan.languages.siyuanNote;
diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.ts
index 77bcb87e33..1a54222cac 100644
--- a/app/src/mobile/util/MobileBackFoward.ts
+++ b/app/src/mobile/util/MobileBackFoward.ts
@@ -7,6 +7,7 @@ import {processRender} from "../../protyle/util/processCode";
import {highlightRender} from "../../protyle/markdown/highlightRender";
import {blockRender} from "../../protyle/markdown/blockRender";
import {disabledForeverProtyle, disabledProtyle, enableProtyle} from "../../protyle/util/onGet";
+import {setStorageVal} from "../../protyle/util/compatibility";
const forwardStack: IBackStack[] = [];
@@ -16,6 +17,7 @@ const focusStack = (backStack: IBackStack) => {
id: backStack.id,
action: backStack.callback,
};
+ setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle);
if (protyle.contentElement.classList.contains("fn__none")) {
setEditMode(protyle, "wysiwyg");
diff --git a/app/src/mobile/util/menu.ts b/app/src/mobile/util/menu.ts
index 50616c783c..72cd1b5df0 100644
--- a/app/src/mobile/util/menu.ts
+++ b/app/src/mobile/util/menu.ts
@@ -1,5 +1,5 @@
import {fetchPost} from "../../util/fetch";
-import {exportLocalStorage, getEventName, openByMobile, writeText} from "../../protyle/util/compatibility";
+import {getEventName, openByMobile, writeText} from "../../protyle/util/compatibility";
import {popSearch} from "./search";
import {initAppearance} from "../settings/appearance";
import {closePanel} from "./closePanel";
@@ -172,9 +172,7 @@ ${accountHTML}
event.stopPropagation();
break;
} else if (target.id === "menuSafeQuit") {
- exportLocalStorage(() => {
- exitSiYuan();
- });
+ exitSiYuan();
event.preventDefault();
event.stopPropagation();
break;
@@ -441,10 +439,8 @@ ${accountHTML}
event.stopPropagation();
break;
} else if (target.id === "menuLock") {
- exportLocalStorage(() => {
- fetchPost("/api/system/logoutAuth", {}, () => {
- window.location.href = "/";
- });
+ fetchPost("/api/system/logoutAuth", {}, () => {
+ window.location.href = "/";
});
event.preventDefault();
event.stopPropagation();
@@ -461,7 +457,6 @@ ${accountHTML}
event.stopPropagation();
break;
} else if (target.id === "menuSyncNow") {
- exportLocalStorage();
syncGuide();
event.preventDefault();
event.stopPropagation();
diff --git a/app/src/mobile/util/search.ts b/app/src/mobile/util/search.ts
index ac310663ca..6df65a1973 100644
--- a/app/src/mobile/util/search.ts
+++ b/app/src/mobile/util/search.ts
@@ -4,6 +4,7 @@ import {Constants} from "../../constants";
import {fetchPost} from "../../util/fetch";
import {getIconByType} from "../../editor/getIcon";
import {preventScroll} from "../../protyle/scroll/preventScroll";
+import {setStorageVal} from "../../protyle/util/compatibility";
const onRecentBlocks = (data: IBlock[], matchedRootCount?:number, matchedBlockCount?:number) => {
let resultHTML = "";
@@ -37,14 +38,15 @@ export const toolbarSearchEvent = () => {
onRecentBlocks(response.data.blocks, response.data.matchedRootCount,response.data.matchedBlockCount);
});
}
- window.siyuan.storage[Constants.LOCAL_SEARCHEDATA].k = inputElement.value;
+ window.siyuan.storage[Constants.LOCAL_SEARCHEKEY] = inputElement.value;
+ setStorageVal(Constants.LOCAL_SEARCHEKEY, window.siyuan.storage[Constants.LOCAL_SEARCHEKEY]);
}, Constants.TIMEOUT_SEARCH);
};
const initToolbarSearch = () => {
const inputElement = document.getElementById("toolbarSearch") as HTMLInputElement;
inputElement.focus();
- inputElement.value = window.siyuan.storage[Constants.LOCAL_SEARCHEDATA].k;
+ inputElement.value = window.siyuan.storage[Constants.LOCAL_SEARCHEKEY];
inputElement.addEventListener("compositionend", (event: InputEvent) => {
if (event && event.isComposing) {
return;
diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts
index 523a74cd95..bd26642a6f 100644
--- a/app/src/protyle/export/index.ts
+++ b/app/src/protyle/export/index.ts
@@ -14,6 +14,7 @@ import {Dialog} from "../../dialog";
import {lockFile} from "../../dialog/processSystem";
import {pathPosix} from "../../util/pathName";
import {replaceLocalPath} from "../../editor/rename";
+import {setStorageVal} from "../util/compatibility";
export const saveExport = (option: { type: string, id: string }) => {
/// #if !BROWSER
@@ -59,6 +60,7 @@ export const saveExport = (option: { type: string, id: string }) => {
const removeAssets = (wordDialog.element.querySelector("#removeAssets") as HTMLInputElement).checked;
const mergeSubdocs = (wordDialog.element.querySelector("#mergeSubdocs") as HTMLInputElement).checked;
window.siyuan.storage[Constants.LOCAL_EXPORTWORD] = {removeAssets, mergeSubdocs};
+ setStorageVal(Constants.LOCAL_EXPORTWORD, window.siyuan.storage[Constants.LOCAL_EXPORTWORD]);
getExportPath(option, removeAssets, mergeSubdocs);
wordDialog.destroy();
});
diff --git a/app/src/protyle/toolbar/Font.ts b/app/src/protyle/toolbar/Font.ts
index b22cd23417..51c17660cf 100644
--- a/app/src/protyle/toolbar/Font.ts
+++ b/app/src/protyle/toolbar/Font.ts
@@ -1,4 +1,4 @@
-import {getEventName, updateHotkeyTip} from "../util/compatibility";
+import {getEventName, setStorageVal, updateHotkeyTip} from "../util/compatibility";
import {ToolbarItem} from "./ToolbarItem";
import {setPosition} from "../../util/setPosition";
import {getSelectionPosition} from "../util/selection";
@@ -143,6 +143,7 @@ export const fontEvent = (protyle: IProtyle, type?: string, color?: string) => {
if (localFontStyles.length > 8) {
localFontStyles.splice(7, 1);
}
+ setStorageVal(Constants.LOCAL_FONTSTYLES, window.siyuan.storage[Constants.LOCAL_FONTSTYLES]);
} else {
if (localFontStyles.length === 0) {
type = "color";
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index 577d1bbf76..429ad1409a 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -15,7 +15,7 @@ import {Link} from "./Link";
import {setPosition} from "../../util/setPosition";
import {updateTransaction} from "../wysiwyg/transaction";
import {Constants} from "../../constants";
-import {getEventName, openByMobile} from "../util/compatibility";
+import {getEventName, openByMobile, setStorageVal} from "../util/compatibility";
import {upDownHint} from "../../util/upDownHint";
import {highlightRender} from "../markdown/highlightRender";
import {getContenteditableElement, hasNextSibling, hasPreviousSibling} from "../wysiwyg/getBlock";
@@ -1163,6 +1163,7 @@ export class Toolbar {
const activeText = this.subElement.querySelector(".b3-list-item--focus").textContent;
languageElement.textContent = activeText === window.siyuan.languages.clear ? "" : activeText;
window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent;
+ setStorageVal(Constants.LOCAL_CODELANG, window.siyuan.storage[Constants.LOCAL_CODELANG]);
const editElement = getContenteditableElement(nodeElement);
const lineNumber = nodeElement.getAttribute("linenumber");
if (lineNumber === "true" || (lineNumber !== "false" && window.siyuan.config.editor.codeSyntaxHighlightLineNum)) {
@@ -1227,6 +1228,7 @@ export class Toolbar {
}
languageElement.textContent = listElement.textContent === window.siyuan.languages.clear ? "" : listElement.textContent;
window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent;
+ setStorageVal(Constants.LOCAL_CODELANG, window.siyuan.storage[Constants.LOCAL_CODELANG]);
const nodeElement = hasClosestBlock(languageElement);
if (nodeElement) {
const editElement = getContenteditableElement(nodeElement);
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index 49045b005d..f20133756a 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -139,94 +139,83 @@ export const hotKey2Electron = (key: string) => {
return electronKey + key.substr(key.length - 1);
};
-export const setLocalStorage = (data?: IWebSocketData) => {
- if (data) {
- setDefaultStorage(data);
- } else {
- fetchPost("/api/storage/getLocalStorage", undefined, (response) => {
- setDefaultStorage(response);
- });
- }
-};
-
-const setDefaultStorage = (response: IWebSocketData) => {
- window.siyuan.storage = response.data;
- // 历史数据迁移
- const defaultStorage: any = {};
- defaultStorage[Constants.LOCAL_SEARCHEKEYS] = {
- keys: [],
- replaceKeys: [],
- col: "",
- row: "",
- layout: 0
- };
- defaultStorage[Constants.LOCAL_PDFTHEME] = {light: "light", dark: "dark"};
- defaultStorage[Constants.LOCAL_BAZAAR] = {
- theme: "0",
- template: "0",
- icon: "0",
- widget: "0",
- };
- defaultStorage[Constants.LOCAL_EXPORTWORD] = {removeAssets: false, mergeSubdocs: false};
- defaultStorage[Constants.LOCAL_EXPORTPDF] = {
- landscape: false,
- marginType: "0",
- scale: 1,
- pageSize: "A4",
- removeAssets: true,
- keepFold: false,
- mergeSubdocs: false,
- };
- defaultStorage[Constants.LOCAL_DOCINFO] = {
- id: "",
- action: []
- };
- defaultStorage[Constants.LOCAL_FONTSTYLES] = [];
- defaultStorage[Constants.LOCAL_SEARCHEDATA] = {
- sort: 0,
- group: 0,
- hasReplace: false,
- method: 0,
- hPath: "",
- idPath: [],
- k: "",
- r: "",
- types: {
- document: window.siyuan.config.search.document,
- heading: window.siyuan.config.search.heading,
- list: window.siyuan.config.search.list,
- listItem: window.siyuan.config.search.listItem,
- codeBlock: window.siyuan.config.search.codeBlock,
- htmlBlock: window.siyuan.config.search.htmlBlock,
- mathBlock: window.siyuan.config.search.mathBlock,
- table: window.siyuan.config.search.table,
- blockquote: window.siyuan.config.search.blockquote,
- superBlock: window.siyuan.config.search.superBlock,
- paragraph: window.siyuan.config.search.paragraph,
- }
- };
-
- [Constants.LOCAL_SEARCHEKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR, Constants.LOCAL_EXPORTWORD,
- Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES, Constants.LOCAL_SEARCHEDATA].forEach((key) => {
- if (typeof response.data[key] === "string") {
- try {
- window.siyuan.storage[key] = Object.assign(defaultStorage[key], JSON.parse(response.data[key]));
- } catch (e) {
+export const getLocalStorage = () => {
+ fetchPost("/api/storage/getLocalStorage", undefined, (response) => {
+ window.siyuan.storage = response.data;
+ // 历史数据迁移
+ const defaultStorage: any = {};
+ defaultStorage[Constants.LOCAL_SEARCHEKEYS] = {
+ keys: [],
+ replaceKeys: [],
+ col: "",
+ row: "",
+ layout: 0
+ };
+ defaultStorage[Constants.LOCAL_PDFTHEME] = {light: "light", dark: "dark"};
+ defaultStorage[Constants.LOCAL_BAZAAR] = {
+ theme: "0",
+ template: "0",
+ icon: "0",
+ widget: "0",
+ };
+ defaultStorage[Constants.LOCAL_EXPORTWORD] = {removeAssets: false, mergeSubdocs: false};
+ defaultStorage[Constants.LOCAL_EXPORTPDF] = {
+ landscape: false,
+ marginType: "0",
+ scale: 1,
+ pageSize: "A4",
+ removeAssets: true,
+ keepFold: false,
+ mergeSubdocs: false,
+ };
+ defaultStorage[Constants.LOCAL_DOCINFO] = {
+ id: "",
+ action: []
+ };
+ defaultStorage[Constants.LOCAL_FONTSTYLES] = [];
+ defaultStorage[Constants.LOCAL_SEARCHEDATA] = {
+ sort: 0,
+ group: 0,
+ hasReplace: false,
+ method: 0,
+ hPath: "",
+ idPath: [],
+ k: "",
+ r: "",
+ types: {
+ document: window.siyuan.config.search.document,
+ heading: window.siyuan.config.search.heading,
+ list: window.siyuan.config.search.list,
+ listItem: window.siyuan.config.search.listItem,
+ codeBlock: window.siyuan.config.search.codeBlock,
+ htmlBlock: window.siyuan.config.search.htmlBlock,
+ mathBlock: window.siyuan.config.search.mathBlock,
+ table: window.siyuan.config.search.table,
+ blockquote: window.siyuan.config.search.blockquote,
+ superBlock: window.siyuan.config.search.superBlock,
+ paragraph: window.siyuan.config.search.paragraph,
+ }
+ };
+
+ [Constants.LOCAL_SEARCHEKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR, Constants.LOCAL_EXPORTWORD,
+ Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES, Constants.LOCAL_SEARCHEDATA].forEach((key) => {
+ if (typeof response.data[key] === "string") {
+ try {
+ window.siyuan.storage[key] = Object.assign(defaultStorage[key], JSON.parse(response.data[key]));
+ } catch (e) {
+ window.siyuan.storage[key] = defaultStorage[key];
+ }
+ } else if (typeof response.data[key] === "undefined") {
window.siyuan.storage[key] = defaultStorage[key];
}
- } else if (typeof response.data[key] === "undefined") {
- window.siyuan.storage[key] = defaultStorage[key];
- }
+ });
});
};
-export const exportLocalStorage = (cb?: () => void) => {
- fetchPost("/api/storage/setLocalStorage", {
+export const setStorageVal = (key: string, val: any) => {
+ fetchPost("/api/storage/setLocalStorageVal", {
app: Constants.SIYUAN_APPID,
- val: window.siyuan.storage,
- }, () => {
- if (cb) {
- cb();
- }
+ key,
+ val,
});
};
diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts
index ad8a7f97ec..7e6ccf1873 100644
--- a/app/src/protyle/wysiwyg/enter.ts
+++ b/app/src/protyle/wysiwyg/enter.ts
@@ -13,6 +13,7 @@ import {highlightRender} from "../markdown/highlightRender";
import {Constants} from "../../constants";
import {scrollCenter} from "../../util/highlightById";
import {hideElements} from "../ui/hideElements";
+import {setStorageVal} from "../util/compatibility";
const listEnter = (protyle: IProtyle, blockElement: HTMLElement, range: Range) => {
const listItemElement = blockElement.parentElement;
@@ -248,6 +249,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
languageElement.textContent = window.siyuan.storage[Constants.LOCAL_CODELANG];
} else {
window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent;
+ setStorageVal(Constants.LOCAL_CODELANG, window.siyuan.storage[Constants.LOCAL_CODELANG]);
}
highlightRender(blockElement);
} else {
diff --git a/app/src/search/util.ts b/app/src/search/util.ts
index c48e42a0e8..3218a072aa 100644
--- a/app/src/search/util.ts
+++ b/app/src/search/util.ts
@@ -18,6 +18,7 @@ import {getIconByType} from "../editor/getIcon";
import {unicode2Emoji} from "../emoji";
import {Dialog} from "../dialog";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
+import {setStorageVal} from "../protyle/util/compatibility";
const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][type];
@@ -28,6 +29,7 @@ const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
}
// new Set 后需重新赋值
window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][type] = list;
+ setStorageVal(Constants.LOCAL_SEARCHEKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]);
};
export const openGlobalSearch = (text: string, replace: boolean) => {
@@ -235,6 +237,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
documentSelf.onselectstart = null;
documentSelf.onselect = null;
window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][direction === "lr" ? "col" : "row"] = nextElement[direction === "lr" ? "clientWidth" : "clientHeight"] + "px";
+ setStorageVal(Constants.LOCAL_SEARCHEKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]);
if (direction === "lr") {
setPadding(edit.protyle);
}
@@ -704,6 +707,7 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element:
}
setPadding(edit.protyle);
localData.layout = 0;
+ setStorageVal(Constants.LOCAL_SEARCHEKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]);
}
}, {
label: window.siyuan.languages.leftRightLayout,
@@ -719,6 +723,7 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element:
}
setPadding(edit.protyle);
localData.layout = 1;
+ setStorageVal(Constants.LOCAL_SEARCHEKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]);
}
}]
}).element);
@@ -871,6 +876,7 @@ const updateConfig = (element: Element, item: ISearchOption, config: ISearchOpti
(element.querySelector("#replaceInput") as HTMLInputElement).value = item.r;
Object.assign(config, item);
window.siyuan.storage[Constants.LOCAL_SEARCHEDATA] = Object.assign({}, config);
+ setStorageVal(Constants.LOCAL_SEARCHEDATA, window.siyuan.storage[Constants.LOCAL_SEARCHEDATA]);
inputEvent(element, config, undefined, edit);
window.siyuan.menus.menu.remove();
};
diff --git a/app/src/util/fetch.ts b/app/src/util/fetch.ts
index f1127c5562..5080798453 100644
--- a/app/src/util/fetch.ts
+++ b/app/src/util/fetch.ts
@@ -46,7 +46,7 @@ export const fetchPost = (url: string, data?: any, cb?: (response: IWebSocketDat
}
/// #if !BROWSER
if (url === "/api/system/exit" || url === "/api/system/setWorkspaceDir" || (
- ["/api/system/setUILayout", "/api/storage/setLocalStorage"].includes(url) && data.exit // 内核中断,点关闭处理
+ ["/api/system/setUILayout"].includes(url) && data.exit // 内核中断,点关闭处理
)) {
ipcRenderer.send(Constants.SIYUAN_CONFIG_CLOSETRAY);
ipcRenderer.send(Constants.SIYUAN_QUIT);
diff --git a/app/src/util/mount.ts b/app/src/util/mount.ts
index 022a8bb5e4..9dffcf7054 100644
--- a/app/src/util/mount.ts
+++ b/app/src/util/mount.ts
@@ -5,6 +5,7 @@ import {fetchPost} from "./fetch";
import {Dialog} from "../dialog";
import {getNotebookName, getOpenNotebookCount} from "./pathName";
import {validateName} from "../editor/rename";
+import {setStorageVal} from "../protyle/util/compatibility";
export const newDailyNote = () => {
const exit = window.siyuan.dialogs.find(item => {
@@ -67,6 +68,7 @@ export const newDailyNote = () => {
btnsElement[1].addEventListener("click", () => {
const notebook = selectElement.value;
window.siyuan.storage[Constants.LOCAL_DAILYNOTEID] = notebook;
+ setStorageVal(Constants.LOCAL_DAILYNOTEID, window.siyuan.storage[Constants.LOCAL_DAILYNOTEID]);
fetchPost("/api/filetree/createDailyNote", {
notebook,
app: Constants.SIYUAN_APPID,
diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts
index e9183c8b11..8605a10036 100644
--- a/app/src/util/onGetConfig.ts
+++ b/app/src/util/onGetConfig.ts
@@ -1,6 +1,6 @@
import {openSearch} from "../search/spread";
import {exportLayout, JSONToLayout, resetLayout, resizeDrag, resizeTabs} from "../layout/util";
-import {hotKey2Electron, updateHotkeyTip} from "../protyle/util/compatibility";
+import {hotKey2Electron, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
/// #if !BROWSER
import {dialog, getCurrentWindow} from "@electron/remote";
import {ipcRenderer, OpenDialogReturnValue} from "electron";
@@ -293,6 +293,7 @@ const initBar = () => {
app: Constants.SIYUAN_APPID,
});
window.siyuan.storage[Constants.LOCAL_DAILYNOTEID] = item.id;
+ setStorageVal(Constants.LOCAL_DAILYNOTEID, window.siyuan.storage[Constants.LOCAL_DAILYNOTEID]);
}
}).element);
}
@@ -389,6 +390,7 @@ const initWindow = () => {
pageSize: ipcData.pdfOptions.pageSize,
scale: ipcData.pdfOptions.scale,
};
+ setStorageVal(Constants.LOCAL_EXPORTPDF, window.siyuan.storage[Constants.LOCAL_EXPORTPDF]);
try {
if (window.siyuan.config.export.addFooter) {
ipcData.pdfOptions.displayHeaderFooter = true;