diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.ts index 533743e82..2e9b0be90 100644 --- a/app/src/layout/dock/Files.ts +++ b/app/src/layout/dock/Files.ts @@ -21,11 +21,6 @@ import {isTouchDevice} from "../../util/functions"; import {App} from "../../index"; import {refreshFileTree} from "../../dialog/processSystem"; -type filesPath = { - notebookId: string, - openPaths: string[] -} - export class Files extends Model { public element: HTMLElement; public parent: Tab; diff --git a/app/src/menus/workspace.ts b/app/src/menus/workspace.ts index f8e972d38..c4657b5fd 100644 --- a/app/src/menus/workspace.ts +++ b/app/src/menus/workspace.ts @@ -92,6 +92,7 @@ const editLayout = (layoutName?: string) => { layoutItem.name = value; layoutItem.time = new Date().getTime(); layoutItem.layout = getAllLayout(); + layoutItem.filesPaths = window.siyuan.storage[Constants.LOCAL_FILESPATHS]; setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]); return true; } @@ -103,6 +104,7 @@ const editLayout = (layoutName?: string) => { confirmDialog(window.siyuan.languages.save, window.siyuan.languages.exportTplTip, () => { item.layout = getAllLayout(); item.time = new Date().getTime(); + item.filesPaths = window.siyuan.storage[Constants.LOCAL_FILESPATHS]; setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]); }); return true; @@ -114,7 +116,8 @@ const editLayout = (layoutName?: string) => { window.siyuan.storage[Constants.LOCAL_LAYOUTS].push({ name: value, time: new Date().getTime(), - layout: getAllLayout() + layout: getAllLayout(), + filesPaths: window.siyuan.storage[Constants.LOCAL_FILESPATHS] }); setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]); }); @@ -344,7 +347,14 @@ export const workspaceMenu = (app: App, rect: DOMRect) => { window.location.reload(); } else { fetchPost("/api/system/setUILayout", {layout: item.layout}, () => { - window.location.reload(); + if (item.filesPaths) { + window.siyuan.storage[Constants.LOCAL_FILESPATHS] = item.filesPaths; + setStorageVal(Constants.LOCAL_FILESPATHS, item.filesPaths, () => { + window.location.reload(); + }); + } else { + window.location.reload(); + } }); } }); diff --git a/app/src/mobile/dock/MobileFiles.ts b/app/src/mobile/dock/MobileFiles.ts index 1afc7c23a..3408020cd 100644 --- a/app/src/mobile/dock/MobileFiles.ts +++ b/app/src/mobile/dock/MobileFiles.ts @@ -17,11 +17,6 @@ import {App} from "../../index"; import {refreshFileTree} from "../../dialog/processSystem"; import {setStorageVal} from "../../protyle/util/compatibility"; -type filesPath = { - notebookId: string, - openPaths: string[] -} - export class MobileFiles extends Model { public element: HTMLElement; private actionsElement: HTMLElement; diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts index fcf3fe856..49b1741a5 100644 --- a/app/src/protyle/util/compatibility.ts +++ b/app/src/protyle/util/compatibility.ts @@ -194,7 +194,7 @@ export const getLocalStorage = (cb: () => void) => { dark: "dark", annoColor: "var(--b3-pdf-background1)" }; - defaultStorage[Constants.LOCAL_LAYOUTS] = []; // {name: "", layout:{}, time: number} + defaultStorage[Constants.LOCAL_LAYOUTS] = []; // {name: "", layout:{}, time: number, filespaths: filesPath[]} defaultStorage[Constants.LOCAL_AI] = []; // {name: "", memo: ""} defaultStorage[Constants.LOCAL_PLUGINTOPUNPIN] = []; defaultStorage[Constants.LOCAL_OUTLINE] = {keepExpand: true}; @@ -231,7 +231,7 @@ export const getLocalStorage = (cb: () => void) => { id: "", }; defaultStorage[Constants.LOCAL_FONTSTYLES] = []; - defaultStorage[Constants.LOCAL_FILESPATHS] = []; + defaultStorage[Constants.LOCAL_FILESPATHS] = []; // filesPath[] defaultStorage[Constants.LOCAL_SEARCHDATA] = { page: 1, sort: 0, @@ -292,7 +292,7 @@ export const getLocalStorage = (cb: () => void) => { }); }; -export const setStorageVal = (key: string, val: any) => { +export const setStorageVal = (key: string, val: any, cb?:()=>void) => { if (window.siyuan.config.readonly) { return; } @@ -301,5 +301,9 @@ export const setStorageVal = (key: string, val: any) => { app: Constants.SIYUAN_APPID, key, val, + }, () => { + if (cb) { + cb(); + } }); }; diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index e19105269..9e78638d4 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -192,6 +192,11 @@ interface Window { destroyTheme(): Promise } +interface filesPath { + notebookId: string, + openPaths: string[] +} + interface IPosition { x: number, y: number, @@ -204,6 +209,7 @@ interface ISaveLayout { name: string, layout: IObject time: number + filesPaths: filesPath[] } interface IWorkspace {