mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
This commit is contained in:
parent
278fa18aee
commit
af2d3ade5e
5 changed files with 49 additions and 20 deletions
|
|
@ -38,6 +38,7 @@ export abstract class Constants {
|
||||||
public static readonly SIZE_UNDO = 64;
|
public static readonly SIZE_UNDO = 64;
|
||||||
public static readonly SIZE_TITLE = 512;
|
public static readonly SIZE_TITLE = 512;
|
||||||
public static readonly SIZE_EDITOR_WIDTH = 760;
|
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
|
// ws callback
|
||||||
public static readonly CB_MOUNT_HELP = "cb-mount-help";
|
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"; // 历史渲染
|
public static readonly CB_GET_HISTORY = "cb-get-history"; // 历史渲染
|
||||||
|
|
||||||
// localstorage
|
// localstorage
|
||||||
|
public static readonly LOCAL_ZOOM = "local-zoom";
|
||||||
public static readonly LOCAL_SEARCHEDATA = "local-searchedata";
|
public static readonly LOCAL_SEARCHEDATA = "local-searchedata";
|
||||||
public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys";
|
public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys";
|
||||||
public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile
|
public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,6 @@ export const saveExport = (option: { type: string, id: string }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
let originalZoomFactor = 1;
|
|
||||||
const renderPDF = (id: string) => {
|
const renderPDF = (id: string) => {
|
||||||
const localData = window.siyuan.storage[Constants.LOCAL_EXPORTPDF];
|
const localData = window.siyuan.storage[Constants.LOCAL_EXPORTPDF];
|
||||||
const servePath = window.location.protocol + "//" + window.location.host;
|
const servePath = window.location.protocol + "//" + window.location.host;
|
||||||
|
|
@ -453,7 +452,6 @@ const renderPDF = (id: string) => {
|
||||||
});
|
});
|
||||||
</script></body></html>`;
|
</script></body></html>`;
|
||||||
const mainWindow = getCurrentWindow();
|
const mainWindow = getCurrentWindow();
|
||||||
originalZoomFactor = mainWindow.webContents.zoomFactor;
|
|
||||||
window.siyuan.printWin = new BrowserWindow({
|
window.siyuan.printWin = new BrowserWindow({
|
||||||
parent: mainWindow,
|
parent: mainWindow,
|
||||||
modal: true,
|
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.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) => {
|
fetchPost("/api/export/exportTempContent", {content: html}, (response) => {
|
||||||
window.siyuan.printWin.loadURL(response.data.url);
|
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) => {
|
const getExportPath = (option: { type: string, id: string }, removeAssets?: boolean, mergeSubdocs?: boolean) => {
|
||||||
fetchPost("/api/block/getBlockInfo", {
|
fetchPost("/api/block/getBlockInfo", {
|
||||||
id: option.id
|
id: option.id
|
||||||
|
|
|
||||||
|
|
@ -199,9 +199,11 @@ export const getLocalStorage = (cb:()=>void) => {
|
||||||
paragraph: window.siyuan.config.search.paragraph,
|
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_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") {
|
if (typeof response.data[key] === "string") {
|
||||||
try {
|
try {
|
||||||
window.siyuan.storage[key] = Object.assign(defaultStorage[key], JSON.parse(response.data[key]));
|
window.siyuan.storage[key] = Object.assign(defaultStorage[key], JSON.parse(response.data[key]));
|
||||||
|
|
|
||||||
|
|
@ -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 {matchHotKey} from "../protyle/util/hotKey";
|
||||||
import {openSearch} from "../search/spread";
|
import {openSearch} from "../search/spread";
|
||||||
import {
|
import {
|
||||||
|
|
@ -42,6 +42,9 @@ import {getNextFileLi, getPreviousFileLi} from "../protyle/wysiwyg/getBlock";
|
||||||
import {editor} from "../config/editor";
|
import {editor} from "../config/editor";
|
||||||
import {hintMoveBlock} from "../protyle/hint/extend";
|
import {hintMoveBlock} from "../protyle/hint/extend";
|
||||||
import {Backlink} from "../layout/dock/Backlink";
|
import {Backlink} from "../layout/dock/Backlink";
|
||||||
|
/// #if !BROWSER
|
||||||
|
import {webFrame} from "electron";
|
||||||
|
/// #endif
|
||||||
import {openHistory} from "../history/history";
|
import {openHistory} from "../history/history";
|
||||||
import {openCard} from "../card/openCard";
|
import {openCard} from "../card/openCard";
|
||||||
|
|
||||||
|
|
@ -486,6 +489,39 @@ export const globalShortcut = () => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
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)) {
|
if (matchHotKey(window.siyuan.config.keymap.general.syncNow.custom, event)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,10 @@ import {exportLayout, JSONToLayout, resetLayout, resizeDrag, resizeTabs} from ".
|
||||||
import {hotKey2Electron, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
import {hotKey2Electron, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {dialog, getCurrentWindow} from "@electron/remote";
|
import {dialog, getCurrentWindow} from "@electron/remote";
|
||||||
import {ipcRenderer, OpenDialogReturnValue} from "electron";
|
import {webFrame, ipcRenderer, OpenDialogReturnValue} from "electron";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import {afterExport} from "../protyle/export/util";
|
import {afterExport} from "../protyle/export/util";
|
||||||
import {destroyPrintWindow} from "../protyle/export";
|
|
||||||
/// #endif
|
/// #endif
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {appearance} from "../config/appearance";
|
import {appearance} from "../config/appearance";
|
||||||
|
|
@ -146,6 +145,7 @@ export const onGetConfig = (isStart: boolean) => {
|
||||||
id: getCurrentWindow().id,
|
id: getCurrentWindow().id,
|
||||||
hotkey: hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom)
|
hotkey: hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom)
|
||||||
});
|
});
|
||||||
|
webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]);
|
||||||
/// #endif
|
/// #endif
|
||||||
if (!window.siyuan.config.uiLayout || (window.siyuan.config.uiLayout && !window.siyuan.config.uiLayout.left)) {
|
if (!window.siyuan.config.uiLayout || (window.siyuan.config.uiLayout && !window.siyuan.config.uiLayout.left)) {
|
||||||
window.siyuan.config.uiLayout = Constants.SIYUAN_EMPTY_LAYOUT;
|
window.siyuan.config.uiLayout = Constants.SIYUAN_EMPTY_LAYOUT;
|
||||||
|
|
@ -391,7 +391,7 @@ const initWindow = () => {
|
||||||
winOnClose(currentWindow, close);
|
winOnClose(currentWindow, close);
|
||||||
});
|
});
|
||||||
ipcRenderer.on(Constants.SIYUAN_EXPORT_CLOSE, () => {
|
ipcRenderer.on(Constants.SIYUAN_EXPORT_CLOSE, () => {
|
||||||
destroyPrintWindow();
|
window.siyuan.printWin.destroy();
|
||||||
});
|
});
|
||||||
ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, (e, ipcData) => {
|
ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, (e, ipcData) => {
|
||||||
dialog.showOpenDialog({
|
dialog.showOpenDialog({
|
||||||
|
|
@ -399,7 +399,7 @@ const initWindow = () => {
|
||||||
properties: ["createDirectory", "openDirectory"],
|
properties: ["createDirectory", "openDirectory"],
|
||||||
}).then((result: OpenDialogReturnValue) => {
|
}).then((result: OpenDialogReturnValue) => {
|
||||||
if (result.canceled) {
|
if (result.canceled) {
|
||||||
destroyPrintWindow();
|
window.siyuan.printWin.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const msgId = showMessage(window.siyuan.languages.exporting, -1);
|
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");
|
const pdfFilePath = path.join(result.filePaths[0], replaceLocalPath(ipcData.rootTitle) + ".pdf");
|
||||||
fs.writeFileSync(pdfFilePath, pdfData);
|
fs.writeFileSync(pdfFilePath, pdfData);
|
||||||
destroyPrintWindow();
|
window.siyuan.printWin.destroy();
|
||||||
fetchPost("/api/export/addPDFOutline", {
|
fetchPost("/api/export/addPDFOutline", {
|
||||||
id: ipcData.rootId,
|
id: ipcData.rootId,
|
||||||
merge: ipcData.mergeSubdocs,
|
merge: ipcData.mergeSubdocs,
|
||||||
|
|
@ -471,11 +471,11 @@ const initWindow = () => {
|
||||||
});
|
});
|
||||||
}).catch((error: string) => {
|
}).catch((error: string) => {
|
||||||
showMessage("Export PDF error:" + error, 0, "error", msgId);
|
showMessage("Export PDF error:" + error, 0, "error", msgId);
|
||||||
destroyPrintWindow();
|
window.siyuan.printWin.destroy();
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showMessage("Export PDF failed: " + e, 0, "error", msgId);
|
showMessage("Export PDF failed: " + e, 0, "error", msgId);
|
||||||
destroyPrintWindow();
|
window.siyuan.printWin.destroy();
|
||||||
}
|
}
|
||||||
window.siyuan.printWin.hide();
|
window.siyuan.printWin.hide();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue