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/13526

Vanessa575a151b8935
diff --git a/app/electron/main.js b/app/electron/main.js
index 999e78aa1d..6c6430ba2f 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -861,6 +861,15 @@ app.whenReady().then(() => {
globalShortcut.unregister(hotKey2Electron(data.accelerator));
}
break;
+ case "setTrafficLightPosition":
+ if (!currentWindow) {
+ return;
+ }
+ if (new URL(currentWindow.getURL()).pathname === "/stage/build/app/window.html") {
+ data.position.y += 5 * data.zoom;
+ }
+ currentWindow.setWindowButtonPosition(data.position);
+ break;
case "show":
if (!currentWindow) {
return;
diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts
index 2e989b3e85..1f3002e6a5 100644
--- a/app/src/boot/onGetConfig.ts
+++ b/app/src/boot/onGetConfig.ts
@@ -40,6 +40,11 @@ export const onGetConfig = (isStart: boolean, app: App) => {
port: location.port
});
webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]);
+ ipcRenderer.send(Constants.SIYUAN_CMD, {
+ cmd: "setTrafficLightPosition",
+ zoom: window.siyuan.storage[Constants.LOCAL_ZOOM],
+ position: Constants.SIZE_ZOOM.find((item) => item.zoom === window.siyuan.storage[Constants.LOCAL_ZOOM]).position
+ });
/// #endif
if (!window.siyuan.config.uiLayout || (window.siyuan.config.uiLayout && !window.siyuan.config.uiLayout.left)) {
window.siyuan.config.uiLayout = Constants.SIYUAN_EMPTY_LAYOUT;
diff --git a/app/src/constants.ts b/app/src/constants.ts
index 8d192e2ad5..2005fc1632 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -74,7 +74,45 @@ export abstract class Constants {
public static readonly SIZE_UNDO = 64;
public static readonly SIZE_TITLE = 512;
public static readonly SIZE_EDITOR_WIDTH = 760;
- public static readonly SIZE_ZOOM = [0.25, 0.33, 0.5, 0.67, 0.75, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3];
+ public static readonly SIZE_ZOOM = [
+ {
+ zoom: 0.67,
+ position: {x: 0, y: 2}
+ },
+ {
+ zoom: 0.75,
+ position: {x: 1, y: 4}
+ }, {
+ zoom: 0.8,
+ position: {x: 2, y: 4}
+ }, {
+ zoom: 0.9,
+ position: {x: 5, y: 6}
+ }, {
+ zoom: 1,
+ position: {x: 8, y: 8}
+ }, {
+ zoom: 1.1,
+ position: {x: 12, y: 9}
+ }, {
+ zoom: 1.25,
+ position: {x: 18, y: 12}
+ }, {
+ zoom: 1.5,
+ position: {x: 27, y: 16}
+ }, {
+ zoom: 1.75,
+ position: {x: 36, y: 20}
+ }, {
+ zoom: 2,
+ position: {x: 45, y: 23}
+ }, {
+ zoom: 2.5,
+ position: {x: 63, y: 31}
+ }, {
+ zoom: 3,
+ position: {x: 80, y: 39}
+ }];
// ws callback
public static readonly CB_MOVE_NOLIST = "cb-move-nolist";
diff --git a/app/src/layout/topBar.ts b/app/src/layout/topBar.ts
index b54f477ffc..83e76ad4ad 100644
--- a/app/src/layout/topBar.ts
+++ b/app/src/layout/topBar.ts
@@ -10,7 +10,7 @@ import {openSetting} from "../config";
import {openSearch} from "../search/spread";
import {App} from "../index";
/// #if !BROWSER
-import {webFrame} from "electron";
+import {ipcRenderer, webFrame} from "electron";
/// #endif
import {Constants} from "../constants";
import {isBrowser, isWindow} from "../util/functions";
@@ -262,39 +262,43 @@ export const initBar = (app: App) => {
export const setZoom = (type: "zoomIn" | "zoomOut" | "restore") => {
/// #if !BROWSER
- const isTabWindow = isWindow();
let zoom = 1;
if (type === "zoomIn") {
Constants.SIZE_ZOOM.find((item, index) => {
- if (item === window.siyuan.storage[Constants.LOCAL_ZOOM]) {
- zoom = Constants.SIZE_ZOOM[index + 1] || 3;
+ if (item.zoom === window.siyuan.storage[Constants.LOCAL_ZOOM]) {
+ zoom = Constants.SIZE_ZOOM[index + 1]?.zoom || 3;
return true;
}
});
} else if (type === "zoomOut") {
Constants.SIZE_ZOOM.find((item, index) => {
- if (item === window.siyuan.storage[Constants.LOCAL_ZOOM]) {
- zoom = Constants.SIZE_ZOOM[index - 1] || 0.25;
+ if (item.zoom === window.siyuan.storage[Constants.LOCAL_ZOOM]) {
+ zoom = Constants.SIZE_ZOOM[index - 1]?.zoom || 0.67;
return true;
}
});
}
webFrame.setZoomFactor(zoom);
+ ipcRenderer.send(Constants.SIYUAN_CMD, {
+ cmd: "setTrafficLightPosition",
+ zoom,
+ position: Constants.SIZE_ZOOM.find((item) => item.zoom === zoom).position
+ });
window.siyuan.storage[Constants.LOCAL_ZOOM] = zoom;
- if (!isTabWindow) {
- setStorageVal(Constants.LOCAL_ZOOM, zoom);
- }
- const barZoomElement = document.getElementById("barZoom");
- if (zoom === 1) {
- barZoomElement.classList.add("fn__none");
- } else {
- if (zoom > 1) {
- barZoomElement.querySelector("use").setAttribute("xlink:href", "#iconZoomIn");
+ setStorageVal(Constants.LOCAL_ZOOM, zoom);
+ if (!isWindow()) {
+ const barZoomElement = document.getElementById("barZoom");
+ if (zoom === 1) {
+ barZoomElement.classList.add("fn__none");
} else {
- barZoomElement.querySelector("use").setAttribute("xlink:href", "#iconZoomOut");
+ if (zoom > 1) {
+ barZoomElement.querySelector("use").setAttribute("xlink:href", "#iconZoomIn");
+ } else {
+ barZoomElement.querySelector("use").setAttribute("xlink:href", "#iconZoomOut");
+ }
+ barZoomElement.classList.remove("fn__none");
}
- barZoomElement.classList.remove("fn__none");
}
/// #endif
};
diff --git a/app/src/window/init.ts b/app/src/window/init.ts
index 13aec0db85..6fc84be6e5 100644
--- a/app/src/window/init.ts
+++ b/app/src/window/init.ts
@@ -1,5 +1,5 @@
import {Constants} from "../constants";
-import {webFrame} from "electron";
+import {ipcRenderer, webFrame} from "electron";
import {fetchPost} from "../util/fetch";
import {adjustLayout, getInstanceById, JSONToCenter} from "../layout/util";
import {resizeTabs} from "../layout/tabUtil";
@@ -16,6 +16,11 @@ import {initWindowEvent} from "../boot/globalEvent/event";
export const init = (app: App) => {
webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]);
+ ipcRenderer.send(Constants.SIYUAN_CMD, {
+ cmd: "setTrafficLightPosition",
+ zoom: window.siyuan.storage[Constants.LOCAL_ZOOM],
+ position: Constants.SIZE_ZOOM.find((item) => item.zoom === window.siyuan.storage[Constants.LOCAL_ZOOM]).position
+ });
initWindowEvent(app);
fetchPost("/api/system/getEmojiConf", {}, response => {
window.siyuan.emojis = response.data as IEmoji[];