From e674cfec703b5e9f990b55d272aab88c0afc890c Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 18 Oct 2024 00:36:52 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/11931 --- app/src/constants.ts | 1 + app/src/plugin/loader.ts | 9 +++++++++ app/src/plugin/uninstall.ts | 4 ++++ app/src/protyle/util/compatibility.ts | 4 +++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/constants.ts b/app/src/constants.ts index d2df4b00a..7b334e4a6 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -121,6 +121,7 @@ export abstract class Constants { public static readonly LOCAL_DIALOGPOSITION = "local-dialogposition"; public static readonly LOCAL_SESSION_FIRSTLOAD = "local-session-firstload"; public static readonly LOCAL_OUTLINE = "local-outline"; + public static readonly LOCAL_PLUGIN_DOCKS = "local-plugin-docks"; // dialog public static readonly DIALOG_OPENCARD = "dialog-opencard"; diff --git a/app/src/plugin/loader.ts b/app/src/plugin/loader.ts index c5daf82ee..93a8dec7a 100644 --- a/app/src/plugin/loader.ts +++ b/app/src/plugin/loader.ts @@ -8,6 +8,7 @@ import {API} from "./API"; import {getFrontend, isMobile, isWindow} from "../util/functions"; import {Constants} from "../constants"; import {uninstall} from "./uninstall"; +import {setStorageVal} from "../protyle/util/compatibility"; const requireFunc = (key: string) => { const modules = { @@ -102,6 +103,11 @@ const updateDock = (dockItem: Config.IUILayoutDockTab[], index: number, plugin: plugin.docks[tabItem.type].config.index = tabIndex; plugin.docks[tabItem.type].config.show = tabItem.show; plugin.docks[tabItem.type].config.size = tabItem.size; + if (!window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name]) { + window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name] = {} + } + window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][tabItem.type] = plugin.docks[tabItem.type].config; + setStorageVal(Constants.LOCAL_PLUGIN_DOCKS, window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS]); } }); }; @@ -153,6 +159,9 @@ export const afterLoadPlugin = (plugin: Plugin) => { updateDock(dockItem, index, plugin, "Bottom"); }); Object.keys(plugin.docks).forEach(key => { + if (window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key]) { + plugin.docks[key].config = window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key]; + } const dock = plugin.docks[key]; const hotkey = window.siyuan.config.keymap.plugin[plugin.name] ? window.siyuan.config.keymap.plugin[plugin.name][key]?.custom : undefined; if (dock.config.position.startsWith("Left")) { diff --git a/app/src/plugin/uninstall.ts b/app/src/plugin/uninstall.ts index fcc7c7ecd..09280fc65 100644 --- a/app/src/plugin/uninstall.ts +++ b/app/src/plugin/uninstall.ts @@ -4,6 +4,8 @@ import {Plugin} from "../plugin"; import {getAllModels} from "../layout/getAll"; import {resizeTopBar} from "../layout/util"; /// #endif +import {Constants} from "../constants"; +import {setStorageVal} from "../protyle/util/compatibility"; export const uninstall = (app: App, name: string, isUninstall = false) => { app.plugins.find((plugin: Plugin, index) => { @@ -13,6 +15,8 @@ export const uninstall = (app: App, name: string, isUninstall = false) => { plugin.onunload(); if (isUninstall) { plugin.uninstall(); + window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name] = {}; + setStorageVal(Constants.LOCAL_PLUGIN_DOCKS, window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS]); } } catch (e) { console.error(`plugin ${plugin.name} onunload error:`, e); diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts index c68cedb42..402a45c6d 100644 --- a/app/src/protyle/util/compatibility.ts +++ b/app/src/protyle/util/compatibility.ts @@ -200,6 +200,7 @@ export const getLocalStorage = (cb: () => void) => { }; defaultStorage[Constants.LOCAL_LAYOUTS] = []; // {name: "", layout:{}, time: number, filespaths: filesPath[]} defaultStorage[Constants.LOCAL_AI] = []; // {name: "", memo: ""} + defaultStorage[Constants.LOCAL_PLUGIN_DOCKS] = {}; // { pluginName: {dockId: IPluginDockTab}} defaultStorage[Constants.LOCAL_PLUGINTOPUNPIN] = []; defaultStorage[Constants.LOCAL_OUTLINE] = {keepExpand: true}; defaultStorage[Constants.LOCAL_FILEPOSITION] = {}; // {id: IScrollAttr} @@ -270,7 +271,8 @@ export const getLocalStorage = (cb: () => void) => { Constants.LOCAL_SEARCHDATA, Constants.LOCAL_ZOOM, Constants.LOCAL_LAYOUTS, Constants.LOCAL_AI, Constants.LOCAL_PLUGINTOPUNPIN, Constants.LOCAL_SEARCHASSET, Constants.LOCAL_FLASHCARD, Constants.LOCAL_DIALOGPOSITION, Constants.LOCAL_SEARCHUNREF, Constants.LOCAL_HISTORY, - Constants.LOCAL_OUTLINE, Constants.LOCAL_FILEPOSITION, Constants.LOCAL_FILESPATHS].forEach((key) => { + Constants.LOCAL_OUTLINE, Constants.LOCAL_FILEPOSITION, Constants.LOCAL_FILESPATHS, + Constants.LOCAL_PLUGIN_DOCKS].forEach((key) => { if (typeof response.data[key] === "string") { try { const parseData = JSON.parse(response.data[key]);