Vanessa 2023-10-08 12:08:11 +08:00
parent 3127ff1e52
commit c1e0b4ff60
3 changed files with 91 additions and 95 deletions

View File

@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const {
net, app, BrowserWindow, shell, Menu, screen, ipcMain, globalShortcut, Tray,
net, app, BrowserWindow, shell, Menu, screen, ipcMain, globalShortcut, Tray, dialog
} = require("electron");
const path = require("path");
const fs = require("fs");
@ -390,7 +390,7 @@ const boot = () => {
event.preventDefault();
});
workspaces.push({
browserWindow: currentWindow, id: currentWindow.id,
browserWindow: currentWindow,
});
};
@ -667,7 +667,7 @@ app.whenReady().then(() => {
});
ipcMain.on("siyuan-config-tray", (event, data) => {
workspaces.find(item => {
if (item.id === data.id) {
if (item.browserWindow.webContents.id === event.sender.id) {
hideWindow(item.browserWindow);
if ("win32" === process.platform || "linux" === process.platform) {
resetTrayMenu(item.tray, data.languages, item.browserWindow);
@ -677,10 +677,20 @@ app.whenReady().then(() => {
});
});
ipcMain.on("siyuan-export-pdf", (event, data) => {
BrowserWindow.fromId(data.id).webContents.send("siyuan-export-pdf", data);
dialog.showOpenDialog({
title: data.title,
properties: ["createDirectory", "openDirectory"],
}).then((result) => {
if (result.canceled) {
event.sender.destroy();
return;
}
data.filePaths = result.filePaths;
BrowserWindow.fromId(BrowserWindow.getAllWindows().find((win) => win.webContents.id === event.sender.id).id).getParentWindow().send("siyuan-export-pdf", data);
});
ipcMain.on("siyuan-export-close", (event, id) => {
BrowserWindow.fromId(id).webContents.send("siyuan-export-close", id);
});
ipcMain.on("siyuan-export-close", (event) => {
event.sender.destroy();
});
ipcMain.on("siyuan-export-prevent", (event, id) => {
BrowserWindow.fromId(id).webContents.on("will-navigate", (event) => {

View File

@ -188,7 +188,6 @@ export const initWindow = (app: App) => {
// 最小化
if ("windows" === window.siyuan.config.system.os) {
ipcRenderer.send(Constants.SIYUAN_CONFIG_TRAY, {
id: getCurrentWindow().id,
languages: window.siyuan.languages["_trayMenu"],
});
} else {
@ -308,9 +307,6 @@ export const initWindow = (app: App) => {
ipcRenderer.on(Constants.SIYUAN_SEND_WINDOWS, (e, ipcData: IWebSocketData) => {
onWindowsMsg(ipcData);
});
ipcRenderer.on(Constants.SIYUAN_EXPORT_CLOSE, () => {
window.siyuan.printWin.destroy();
});
ipcRenderer.on(Constants.SIYUAN_HOTKEY, (e, data) => {
let matchCommand = false;
app.plugins.find(item => {
@ -326,15 +322,7 @@ export const initWindow = (app: App) => {
}
});
});
ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, (e, ipcData) => {
dialog.showOpenDialog({
title: window.siyuan.languages.export + " PDF",
properties: ["createDirectory", "openDirectory"],
}).then(async (result: OpenDialogReturnValue) => {
if (result.canceled) {
window.siyuan.printWin.destroy();
return;
}
ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, async (e, ipcData) => {
const msgId = showMessage(window.siyuan.languages.exporting, -1);
window.siyuan.storage[Constants.LOCAL_EXPORTPDF] = {
removeAssets: ipcData.removeAssets,
@ -365,9 +353,9 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
pdf: true,
removeAssets: ipcData.removeAssets,
merge: ipcData.mergeSubdocs,
savePath: result.filePaths[0]
savePath: ipcData.filePaths[0]
}, () => {
const pdfFilePath = path.join(result.filePaths[0], replaceLocalPath(ipcData.rootTitle) + ".pdf");
const pdfFilePath = path.join(ipcData.filePaths[0], replaceLocalPath(ipcData.rootTitle) + ".pdf");
fs.writeFileSync(pdfFilePath, pdfData);
window.siyuan.printWin.destroy();
fetchPost("/api/export/processPDF", {
@ -397,7 +385,7 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
});
});
};
removePromise(path.join(result.filePaths[0], "assets"));
removePromise(path.join(ipcData.filePaths[0], "assets"));
}
});
});
@ -411,7 +399,6 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
}
window.siyuan.printWin.hide();
});
});
window.addEventListener("beforeunload", () => {
currentWindow.off("focus", winOnFocus);

View File

@ -461,15 +461,14 @@ const renderPDF = (id: string) => {
actionElement.querySelector("#landscape").addEventListener('change', () => {
setPadding();
});
const currentWindowId = ${getCurrentWindow().id};
actionElement.querySelector('.b3-button--cancel').addEventListener('click', () => {
const {ipcRenderer} = require("electron");
ipcRenderer.send("${Constants.SIYUAN_EXPORT_CLOSE}", currentWindowId)
ipcRenderer.send("${Constants.SIYUAN_EXPORT_CLOSE}")
});
actionElement.querySelector('.b3-button--text').addEventListener('click', () => {
const {ipcRenderer} = require("electron");
ipcRenderer.send("${Constants.SIYUAN_EXPORT_PDF}", {
id: currentWindowId,
title: "${window.siyuan.languages.export} PDF",
pdfOptions:{
printBackground: true,
landscape: actionElement.querySelector("#landscape").checked,