mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-17 01:21:14 +08:00
This commit is contained in:
parent
3127ff1e52
commit
c1e0b4ff60
@ -15,7 +15,7 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const {
|
const {
|
||||||
net, app, BrowserWindow, shell, Menu, screen, ipcMain, globalShortcut, Tray,
|
net, app, BrowserWindow, shell, Menu, screen, ipcMain, globalShortcut, Tray, dialog
|
||||||
} = require("electron");
|
} = require("electron");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
@ -390,7 +390,7 @@ const boot = () => {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
workspaces.push({
|
workspaces.push({
|
||||||
browserWindow: currentWindow, id: currentWindow.id,
|
browserWindow: currentWindow,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -667,7 +667,7 @@ app.whenReady().then(() => {
|
|||||||
});
|
});
|
||||||
ipcMain.on("siyuan-config-tray", (event, data) => {
|
ipcMain.on("siyuan-config-tray", (event, data) => {
|
||||||
workspaces.find(item => {
|
workspaces.find(item => {
|
||||||
if (item.id === data.id) {
|
if (item.browserWindow.webContents.id === event.sender.id) {
|
||||||
hideWindow(item.browserWindow);
|
hideWindow(item.browserWindow);
|
||||||
if ("win32" === process.platform || "linux" === process.platform) {
|
if ("win32" === process.platform || "linux" === process.platform) {
|
||||||
resetTrayMenu(item.tray, data.languages, item.browserWindow);
|
resetTrayMenu(item.tray, data.languages, item.browserWindow);
|
||||||
@ -677,10 +677,20 @@ app.whenReady().then(() => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
ipcMain.on("siyuan-export-pdf", (event, data) => {
|
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) => {
|
ipcMain.on("siyuan-export-prevent", (event, id) => {
|
||||||
BrowserWindow.fromId(id).webContents.on("will-navigate", (event) => {
|
BrowserWindow.fromId(id).webContents.on("will-navigate", (event) => {
|
||||||
|
@ -188,7 +188,6 @@ export const initWindow = (app: App) => {
|
|||||||
// 最小化
|
// 最小化
|
||||||
if ("windows" === window.siyuan.config.system.os) {
|
if ("windows" === window.siyuan.config.system.os) {
|
||||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_TRAY, {
|
ipcRenderer.send(Constants.SIYUAN_CONFIG_TRAY, {
|
||||||
id: getCurrentWindow().id,
|
|
||||||
languages: window.siyuan.languages["_trayMenu"],
|
languages: window.siyuan.languages["_trayMenu"],
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -308,9 +307,6 @@ export const initWindow = (app: App) => {
|
|||||||
ipcRenderer.on(Constants.SIYUAN_SEND_WINDOWS, (e, ipcData: IWebSocketData) => {
|
ipcRenderer.on(Constants.SIYUAN_SEND_WINDOWS, (e, ipcData: IWebSocketData) => {
|
||||||
onWindowsMsg(ipcData);
|
onWindowsMsg(ipcData);
|
||||||
});
|
});
|
||||||
ipcRenderer.on(Constants.SIYUAN_EXPORT_CLOSE, () => {
|
|
||||||
window.siyuan.printWin.destroy();
|
|
||||||
});
|
|
||||||
ipcRenderer.on(Constants.SIYUAN_HOTKEY, (e, data) => {
|
ipcRenderer.on(Constants.SIYUAN_HOTKEY, (e, data) => {
|
||||||
let matchCommand = false;
|
let matchCommand = false;
|
||||||
app.plugins.find(item => {
|
app.plugins.find(item => {
|
||||||
@ -326,15 +322,7 @@ export const initWindow = (app: App) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, (e, ipcData) => {
|
ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, async (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;
|
|
||||||
}
|
|
||||||
const msgId = showMessage(window.siyuan.languages.exporting, -1);
|
const msgId = showMessage(window.siyuan.languages.exporting, -1);
|
||||||
window.siyuan.storage[Constants.LOCAL_EXPORTPDF] = {
|
window.siyuan.storage[Constants.LOCAL_EXPORTPDF] = {
|
||||||
removeAssets: ipcData.removeAssets,
|
removeAssets: ipcData.removeAssets,
|
||||||
@ -365,9 +353,9 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
|
|||||||
pdf: true,
|
pdf: true,
|
||||||
removeAssets: ipcData.removeAssets,
|
removeAssets: ipcData.removeAssets,
|
||||||
merge: ipcData.mergeSubdocs,
|
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);
|
fs.writeFileSync(pdfFilePath, pdfData);
|
||||||
window.siyuan.printWin.destroy();
|
window.siyuan.printWin.destroy();
|
||||||
fetchPost("/api/export/processPDF", {
|
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.siyuan.printWin.hide();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
window.addEventListener("beforeunload", () => {
|
window.addEventListener("beforeunload", () => {
|
||||||
currentWindow.off("focus", winOnFocus);
|
currentWindow.off("focus", winOnFocus);
|
||||||
|
@ -461,15 +461,14 @@ const renderPDF = (id: string) => {
|
|||||||
actionElement.querySelector("#landscape").addEventListener('change', () => {
|
actionElement.querySelector("#landscape").addEventListener('change', () => {
|
||||||
setPadding();
|
setPadding();
|
||||||
});
|
});
|
||||||
const currentWindowId = ${getCurrentWindow().id};
|
|
||||||
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}", currentWindowId)
|
ipcRenderer.send("${Constants.SIYUAN_EXPORT_CLOSE}")
|
||||||
});
|
});
|
||||||
actionElement.querySelector('.b3-button--text').addEventListener('click', () => {
|
actionElement.querySelector('.b3-button--text').addEventListener('click', () => {
|
||||||
const {ipcRenderer} = require("electron");
|
const {ipcRenderer} = require("electron");
|
||||||
ipcRenderer.send("${Constants.SIYUAN_EXPORT_PDF}", {
|
ipcRenderer.send("${Constants.SIYUAN_EXPORT_PDF}", {
|
||||||
id: currentWindowId,
|
title: "${window.siyuan.languages.export} PDF",
|
||||||
pdfOptions:{
|
pdfOptions:{
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
landscape: actionElement.querySelector("#landscape").checked,
|
landscape: actionElement.querySelector("#landscape").checked,
|
||||||
|
Loading…
Reference in New Issue
Block a user