Vanessa 2023-01-01 15:18:32 +08:00
parent 95bb18afe1
commit 00eaf9b4b4
21 changed files with 123 additions and 111 deletions

View file

@ -9,6 +9,7 @@ import {webViewerLoad} from "./pdf/viewer";
import {webViewerPageNumberChanged} from "./pdf/app"; import {webViewerPageNumberChanged} from "./pdf/app";
/// #endif /// #endif
import {fetchPost} from "../util/fetch"; import {fetchPost} from "../util/fetch";
import { setStorageVal } from "../protyle/util/compatibility";
export class Asset extends Model { export class Asset extends Model {
public path: string; public path: string;
@ -445,6 +446,7 @@ export class Asset extends Model {
this.element.firstElementChild.classList.remove("pdf__outer--dark"); this.element.firstElementChild.classList.remove("pdf__outer--dark");
lightElement.classList.add("toggled"); lightElement.classList.add("toggled");
darkElement.classList.remove("toggled"); darkElement.classList.remove("toggled");
setStorageVal(Constants.LOCAL_PDFTHEME, window.siyuan.storage[Constants.LOCAL_PDFTHEME]);
}); });
darkElement.addEventListener("click", () => { darkElement.addEventListener("click", () => {
if (window.siyuan.config.appearance.mode === 0) { if (window.siyuan.config.appearance.mode === 0) {
@ -455,6 +457,7 @@ export class Asset extends Model {
this.element.firstElementChild.classList.add("pdf__outer--dark"); this.element.firstElementChild.classList.add("pdf__outer--dark");
lightElement.classList.remove("toggled"); lightElement.classList.remove("toggled");
darkElement.classList.add("toggled"); darkElement.classList.add("toggled");
setStorageVal(Constants.LOCAL_PDFTHEME, window.siyuan.storage[Constants.LOCAL_PDFTHEME]);
}); });
// 初始化完成后需等待页签是否显示设置完成,才可以判断 pdf 是否能进行渲染 // 初始化完成后需等待页签是否显示设置完成,才可以判断 pdf 是否能进行渲染
setTimeout(() => { setTimeout(() => {

View file

@ -11,6 +11,7 @@ import {shell} from "electron";
import * as path from "path"; import * as path from "path";
/// #endif /// #endif
import {isBrowser} from "../util/functions"; import {isBrowser} from "../util/functions";
import {setStorageVal} from "../protyle/util/compatibility";
export const bazaar = { export const bazaar = {
element: undefined as Element, element: undefined as Element,
@ -626,6 +627,7 @@ export const bazaar = {
}); });
} }
localSort[selectElement.parentElement.parentElement.getAttribute("data-type")] = selectElement.value; 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; panelElement.querySelector(".b3-cards").innerHTML = html;
} }
}); });

View file

@ -61,6 +61,7 @@ export abstract class Constants {
public static readonly LOCAL_SEARCHEDATA = "local-searchedata"; public static readonly LOCAL_SEARCHEDATA = "local-searchedata";
public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys"; public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys";
public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile 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_DAILYNOTEID = "local-dailynoteid"; // string
public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; // string public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; // string
public static readonly LOCAL_CODELANG = "local-codelang"; // string public static readonly LOCAL_CODELANG = "local-codelang"; // string

View file

@ -10,6 +10,7 @@ import {fetchPost} from "../util/fetch";
import {escapeHtml} from "../util/escape"; import {escapeHtml} from "../util/escape";
import {isMobile} from "../util/functions"; import {isMobile} from "../util/functions";
import {showDiff} from "./diff"; import {showDiff} from "./diff";
import {setStorageVal} from "../protyle/util/compatibility";
let historyEditor: Protyle; let historyEditor: Protyle;
const renderDoc = (element: HTMLElement, currentPage: number) => { 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 typeElement = element.querySelector('.b3-select[data-type="typeselect"]') as HTMLSelectElement;
const notebookElement = element.querySelector('.b3-select[data-type="notebookselect"]') as HTMLSelectElement; const notebookElement = element.querySelector('.b3-select[data-type="notebookselect"]') as HTMLSelectElement;
window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID] = notebookElement.value; 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 docElement = element.querySelector('.history__text[data-type="docPanel"]');
const assetElement = element.querySelector('.history__text[data-type="assetPanel"]'); const assetElement = element.querySelector('.history__text[data-type="assetPanel"]');
const mdElement = element.querySelector('.history__text[data-type="mdPanel"]') as HTMLTextAreaElement; const mdElement = element.querySelector('.history__text[data-type="mdPanel"]') as HTMLTextAreaElement;

View file

@ -21,8 +21,8 @@ import {
import {promiseTransactions} from "./protyle/wysiwyg/transaction"; import {promiseTransactions} from "./protyle/wysiwyg/transaction";
import {initMessage} from "./dialog/message"; import {initMessage} from "./dialog/message";
import {resizeDrag} from "./layout/util"; import {resizeDrag} from "./layout/util";
import {setLocalStorage} from "./protyle/util/compatibility";
import {getAllTabs} from "./layout/getAll"; import {getAllTabs} from "./layout/getAll";
import {getLocalStorage} from "./protyle/util/compatibility";
class App { class App {
constructor() { constructor() {
@ -47,8 +47,8 @@ class App {
case"progress": case"progress":
progressLoading(data); progressLoading(data);
break; break;
case"setLocalStorage": case"setLocalStorageVal":
setLocalStorage(data); window.siyuan.storage[data.data.key] = data.data.val;
break; break;
case "rename": case "rename":
getAllTabs().forEach((tab) => { getAllTabs().forEach((tab) => {
@ -127,7 +127,7 @@ class App {
}; };
fetchPost("/api/system/getConf", {}, response => { fetchPost("/api/system/getConf", {}, response => {
window.siyuan.config = response.data.conf; window.siyuan.config = response.data.conf;
setLocalStorage(); getLocalStorage();
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => { fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
window.siyuan.languages = lauguages; window.siyuan.languages = lauguages;
bootSync(); bootSync();

View file

@ -10,7 +10,7 @@ import {setPadding} from "../protyle/ui/initUI";
import {newFile} from "../util/newFile"; import {newFile} from "../util/newFile";
import {Outline} from "./dock/Outline"; import {Outline} from "./dock/Outline";
import {Bookmark} from "./dock/Bookmark"; import {Bookmark} from "./dock/Bookmark";
import {exportLocalStorage, updateHotkeyTip} from "../protyle/util/compatibility"; import {updateHotkeyTip} from "../protyle/util/compatibility";
import {Tag} from "./dock/Tag"; import {Tag} from "./dock/Tag";
import {getAllModels, getAllTabs} from "./getAll"; import {getAllModels, getAllTabs} from "./getAll";
import {Asset} from "../asset"; import {Asset} from "../asset";
@ -138,10 +138,8 @@ const dockToJSON = (dock: Dock) => {
export const resetLayout = () => { export const resetLayout = () => {
fetchPost("/api/system/setUILayout", {layout: {}}, () => { fetchPost("/api/system/setUILayout", {layout: {}}, () => {
exportLocalStorage(() => {
window.location.reload(); window.location.reload();
}); });
});
}; };
export const exportLayout = (reload: boolean, cb?: () => void) => { export const exportLayout = (reload: boolean, cb?: () => void) => {
@ -159,14 +157,12 @@ export const exportLayout = (reload: boolean, cb?: () => void) => {
}; };
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout); layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
fetchPost("/api/system/setUILayout", {layout: layoutJSON, exit: typeof cb !== "undefined"}, () => { fetchPost("/api/system/setUILayout", {layout: layoutJSON, exit: typeof cb !== "undefined"}, () => {
exportLocalStorage(() => {
if (reload) { if (reload) {
window.location.reload(); window.location.reload();
} else if (cb) { } else if (cb) {
cb(); cb();
} }
}); });
});
}; };
const JSONToDock = (json: any) => { const JSONToDock = (json: any) => {
@ -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) => { const _getInstanceById = (item: Layout | Wnd, id: string) => {
if (item.id === id) { if (item.id === id) {
return item; return item;

View file

@ -25,7 +25,7 @@ import {transaction, updateTransaction} from "../protyle/wysiwyg/transaction";
import {openMenu} from "./commonMenuItem"; import {openMenu} from "./commonMenuItem";
import {fetchPost} from "../util/fetch"; import {fetchPost} from "../util/fetch";
import {Constants} from "../constants"; 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 {preventScroll} from "../protyle/scroll/preventScroll";
import {onGet} from "../protyle/util/onGet"; import {onGet} from "../protyle/util/onGet";
import {getAllModels} from "../layout/getAll"; import {getAllModels} from "../layout/getAll";
@ -459,6 +459,7 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB
id, id,
action: id === protyle.block.rootID ? [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT] : [Constants.CB_GET_ALL] 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) { if (isPushBack) {
pushBack(); pushBack();
} }

View file

@ -12,9 +12,11 @@ import {hasClosestByAttribute} from "../protyle/util/hasClosest";
import {setEditMode} from "../protyle/util/setEditMode"; import {setEditMode} from "../protyle/util/setEditMode";
import {hideElements} from "../protyle/ui/hideElements"; import {hideElements} from "../protyle/ui/hideElements";
import {pushBack} from "./util/MobileBackFoward"; import {pushBack} from "./util/MobileBackFoward";
import {setStorageVal} from "../protyle/util/compatibility";
export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) => { export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) => {
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id, action}; window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id, action};
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
if (window.siyuan.mobileEditor) { if (window.siyuan.mobileEditor) {
hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle); hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle);
if (window.siyuan.mobileEditor.protyle.contentElement.classList.contains("fn__none")) { if (window.siyuan.mobileEditor.protyle.contentElement.classList.contains("fn__none")) {

View file

@ -16,7 +16,7 @@ import {bootSync} from "../dialog/processSystem";
import {initMessage} from "../dialog/message"; import {initMessage} from "../dialog/message";
import {goBack} from "./util/MobileBackFoward"; import {goBack} from "./util/MobileBackFoward";
import {hideKeyboardToolbar, showKeyboardToolbar} from "./util/showKeyboardToolbar"; import {hideKeyboardToolbar, showKeyboardToolbar} from "./util/showKeyboardToolbar";
import {setLocalStorage} from "../protyle/util/compatibility"; import {getLocalStorage} from "../protyle/util/compatibility";
class App { class App {
constructor() { constructor() {
@ -47,7 +47,7 @@ class App {
fetchPost("/api/system/getConf", {}, confResponse => { fetchPost("/api/system/getConf", {}, confResponse => {
confResponse.data.conf.keymap = Constants.SIYUAN_KEYMAP; confResponse.data.conf.keymap = Constants.SIYUAN_KEYMAP;
window.siyuan.config = confResponse.data.conf; window.siyuan.config = confResponse.data.conf;
setLocalStorage(); getLocalStorage();
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => { fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
window.siyuan.languages = lauguages; window.siyuan.languages = lauguages;
document.title = window.siyuan.languages.siyuanNote; document.title = window.siyuan.languages.siyuanNote;

View file

@ -7,6 +7,7 @@ import {processRender} from "../../protyle/util/processCode";
import {highlightRender} from "../../protyle/markdown/highlightRender"; import {highlightRender} from "../../protyle/markdown/highlightRender";
import {blockRender} from "../../protyle/markdown/blockRender"; import {blockRender} from "../../protyle/markdown/blockRender";
import {disabledForeverProtyle, disabledProtyle, enableProtyle} from "../../protyle/util/onGet"; import {disabledForeverProtyle, disabledProtyle, enableProtyle} from "../../protyle/util/onGet";
import {setStorageVal} from "../../protyle/util/compatibility";
const forwardStack: IBackStack[] = []; const forwardStack: IBackStack[] = [];
@ -16,6 +17,7 @@ const focusStack = (backStack: IBackStack) => {
id: backStack.id, id: backStack.id,
action: backStack.callback, action: backStack.callback,
}; };
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle); hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle);
if (protyle.contentElement.classList.contains("fn__none")) { if (protyle.contentElement.classList.contains("fn__none")) {
setEditMode(protyle, "wysiwyg"); setEditMode(protyle, "wysiwyg");

View file

@ -1,5 +1,5 @@
import {fetchPost} from "../../util/fetch"; 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 {popSearch} from "./search";
import {initAppearance} from "../settings/appearance"; import {initAppearance} from "../settings/appearance";
import {closePanel} from "./closePanel"; import {closePanel} from "./closePanel";
@ -172,9 +172,7 @@ ${accountHTML}
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (target.id === "menuSafeQuit") { } else if (target.id === "menuSafeQuit") {
exportLocalStorage(() => {
exitSiYuan(); exitSiYuan();
});
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
break; break;
@ -441,11 +439,9 @@ ${accountHTML}
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (target.id === "menuLock") { } else if (target.id === "menuLock") {
exportLocalStorage(() => {
fetchPost("/api/system/logoutAuth", {}, () => { fetchPost("/api/system/logoutAuth", {}, () => {
window.location.href = "/"; window.location.href = "/";
}); });
});
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
break; break;
@ -461,7 +457,6 @@ ${accountHTML}
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (target.id === "menuSyncNow") { } else if (target.id === "menuSyncNow") {
exportLocalStorage();
syncGuide(); syncGuide();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();

View file

@ -4,6 +4,7 @@ import {Constants} from "../../constants";
import {fetchPost} from "../../util/fetch"; import {fetchPost} from "../../util/fetch";
import {getIconByType} from "../../editor/getIcon"; import {getIconByType} from "../../editor/getIcon";
import {preventScroll} from "../../protyle/scroll/preventScroll"; import {preventScroll} from "../../protyle/scroll/preventScroll";
import {setStorageVal} from "../../protyle/util/compatibility";
const onRecentBlocks = (data: IBlock[], matchedRootCount?:number, matchedBlockCount?:number) => { const onRecentBlocks = (data: IBlock[], matchedRootCount?:number, matchedBlockCount?:number) => {
let resultHTML = ""; let resultHTML = "";
@ -37,14 +38,15 @@ export const toolbarSearchEvent = () => {
onRecentBlocks(response.data.blocks, response.data.matchedRootCount,response.data.matchedBlockCount); 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); }, Constants.TIMEOUT_SEARCH);
}; };
const initToolbarSearch = () => { const initToolbarSearch = () => {
const inputElement = document.getElementById("toolbarSearch") as HTMLInputElement; const inputElement = document.getElementById("toolbarSearch") as HTMLInputElement;
inputElement.focus(); inputElement.focus();
inputElement.value = window.siyuan.storage[Constants.LOCAL_SEARCHEDATA].k; inputElement.value = window.siyuan.storage[Constants.LOCAL_SEARCHEKEY];
inputElement.addEventListener("compositionend", (event: InputEvent) => { inputElement.addEventListener("compositionend", (event: InputEvent) => {
if (event && event.isComposing) { if (event && event.isComposing) {
return; return;

View file

@ -14,6 +14,7 @@ import {Dialog} from "../../dialog";
import {lockFile} from "../../dialog/processSystem"; import {lockFile} from "../../dialog/processSystem";
import {pathPosix} from "../../util/pathName"; import {pathPosix} from "../../util/pathName";
import {replaceLocalPath} from "../../editor/rename"; import {replaceLocalPath} from "../../editor/rename";
import {setStorageVal} from "../util/compatibility";
export const saveExport = (option: { type: string, id: string }) => { export const saveExport = (option: { type: string, id: string }) => {
/// #if !BROWSER /// #if !BROWSER
@ -59,6 +60,7 @@ export const saveExport = (option: { type: string, id: string }) => {
const removeAssets = (wordDialog.element.querySelector("#removeAssets") as HTMLInputElement).checked; const removeAssets = (wordDialog.element.querySelector("#removeAssets") as HTMLInputElement).checked;
const mergeSubdocs = (wordDialog.element.querySelector("#mergeSubdocs") as HTMLInputElement).checked; const mergeSubdocs = (wordDialog.element.querySelector("#mergeSubdocs") as HTMLInputElement).checked;
window.siyuan.storage[Constants.LOCAL_EXPORTWORD] = {removeAssets, mergeSubdocs}; window.siyuan.storage[Constants.LOCAL_EXPORTWORD] = {removeAssets, mergeSubdocs};
setStorageVal(Constants.LOCAL_EXPORTWORD, window.siyuan.storage[Constants.LOCAL_EXPORTWORD]);
getExportPath(option, removeAssets, mergeSubdocs); getExportPath(option, removeAssets, mergeSubdocs);
wordDialog.destroy(); wordDialog.destroy();
}); });

View file

@ -1,4 +1,4 @@
import {getEventName, updateHotkeyTip} from "../util/compatibility"; import {getEventName, setStorageVal, updateHotkeyTip} from "../util/compatibility";
import {ToolbarItem} from "./ToolbarItem"; import {ToolbarItem} from "./ToolbarItem";
import {setPosition} from "../../util/setPosition"; import {setPosition} from "../../util/setPosition";
import {getSelectionPosition} from "../util/selection"; import {getSelectionPosition} from "../util/selection";
@ -143,6 +143,7 @@ export const fontEvent = (protyle: IProtyle, type?: string, color?: string) => {
if (localFontStyles.length > 8) { if (localFontStyles.length > 8) {
localFontStyles.splice(7, 1); localFontStyles.splice(7, 1);
} }
setStorageVal(Constants.LOCAL_FONTSTYLES, window.siyuan.storage[Constants.LOCAL_FONTSTYLES]);
} else { } else {
if (localFontStyles.length === 0) { if (localFontStyles.length === 0) {
type = "color"; type = "color";

View file

@ -15,7 +15,7 @@ import {Link} from "./Link";
import {setPosition} from "../../util/setPosition"; import {setPosition} from "../../util/setPosition";
import {updateTransaction} from "../wysiwyg/transaction"; import {updateTransaction} from "../wysiwyg/transaction";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import {getEventName, openByMobile} from "../util/compatibility"; import {getEventName, openByMobile, setStorageVal} from "../util/compatibility";
import {upDownHint} from "../../util/upDownHint"; import {upDownHint} from "../../util/upDownHint";
import {highlightRender} from "../markdown/highlightRender"; import {highlightRender} from "../markdown/highlightRender";
import {getContenteditableElement, hasNextSibling, hasPreviousSibling} from "../wysiwyg/getBlock"; import {getContenteditableElement, hasNextSibling, hasPreviousSibling} from "../wysiwyg/getBlock";
@ -1163,6 +1163,7 @@ export class Toolbar {
const activeText = this.subElement.querySelector(".b3-list-item--focus").textContent; const activeText = this.subElement.querySelector(".b3-list-item--focus").textContent;
languageElement.textContent = activeText === window.siyuan.languages.clear ? "" : activeText; languageElement.textContent = activeText === window.siyuan.languages.clear ? "" : activeText;
window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent; window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent;
setStorageVal(Constants.LOCAL_CODELANG, window.siyuan.storage[Constants.LOCAL_CODELANG]);
const editElement = getContenteditableElement(nodeElement); const editElement = getContenteditableElement(nodeElement);
const lineNumber = nodeElement.getAttribute("linenumber"); const lineNumber = nodeElement.getAttribute("linenumber");
if (lineNumber === "true" || (lineNumber !== "false" && window.siyuan.config.editor.codeSyntaxHighlightLineNum)) { 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; languageElement.textContent = listElement.textContent === window.siyuan.languages.clear ? "" : listElement.textContent;
window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent; window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent;
setStorageVal(Constants.LOCAL_CODELANG, window.siyuan.storage[Constants.LOCAL_CODELANG]);
const nodeElement = hasClosestBlock(languageElement); const nodeElement = hasClosestBlock(languageElement);
if (nodeElement) { if (nodeElement) {
const editElement = getContenteditableElement(nodeElement); const editElement = getContenteditableElement(nodeElement);

View file

@ -139,17 +139,8 @@ export const hotKey2Electron = (key: string) => {
return electronKey + key.substr(key.length - 1); return electronKey + key.substr(key.length - 1);
}; };
export const setLocalStorage = (data?: IWebSocketData) => { export const getLocalStorage = () => {
if (data) {
setDefaultStorage(data);
} else {
fetchPost("/api/storage/getLocalStorage", undefined, (response) => { fetchPost("/api/storage/getLocalStorage", undefined, (response) => {
setDefaultStorage(response);
});
}
};
const setDefaultStorage = (response: IWebSocketData) => {
window.siyuan.storage = response.data; window.siyuan.storage = response.data;
// 历史数据迁移 // 历史数据迁移
const defaultStorage: any = {}; const defaultStorage: any = {};
@ -218,15 +209,13 @@ const setDefaultStorage = (response: IWebSocketData) => {
window.siyuan.storage[key] = defaultStorage[key]; window.siyuan.storage[key] = defaultStorage[key];
} }
}); });
}; });
};
export const exportLocalStorage = (cb?: () => void) => {
fetchPost("/api/storage/setLocalStorage", { export const setStorageVal = (key: string, val: any) => {
app: Constants.SIYUAN_APPID, fetchPost("/api/storage/setLocalStorageVal", {
val: window.siyuan.storage, app: Constants.SIYUAN_APPID,
}, () => { key,
if (cb) { val,
cb();
}
}); });
}; };

View file

@ -13,6 +13,7 @@ import {highlightRender} from "../markdown/highlightRender";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import {scrollCenter} from "../../util/highlightById"; import {scrollCenter} from "../../util/highlightById";
import {hideElements} from "../ui/hideElements"; import {hideElements} from "../ui/hideElements";
import {setStorageVal} from "../util/compatibility";
const listEnter = (protyle: IProtyle, blockElement: HTMLElement, range: Range) => { const listEnter = (protyle: IProtyle, blockElement: HTMLElement, range: Range) => {
const listItemElement = blockElement.parentElement; 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]; languageElement.textContent = window.siyuan.storage[Constants.LOCAL_CODELANG];
} else { } else {
window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent; window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent;
setStorageVal(Constants.LOCAL_CODELANG, window.siyuan.storage[Constants.LOCAL_CODELANG]);
} }
highlightRender(blockElement); highlightRender(blockElement);
} else { } else {

View file

@ -18,6 +18,7 @@ import {getIconByType} from "../editor/getIcon";
import {unicode2Emoji} from "../emoji"; import {unicode2Emoji} from "../emoji";
import {Dialog} from "../dialog"; import {Dialog} from "../dialog";
import {hasClosestByClassName} from "../protyle/util/hasClosest"; import {hasClosestByClassName} from "../protyle/util/hasClosest";
import {setStorageVal} from "../protyle/util/compatibility";
const saveKeyList = (type: "keys" | "replaceKeys", value: string) => { const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][type]; let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][type];
@ -28,6 +29,7 @@ const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
} }
// new Set 后需重新赋值 // new Set 后需重新赋值
window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][type] = list; 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) => { export const openGlobalSearch = (text: string, replace: boolean) => {
@ -235,6 +237,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
documentSelf.onselectstart = null; documentSelf.onselectstart = null;
documentSelf.onselect = null; documentSelf.onselect = null;
window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][direction === "lr" ? "col" : "row"] = nextElement[direction === "lr" ? "clientWidth" : "clientHeight"] + "px"; 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") { if (direction === "lr") {
setPadding(edit.protyle); setPadding(edit.protyle);
} }
@ -704,6 +707,7 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element:
} }
setPadding(edit.protyle); setPadding(edit.protyle);
localData.layout = 0; localData.layout = 0;
setStorageVal(Constants.LOCAL_SEARCHEKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]);
} }
}, { }, {
label: window.siyuan.languages.leftRightLayout, label: window.siyuan.languages.leftRightLayout,
@ -719,6 +723,7 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element:
} }
setPadding(edit.protyle); setPadding(edit.protyle);
localData.layout = 1; localData.layout = 1;
setStorageVal(Constants.LOCAL_SEARCHEKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]);
} }
}] }]
}).element); }).element);
@ -871,6 +876,7 @@ const updateConfig = (element: Element, item: ISearchOption, config: ISearchOpti
(element.querySelector("#replaceInput") as HTMLInputElement).value = item.r; (element.querySelector("#replaceInput") as HTMLInputElement).value = item.r;
Object.assign(config, item); Object.assign(config, item);
window.siyuan.storage[Constants.LOCAL_SEARCHEDATA] = Object.assign({}, config); window.siyuan.storage[Constants.LOCAL_SEARCHEDATA] = Object.assign({}, config);
setStorageVal(Constants.LOCAL_SEARCHEDATA, window.siyuan.storage[Constants.LOCAL_SEARCHEDATA]);
inputEvent(element, config, undefined, edit); inputEvent(element, config, undefined, edit);
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
}; };

View file

@ -46,7 +46,7 @@ export const fetchPost = (url: string, data?: any, cb?: (response: IWebSocketDat
} }
/// #if !BROWSER /// #if !BROWSER
if (url === "/api/system/exit" || url === "/api/system/setWorkspaceDir" || ( 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_CONFIG_CLOSETRAY);
ipcRenderer.send(Constants.SIYUAN_QUIT); ipcRenderer.send(Constants.SIYUAN_QUIT);

View file

@ -5,6 +5,7 @@ import {fetchPost} from "./fetch";
import {Dialog} from "../dialog"; import {Dialog} from "../dialog";
import {getNotebookName, getOpenNotebookCount} from "./pathName"; import {getNotebookName, getOpenNotebookCount} from "./pathName";
import {validateName} from "../editor/rename"; import {validateName} from "../editor/rename";
import {setStorageVal} from "../protyle/util/compatibility";
export const newDailyNote = () => { export const newDailyNote = () => {
const exit = window.siyuan.dialogs.find(item => { const exit = window.siyuan.dialogs.find(item => {
@ -67,6 +68,7 @@ export const newDailyNote = () => {
btnsElement[1].addEventListener("click", () => { btnsElement[1].addEventListener("click", () => {
const notebook = selectElement.value; const notebook = selectElement.value;
window.siyuan.storage[Constants.LOCAL_DAILYNOTEID] = notebook; window.siyuan.storage[Constants.LOCAL_DAILYNOTEID] = notebook;
setStorageVal(Constants.LOCAL_DAILYNOTEID, window.siyuan.storage[Constants.LOCAL_DAILYNOTEID]);
fetchPost("/api/filetree/createDailyNote", { fetchPost("/api/filetree/createDailyNote", {
notebook, notebook,
app: Constants.SIYUAN_APPID, app: Constants.SIYUAN_APPID,

View file

@ -1,6 +1,6 @@
import {openSearch} from "../search/spread"; import {openSearch} from "../search/spread";
import {exportLayout, JSONToLayout, resetLayout, resizeDrag, resizeTabs} from "../layout/util"; 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 /// #if !BROWSER
import {dialog, getCurrentWindow} from "@electron/remote"; import {dialog, getCurrentWindow} from "@electron/remote";
import {ipcRenderer, OpenDialogReturnValue} from "electron"; import {ipcRenderer, OpenDialogReturnValue} from "electron";
@ -293,6 +293,7 @@ const initBar = () => {
app: Constants.SIYUAN_APPID, app: Constants.SIYUAN_APPID,
}); });
window.siyuan.storage[Constants.LOCAL_DAILYNOTEID] = item.id; window.siyuan.storage[Constants.LOCAL_DAILYNOTEID] = item.id;
setStorageVal(Constants.LOCAL_DAILYNOTEID, window.siyuan.storage[Constants.LOCAL_DAILYNOTEID]);
} }
}).element); }).element);
} }
@ -389,6 +390,7 @@ const initWindow = () => {
pageSize: ipcData.pdfOptions.pageSize, pageSize: ipcData.pdfOptions.pageSize,
scale: ipcData.pdfOptions.scale, scale: ipcData.pdfOptions.scale,
}; };
setStorageVal(Constants.LOCAL_EXPORTPDF, window.siyuan.storage[Constants.LOCAL_EXPORTPDF]);
try { try {
if (window.siyuan.config.export.addFooter) { if (window.siyuan.config.export.addFooter) {
ipcData.pdfOptions.displayHeaderFooter = true; ipcData.pdfOptions.displayHeaderFooter = true;