diff options
| author | Lex Neva <github.com@lexneva.name> | 2019-04-12 17:45:57 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2019-04-12 17:57:07 -0400 |
| commit | 9b2a47136b34a4b9cfcc42282a39fdd909e9f8af (patch) | |
| tree | 67edbda61bb5b72afac0c1bf26836f7feda43a48 /electron/src | |
| parent | 785e3798c46a00ccbde89c0aeee95140dfbe6d92 (diff) | |
enable print button
Diffstat (limited to 'electron/src')
| -rw-r--r-- | electron/src/index.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/electron/src/index.js b/electron/src/index.js index 398a9580..90aaea63 100644 --- a/electron/src/index.js +++ b/electron/src/index.js @@ -1,4 +1,5 @@ -import { app, BrowserWindow } from 'electron'; +import { app, BrowserWindow, ipcMain, dialog } from 'electron'; +var fs = require('fs'); // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. @@ -11,8 +12,16 @@ const createWindow = () => { mainWindow.maximize(); // and load the index.html of the app. - mainWindow.loadURL(process.argv[1]); + if (process.argv[1] == ".") { + // run in development mode with `electron . <url>` + var url = process.argv[2]; + } else { + var url = process.argv[1]; + } + mainWindow.loadURL(url); + mainWindow.webContents.openDevTools(); + // Emitted when the window is closed. mainWindow.on('closed', () => { // Dereference the window object, usually you would store windows @@ -31,3 +40,11 @@ app.on('ready', createWindow); app.on('window-all-closed', () => { app.quit(); }); + +ipcMain.on('print', function (event, pageSize) { + mainWindow.webContents.printToPDF({"pageSize": pageSize}, function(error, data) { + dialog.showSaveDialog(mainWindow, {"defaultPath": "inkstitch.pdf"}, function(filename, bookmark) { + fs.writeFileSync(filename, data, 'utf-8'); + }) + }) +})
\ No newline at end of file |
