diff --git a/app/src/constants.ts b/app/src/constants.ts index 64ca3ffac..c329be9e3 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -38,6 +38,7 @@ 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]; // ws callback public static readonly CB_MOUNT_HELP = "cb-mount-help"; @@ -58,6 +59,7 @@ export abstract class Constants { public static readonly CB_GET_HISTORY = "cb-get-history"; // 历史渲染 // localstorage + public static readonly LOCAL_ZOOM = "local-zoom"; public static readonly LOCAL_SEARCHEDATA = "local-searchedata"; public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys"; public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts index 56aff5d23..07ef34c57 100644 --- a/app/src/protyle/export/index.ts +++ b/app/src/protyle/export/index.ts @@ -71,7 +71,6 @@ export const saveExport = (option: { type: string, id: string }) => { }; /// #if !BROWSER -let originalZoomFactor = 1; const renderPDF = (id: string) => { const localData = window.siyuan.storage[Constants.LOCAL_EXPORTPDF]; const servePath = window.location.protocol + "//" + window.location.host; @@ -453,7 +452,6 @@ const renderPDF = (id: string) => { }); `; const mainWindow = getCurrentWindow(); - originalZoomFactor = mainWindow.webContents.zoomFactor; window.siyuan.printWin = new BrowserWindow({ parent: mainWindow, modal: true, @@ -472,20 +470,11 @@ const renderPDF = (id: string) => { }, }); window.siyuan.printWin.webContents.userAgent = `SiYuan/${app.getVersion()} https://b3log.org/siyuan Electron`; - window.siyuan.printWin.once("ready-to-show", () => { - // 导出 PDF 预览界面不受主界面缩放影响 https://github.com/siyuan-note/siyuan/issues/6262 - window.siyuan.printWin.webContents.setZoomFactor(1); - }); fetchPost("/api/export/exportTempContent", {content: html}, (response) => { window.siyuan.printWin.loadURL(response.data.url); }); }; -export const destroyPrintWindow = () => { - getCurrentWindow().webContents.setZoomFactor(originalZoomFactor); - window.siyuan.printWin.destroy(); -}; - const getExportPath = (option: { type: string, id: string }, removeAssets?: boolean, mergeSubdocs?: boolean) => { fetchPost("/api/block/getBlockInfo", { id: option.id diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts index 85ab5a4de..2e2233206 100644 --- a/app/src/protyle/util/compatibility.ts +++ b/app/src/protyle/util/compatibility.ts @@ -199,9 +199,11 @@ export const getLocalStorage = (cb:()=>void) => { paragraph: window.siyuan.config.search.paragraph, } }; + defaultStorage[Constants.LOCAL_ZOOM] = 1; [Constants.LOCAL_SEARCHEKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR, Constants.LOCAL_EXPORTWORD, - Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES, Constants.LOCAL_SEARCHEDATA].forEach((key) => { + Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES, Constants.LOCAL_SEARCHEDATA, + Constants.LOCAL_ZOOM,].forEach((key) => { if (typeof response.data[key] === "string") { try { window.siyuan.storage[key] = Object.assign(defaultStorage[key], JSON.parse(response.data[key])); diff --git a/app/src/util/globalShortcut.ts b/app/src/util/globalShortcut.ts index e867d3f98..985ca25d7 100644 --- a/app/src/util/globalShortcut.ts +++ b/app/src/util/globalShortcut.ts @@ -1,4 +1,4 @@ -import {isCtrl, isMac, updateHotkeyTip, writeText} from "../protyle/util/compatibility"; +import {isCtrl, isMac, setStorageVal, updateHotkeyTip, writeText} from "../protyle/util/compatibility"; import {matchHotKey} from "../protyle/util/hotKey"; import {openSearch} from "../search/spread"; import { @@ -42,6 +42,9 @@ import {getNextFileLi, getPreviousFileLi} from "../protyle/wysiwyg/getBlock"; import {editor} from "../config/editor"; import {hintMoveBlock} from "../protyle/hint/extend"; import {Backlink} from "../layout/dock/Backlink"; +/// #if !BROWSER +import {webFrame} from "electron"; +/// #endif import {openHistory} from "../history/history"; import {openCard} from "../card/openCard"; @@ -486,6 +489,39 @@ export const globalShortcut = () => { event.preventDefault(); return; } + /// #if !BROWSER + if (matchHotKey("⌘=", event)) { + Constants.SIZE_ZOOM.find((item, index) => { + if (item === window.siyuan.storage[Constants.LOCAL_ZOOM]) { + window.siyuan.storage[Constants.LOCAL_ZOOM] = Constants.SIZE_ZOOM[index + 1] || 3 + webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]); + setStorageVal(Constants.LOCAL_ZOOM, window.siyuan.storage[Constants.LOCAL_ZOOM]); + return true; + } + }) + event.preventDefault(); + return; + } + if (matchHotKey("⌘0", event)) { + webFrame.setZoomFactor(1); + window.siyuan.storage[Constants.LOCAL_ZOOM] = 1 + setStorageVal(Constants.LOCAL_ZOOM, 1) + event.preventDefault(); + return; + } + if (matchHotKey("⌘-", event)) { + Constants.SIZE_ZOOM.find((item, index) => { + if (item === window.siyuan.storage[Constants.LOCAL_ZOOM]) { + window.siyuan.storage[Constants.LOCAL_ZOOM] = Constants.SIZE_ZOOM[index - 1] || 0.25 + webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]); + setStorageVal(Constants.LOCAL_ZOOM, window.siyuan.storage[Constants.LOCAL_ZOOM]); + return true; + } + }) + event.preventDefault(); + return; + } + /// #endif if (matchHotKey(window.siyuan.config.keymap.general.syncNow.custom, event)) { event.preventDefault(); diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts index 550216847..d181faa7a 100644 --- a/app/src/util/onGetConfig.ts +++ b/app/src/util/onGetConfig.ts @@ -3,11 +3,10 @@ import {exportLayout, JSONToLayout, resetLayout, resizeDrag, resizeTabs} from ". import {hotKey2Electron, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility"; /// #if !BROWSER import {dialog, getCurrentWindow} from "@electron/remote"; -import {ipcRenderer, OpenDialogReturnValue} from "electron"; +import {webFrame, ipcRenderer, OpenDialogReturnValue} from "electron"; import * as fs from "fs"; import * as path from "path"; import {afterExport} from "../protyle/export/util"; -import {destroyPrintWindow} from "../protyle/export"; /// #endif import {Constants} from "../constants"; import {appearance} from "../config/appearance"; @@ -146,6 +145,7 @@ export const onGetConfig = (isStart: boolean) => { id: getCurrentWindow().id, hotkey: hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom) }); + webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]); /// #endif if (!window.siyuan.config.uiLayout || (window.siyuan.config.uiLayout && !window.siyuan.config.uiLayout.left)) { window.siyuan.config.uiLayout = Constants.SIYUAN_EMPTY_LAYOUT; @@ -391,7 +391,7 @@ const initWindow = () => { winOnClose(currentWindow, close); }); ipcRenderer.on(Constants.SIYUAN_EXPORT_CLOSE, () => { - destroyPrintWindow(); + window.siyuan.printWin.destroy(); }); ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, (e, ipcData) => { dialog.showOpenDialog({ @@ -399,7 +399,7 @@ const initWindow = () => { properties: ["createDirectory", "openDirectory"], }).then((result: OpenDialogReturnValue) => { if (result.canceled) { - destroyPrintWindow(); + window.siyuan.printWin.destroy(); return; } const msgId = showMessage(window.siyuan.languages.exporting, -1); @@ -438,7 +438,7 @@ const initWindow = () => { }, () => { const pdfFilePath = path.join(result.filePaths[0], replaceLocalPath(ipcData.rootTitle) + ".pdf"); fs.writeFileSync(pdfFilePath, pdfData); - destroyPrintWindow(); + window.siyuan.printWin.destroy(); fetchPost("/api/export/addPDFOutline", { id: ipcData.rootId, merge: ipcData.mergeSubdocs, @@ -471,11 +471,11 @@ const initWindow = () => { }); }).catch((error: string) => { showMessage("Export PDF error:" + error, 0, "error", msgId); - destroyPrintWindow(); + window.siyuan.printWin.destroy(); }); } catch (e) { showMessage("Export PDF failed: " + e, 0, "error", msgId); - destroyPrintWindow(); + window.siyuan.printWin.destroy(); } window.siyuan.printWin.hide(); });