mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
This commit is contained in:
parent
2ca7253d1f
commit
7a70b53289
5 changed files with 84 additions and 78 deletions
|
|
@ -680,17 +680,26 @@ app.whenReady().then(() => {
|
||||||
if (data.cmd === "askMicrophone") {
|
if (data.cmd === "askMicrophone") {
|
||||||
return systemPreferences.askForMediaAccess("microphone");
|
return systemPreferences.askForMediaAccess("microphone");
|
||||||
}
|
}
|
||||||
|
if (data.cmd === "printToPDF") {
|
||||||
|
return getWindowByContentId(data.webContentsId).webContents.printToPDF(data.pdfOptions);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
ipcMain.on("siyuan-cmd", (event, cmd) => {
|
ipcMain.on("siyuan-cmd", (event, data) => {
|
||||||
|
let cmd = data;
|
||||||
|
let webContentsId = event.sender.id
|
||||||
|
if (typeof data !== "string") {
|
||||||
|
cmd = data.cmd;
|
||||||
|
webContentsId = data.webContentsId
|
||||||
|
}
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case "openDevTools":
|
case "openDevTools":
|
||||||
event.sender.openDevTools({mode: "bottom"});
|
event.sender.openDevTools({mode: "bottom"});
|
||||||
break;
|
break;
|
||||||
case "show":
|
case "show":
|
||||||
showWindow(getWindowByContentId(event.sender.id));
|
showWindow(getWindowByContentId(webContentsId));
|
||||||
break;
|
break;
|
||||||
case "hide":
|
case "hide":
|
||||||
getWindowByContentId(event.sender.id).hide();
|
getWindowByContentId(webContentsId).hide();
|
||||||
break;
|
break;
|
||||||
case "redo":
|
case "redo":
|
||||||
event.sender.redo();
|
event.sender.redo();
|
||||||
|
|
@ -698,6 +707,9 @@ app.whenReady().then(() => {
|
||||||
case "undo":
|
case "undo":
|
||||||
event.sender.undo();
|
event.sender.undo();
|
||||||
break;
|
break;
|
||||||
|
case "destroy":
|
||||||
|
getWindowByContentId(webContentsId).destroy();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ipcMain.on("siyuan-config-tray", (event, data) => {
|
ipcMain.on("siyuan-config-tray", (event, data) => {
|
||||||
|
|
@ -721,20 +733,37 @@ app.whenReady().then(() => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
data.filePaths = result.filePaths;
|
data.filePaths = result.filePaths;
|
||||||
|
data.webContentsId = event.sender.id;
|
||||||
getWindowByContentId(event.sender.id).getParentWindow().send("siyuan-export-pdf", data);
|
getWindowByContentId(event.sender.id).getParentWindow().send("siyuan-export-pdf", data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ipcMain.on("siyuan-export-close", (event) => {
|
ipcMain.on("siyuan-export-newwindow", (event, data) => {
|
||||||
event.sender.destroy();
|
const printWin = new BrowserWindow({
|
||||||
|
parent: getWindowByContentId(event.sender.id),
|
||||||
|
modal: true,
|
||||||
|
show: true,
|
||||||
|
width: 1032,
|
||||||
|
height: 650,
|
||||||
|
resizable: false,
|
||||||
|
frame: "darwin" === process.platform,
|
||||||
|
icon: path.join(appDir, "stage", "icon-large.png"),
|
||||||
|
titleBarStyle: "hidden",
|
||||||
|
webPreferences: {
|
||||||
|
contextIsolation: false,
|
||||||
|
nodeIntegration: true,
|
||||||
|
webviewTag: true,
|
||||||
|
webSecurity: false,
|
||||||
|
autoplayPolicy: "user-gesture-required" // 桌面端禁止自动播放多媒体 https://github.com/siyuan-note/siyuan/issues/7587
|
||||||
|
},
|
||||||
});
|
});
|
||||||
ipcMain.on("siyuan-export-prevent", (event, id) => {
|
printWin.webContents.userAgent = "SiYuan/" + appVer + " https://b3log.org/siyuan Electron " + printWin.webContents.userAgent;
|
||||||
BrowserWindow.fromId(id).webContents.on("will-navigate", (event) => {
|
printWin.loadURL(data);
|
||||||
const url = event.url;
|
printWin.webContents.on("will-navigate", (nEvent) => {
|
||||||
event.preventDefault();
|
nEvent.preventDefault();
|
||||||
if (url.startsWith(localServer)) {
|
if (nEvent.url.startsWith(localServer)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
shell.openExternal(url);
|
shell.openExternal(nEvent.url);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ipcMain.on("siyuan-quit", (event, port) => {
|
ipcMain.on("siyuan-quit", (event, port) => {
|
||||||
|
|
|
||||||
|
|
@ -347,7 +347,11 @@ export const initWindow = (app: App) => {
|
||||||
${response.data.replace("%pages", "<span class=totalPages></span>").replace("%page", "<span class=pageNumber></span>")}
|
${response.data.replace("%pages", "<span class=totalPages></span>").replace("%page", "<span class=pageNumber></span>")}
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
window.siyuan.printWin.webContents.printToPDF(ipcData.pdfOptions).then((pdfData) => {
|
const pdfData = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
|
||||||
|
cmd: "printToPDF",
|
||||||
|
pdfOptions: ipcData.pdfOptions,
|
||||||
|
webContentsId: ipcData.webContentsId
|
||||||
|
});
|
||||||
fetchPost("/api/export/exportHTML", {
|
fetchPost("/api/export/exportHTML", {
|
||||||
id: ipcData.rootId,
|
id: ipcData.rootId,
|
||||||
pdf: true,
|
pdf: true,
|
||||||
|
|
@ -357,7 +361,7 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
|
||||||
}, () => {
|
}, () => {
|
||||||
const pdfFilePath = path.join(ipcData.filePaths[0], replaceLocalPath(ipcData.rootTitle) + ".pdf");
|
const pdfFilePath = path.join(ipcData.filePaths[0], replaceLocalPath(ipcData.rootTitle) + ".pdf");
|
||||||
fs.writeFileSync(pdfFilePath, pdfData);
|
fs.writeFileSync(pdfFilePath, pdfData);
|
||||||
window.siyuan.printWin.destroy();
|
ipcRenderer.send(Constants.SIYUAN_CMD, {cmd: "destroy", webContentsId: ipcData.webContentsId});
|
||||||
fetchPost("/api/export/processPDF", {
|
fetchPost("/api/export/processPDF", {
|
||||||
id: ipcData.rootId,
|
id: ipcData.rootId,
|
||||||
merge: ipcData.mergeSubdocs,
|
merge: ipcData.mergeSubdocs,
|
||||||
|
|
@ -389,15 +393,11 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).catch((error: string) => {
|
|
||||||
showMessage("Export PDF error:" + error, 0, "error", msgId);
|
|
||||||
window.siyuan.printWin.destroy();
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showMessage("Export PDF failed: " + e, 0, "error", msgId);
|
showMessage("Export PDF failed: " + e, 0, "error", msgId);
|
||||||
window.siyuan.printWin.destroy();
|
ipcRenderer.send(Constants.SIYUAN_CMD, {cmd: "destroy", webContentsId: ipcData.webContentsId});
|
||||||
}
|
}
|
||||||
window.siyuan.printWin.hide();
|
ipcRenderer.send(Constants.SIYUAN_CMD, {cmd: "hide", webContentsId: ipcData.webContentsId});
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener("beforeunload", () => {
|
window.addEventListener("beforeunload", () => {
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,7 @@ export abstract class Constants {
|
||||||
public static readonly SIYUAN_OPEN_FOLDER: string = "siyuan-open-folder";
|
public static readonly SIYUAN_OPEN_FOLDER: string = "siyuan-open-folder";
|
||||||
|
|
||||||
public static readonly SIYUAN_EXPORT_PDF: string = "siyuan-export-pdf";
|
public static readonly SIYUAN_EXPORT_PDF: string = "siyuan-export-pdf";
|
||||||
public static readonly SIYUAN_EXPORT_CLOSE: string = "siyuan-export-close";
|
public static readonly SIYUAN_EXPORT_NEWWINDOW: string = "siyuan-export-newwindow";
|
||||||
public static readonly SIYUAN_EXPORT_PREVENT: string = "siyuan-export-prevent";
|
|
||||||
|
|
||||||
// custom
|
// custom
|
||||||
public static readonly CUSTOM_SY_READONLY: string = "custom-sy-readonly";
|
public static readonly CUSTOM_SY_READONLY: string = "custom-sy-readonly";
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import {hideMessage, showMessage} from "../../dialog/message";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {ipcRenderer} from "electron";
|
import {ipcRenderer} from "electron";
|
||||||
import {app, BrowserWindow, getCurrentWindow} from "@electron/remote";
|
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import {afterExport} from "./util";
|
import {afterExport} from "./util";
|
||||||
|
|
@ -463,7 +462,7 @@ const renderPDF = (id: string) => {
|
||||||
});
|
});
|
||||||
actionElement.querySelector('.b3-button--cancel').addEventListener('click', () => {
|
actionElement.querySelector('.b3-button--cancel').addEventListener('click', () => {
|
||||||
const {ipcRenderer} = require("electron");
|
const {ipcRenderer} = require("electron");
|
||||||
ipcRenderer.send("${Constants.SIYUAN_EXPORT_CLOSE}")
|
ipcRenderer.send("${Constants.SIYUAN_CMD}", "destroy")
|
||||||
});
|
});
|
||||||
actionElement.querySelector('.b3-button--text').addEventListener('click', () => {
|
actionElement.querySelector('.b3-button--text').addEventListener('click', () => {
|
||||||
const {ipcRenderer} = require("electron");
|
const {ipcRenderer} = require("electron");
|
||||||
|
|
@ -499,28 +498,8 @@ const renderPDF = (id: string) => {
|
||||||
renderPreview(response.data.content);
|
renderPreview(response.data.content);
|
||||||
});
|
});
|
||||||
</script></body></html>`;
|
</script></body></html>`;
|
||||||
window.siyuan.printWin = new BrowserWindow({
|
|
||||||
parent: getCurrentWindow(),
|
|
||||||
modal: true,
|
|
||||||
show: true,
|
|
||||||
width: 1032,
|
|
||||||
height: 650,
|
|
||||||
resizable: false,
|
|
||||||
frame: "darwin" === window.siyuan.config.system.os,
|
|
||||||
icon: path.join(window.siyuan.config.system.appDir, "stage", "icon-large.png"),
|
|
||||||
titleBarStyle: "hidden",
|
|
||||||
webPreferences: {
|
|
||||||
contextIsolation: false,
|
|
||||||
nodeIntegration: true,
|
|
||||||
webviewTag: true,
|
|
||||||
webSecurity: false,
|
|
||||||
autoplayPolicy: "user-gesture-required" // 桌面端禁止自动播放多媒体 https://github.com/siyuan-note/siyuan/issues/7587
|
|
||||||
},
|
|
||||||
});
|
|
||||||
ipcRenderer.send(Constants.SIYUAN_EXPORT_PREVENT, window.siyuan.printWin.id);
|
|
||||||
window.siyuan.printWin.webContents.userAgent = `SiYuan/${app.getVersion()} https://b3log.org/siyuan Electron`;
|
|
||||||
fetchPost("/api/export/exportTempContent", {content: html}, (response) => {
|
fetchPost("/api/export/exportTempContent", {content: html}, (response) => {
|
||||||
window.siyuan.printWin.loadURL(response.data.url);
|
ipcRenderer.send(Constants.SIYUAN_EXPORT_NEWWINDOW, response.data.url);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
1
app/src/types/index.d.ts
vendored
1
app/src/types/index.d.ts
vendored
|
|
@ -327,7 +327,6 @@ interface ISiyuan {
|
||||||
storage?: {
|
storage?: {
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
},
|
},
|
||||||
printWin?: import("electron").BrowserWindow
|
|
||||||
transactions?: {
|
transactions?: {
|
||||||
protyle: IProtyle,
|
protyle: IProtyle,
|
||||||
doOperations: IOperation[],
|
doOperations: IOperation[],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue