diff options
| author | Lex Neva <github.com@lexneva.name> | 2020-07-21 23:19:53 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2020-07-21 23:19:53 -0400 |
| commit | 00dd71e63f575533278c9609df5cd0276d6c2702 (patch) | |
| tree | 140593e8d03a5a2d0478b823ef6b60c199abdbd5 /electron/src | |
| parent | 7304d884978dd6bb20a99040392bfd85f41c30d6 (diff) | |
fix save and print PDF buttons
Diffstat (limited to 'electron/src')
| -rw-r--r-- | electron/src/main/index.js | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/electron/src/main/index.js b/electron/src/main/index.js index 9e90851f..f7fb9437 100644 --- a/electron/src/main/index.js +++ b/electron/src/main/index.js @@ -1,6 +1,9 @@ 'use strict' -import {app, BrowserWindow} from 'electron' +import {app, BrowserWindow, ipcMain, dialog, shell} from 'electron' +var fs = require('fs'); +var path = require('path'); +var tmp = require('tmp'); const url = require('url') @@ -15,7 +18,7 @@ if (process.env.NODE_ENV === 'development') { process.argv.shift() process.argv.shift() } else { - global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\') + global.__static = path.join(__dirname, '/static').replace(/\\/g, '\\\\') } let mainWindow @@ -69,6 +72,25 @@ app.on('activate', () => { } }) +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'); + }) + }) +}) + +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); + }) + }) +}) + + /** * Auto Updater * |
