This commit is contained in:
parent
fd98963038
commit
575a151b89
5 changed files with 80 additions and 19 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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[];
|
||||
|
|
Loading…
Add table
Reference in a new issue