Vanessa 2023-01-01 14:08:29 +08:00
parent 853ba5be3a
commit e007324aa6
2 changed files with 79 additions and 68 deletions

View file

@ -47,6 +47,9 @@ class App {
case"progress": case"progress":
progressLoading(data); progressLoading(data);
break; break;
case"setLocalStorage":
setLocalStorage(data);
break;
case "rename": case "rename":
getAllTabs().forEach((tab) => { getAllTabs().forEach((tab) => {
if (tab.headElement) { if (tab.headElement) {

View file

@ -139,8 +139,17 @@ export const hotKey2Electron = (key: string) => {
return electronKey + key.substr(key.length - 1); return electronKey + key.substr(key.length - 1);
}; };
export const setLocalStorage = () => { export const setLocalStorage = (data?: IWebSocketData) => {
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 = {};
@ -209,8 +218,7 @@ export const setLocalStorage = () => {
window.siyuan.storage[key] = defaultStorage[key]; window.siyuan.storage[key] = defaultStorage[key];
} }
}); });
}); }
};
export const exportLocalStorage = (cb?: () => void) => { export const exportLocalStorage = (cb?: () => void) => {
fetchPost("/api/storage/setLocalStorage", {val: window.siyuan.storage}, () => { fetchPost("/api/storage/setLocalStorage", {val: window.siyuan.storage}, () => {