Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

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

Vanessacc62cbe6d943
diff --git a/app/src/layout/dock/index.ts b/app/src/layout/dock/index.ts
index 135646688d..44e36c40bc 100644
--- a/app/src/layout/dock/index.ts
+++ b/app/src/layout/dock/index.ts
@@ -1,4 +1,4 @@
-import {updateHotkeyTip} from "../../protyle/util/compatibility";
+import {setStorageVal, updateHotkeyTip} from "../../protyle/util/compatibility";
import {Layout} from "../index";
import {Wnd} from "../Wnd";
import {Tab} from "../Tab";
@@ -15,7 +15,7 @@ import {Inbox} from "./Inbox";
import {Protyle} from "../../protyle";
import {Backlink} from "./Backlink";
import {resetFloatDockSize} from "./util";
-import {hasClosestByClassName} from "../../protyle/util/hasClosest";
+import {hasClosestByAttribute, hasClosestByClassName} from "../../protyle/util/hasClosest";
import {App} from "../../index";
import {Plugin} from "../../plugin";
import {Custom} from "./Custom";
@@ -571,6 +571,9 @@ export class Dock {
});
}
}
+ if (isSaveLayout) {
+ this.saveLocalPlugin(type, {show: false});
+ }
} else {
this.element.querySelectorAll(`.dock__item--active[data-index="${index}"]`).forEach(item => {
item.classList.remove("dock__item--active", "dock__item--activefocus");
@@ -723,6 +726,9 @@ export class Dock {
if (document.activeElement) {
(document.activeElement as HTMLElement).blur();
}
+ if (isSaveLayout) {
+ this.saveLocalPlugin(type, {show: true});
+ }
}
// dock 中两个面板的显示关系
@@ -826,6 +832,28 @@ export class Dock {
setTimeout(() => {
saveLayout();
}, Constants.TIMEOUT_TRANSITION);
+ let position: TPluginDockPosition;
+ if (hasClosestByAttribute(sourceElement, "id", "dockLeft")) {
+ position = "Left" + (index === 0 ? "Top" : "Bottom") as TPluginDockPosition;
+ } else if (hasClosestByAttribute(sourceElement, "id", "dockRight")) {
+ position = "Right" + (index === 0 ? "Top" : "Bottom") as TPluginDockPosition;
+ } else if (hasClosestByAttribute(sourceElement, "id", "dockBottom")) {
+ position = "Bottom" + (index === 0 ? "Left" : "Right") as TPluginDockPosition;
+ }
+ let sortIndex = 0;
+ let previousElement = sourceElement;
+ while (previousElement.previousElementSibling) {
+ sortIndex++;
+ previousElement = previousElement.previousElementSibling;
+ }
+ this.saveLocalPlugin(type, {
+ index: sortIndex,
+ position,
+ size: {
+ height: null,
+ width: null,
+ }
+ });
}
public remove(key: TDock | string) {
@@ -835,7 +863,7 @@ export class Dock {
if (custom.parent) {
custom.parent.parent.removeTab(custom.parent.id);
}
- if (this.element.querySelectorAll(".dock__item").length === 1 ) {
+ if (this.element.querySelectorAll(".dock__item").length === 1) {
this.element.classList.add("fn__none");
}
delete this.data[key];
@@ -857,6 +885,12 @@ export class Dock {
}
item.setAttribute("data-height", this.layout.element.clientHeight.toString());
}
+ this.saveLocalPlugin(item.getAttribute("data-type"), {
+ size: {
+ width: parseInt(item.getAttribute("data-width")) || null,
+ height: parseInt(item.getAttribute("data-height")) || null
+ }
+ });
});
}
@@ -921,4 +955,21 @@ export class Dock {
}
}
}
+
+ private saveLocalPlugin(dockType: TDock | string, options: {
+ position?: TPluginDockPosition,
+ size?: Config.IUILayoutDockPanelSize,
+ index?: number,
+ show?: boolean
+ }) {
+ this.app.plugins.find(pluginItem => {
+ if (Object.keys(pluginItem.docks).includes(dockType)) {
+ Object.keys(options).forEach((item: "position") => {
+ window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][pluginItem.name][dockType][item] = options[item];
+ });
+ setStorageVal(Constants.LOCAL_PLUGIN_DOCKS, window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS]);
+ return true;
+ }
+ });
+ }
}
diff --git a/app/src/plugin/uninstall.ts b/app/src/plugin/uninstall.ts
index 7075308045..1b92a30cd4 100644
--- a/app/src/plugin/uninstall.ts
+++ b/app/src/plugin/uninstall.ts
@@ -56,47 +56,12 @@ export const uninstall = (app: App, name: string, isReload: boolean) => {
// rm dock
const docksKeys = Object.keys(plugin.docks);
docksKeys.forEach(key => {
- let dockIconElement;
- if (window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name] &&
- window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key]) {
- dockIconElement = document.querySelector(`.dock__item[data-type="${key}"]`);
- if (dockIconElement) {
- let index = 0;
- let previousElement = dockIconElement;
- while (previousElement.previousElementSibling) {
- index++;
- previousElement = previousElement.previousElementSibling;
- }
- window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key].index = index;
- window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key].show = dockIconElement.classList.contains("dock__item--active");
- window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key].size = {
- height: parseInt(dockIconElement.getAttribute("data-height")) || null,
- width: parseInt(dockIconElement.getAttribute("data-width")) || null
- };
- }
- }
-
if (window.siyuan.layout.leftDock && Object.keys(window.siyuan.layout.leftDock.data).includes(key)) {
window.siyuan.layout.leftDock.remove(key);
- if (dockIconElement) {
- window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key].position =
- "Left" + (dockIconElement.getAttribute("data-index") === "0" ? "Top" : "Bottom");
- }
} else if (window.siyuan.layout.rightDock && Object.keys(window.siyuan.layout.rightDock.data).includes(key)) {
window.siyuan.layout.rightDock.remove(key);
- if (dockIconElement) {
- window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key].position =
- "Right" + (dockIconElement.getAttribute("data-index") === "0" ? "Top" : "Bottom");
- }
} else if (window.siyuan.layout.bottomDock && Object.keys(window.siyuan.layout.bottomDock.data).includes(key)) {
window.siyuan.layout.bottomDock.remove(key);
- if (dockIconElement) {
- window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key].position =
- "Bottom" + (dockIconElement.getAttribute("data-index") === "0" ? "Left" : "Right");
- }
- }
- if (dockIconElement) {
- setStorageVal(Constants.LOCAL_PLUGIN_DOCKS, window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS]);
}
});
/// #endif