Vanessa 2024-10-18 00:36:52 +08:00
parent cabe855372
commit e674cfec70
4 changed files with 17 additions and 1 deletions

View file

@ -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";

View file

@ -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")) {

View file

@ -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);

View file

@ -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]);