diff options
Diffstat (limited to 'electron/src/main.js')
| -rw-r--r-- | electron/src/main.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/electron/src/main.js b/electron/src/main.js index 210e26ed..db52ac94 100644 --- a/electron/src/main.js +++ b/electron/src/main.js @@ -1,4 +1,4 @@ -import { app, BrowserWindow, ipcMain, dialog } from 'electron'; +import { app, BrowserWindow, ipcMain, dialog, shell } from 'electron'; var fs = require('fs'); var path = require('path') var tmp = require('tmp') @@ -43,11 +43,20 @@ app.on('window-all-closed', () => { app.quit(); }); -ipcMain.on('print', function (event, pageSize) { +ipcMain.on('save-pdf', function (event, pageSize) { mainWindow.webContents.printToPDF({"pageSize": pageSize}, function(error, data) { dialog.showSaveDialog(mainWindow, {"defaultPath": "inkstitch.pdf"}, function(filename, bookmark) { if (typeof filename !== 'undefined') fs.writeFileSync(filename, data, 'utf-8'); }) }) -})
\ No newline at end of file +}) + +ipcMain.on('open-pdf', function (event, pageSize) { + mainWindow.webContents.printToPDF({"pageSize": pageSize}, function(error, data) { + tmp.file({keep: true, discardDescriptor: true}, function(err, path, fd, cleanupCallback) { + fs.writeFileSync(path, data, 'utf-8'); + shell.openItem(path); + }) + }) +}) |
