Browse Source

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

Vanessa 10 months ago
parent
commit
92ddab06ea

+ 0 - 5
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;

+ 12 - 2
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();
+                                }
                             });
                         }
                     });

+ 0 - 5
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;

+ 7 - 3
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();
+        }
     });
 };

+ 6 - 0
app/src/types/index.d.ts

@@ -192,6 +192,11 @@ interface Window {
     destroyTheme(): Promise<void>
 }
 
+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 {