summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2020-08-18 16:06:21 -0400
committerGitHub <noreply@github.com>2020-08-18 16:06:21 -0400
commit21a8da80e115b3121a13fce5835b33885d278a3d (patch)
treea73e5c61cf7d1f9117e8a4ee6fa8569e98e9ba73
parent811f1714d0e20a40c51398df4d186589d07e23ef (diff)
parentc2c2d569c245d9982542bb7e7c526f3a9405e5c8 (diff)
Merge pull request #769 from inkstitch/lexelby/fix-save-print-pdf
fix save and print PDF buttons
-rw-r--r--Makefile6
-rwxr-xr-xbin/build-electron5
-rw-r--r--electron/src/main/index.js26
3 files changed, 30 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 0f559355..b5bbd4e5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
dist: locales inx
- bin/build-python
- bin/build-electron
- bin/build-distribution-archives
+ bash bin/build-python
+ bash bin/build-electron
+ bash bin/build-distribution-archives
distclean:
rm -rf build dist inx locales *.spec *.tar.gz *.zip electron/node_modules electron/dist
diff --git a/bin/build-electron b/bin/build-electron
index dc7a1ca2..11616cb4 100755
--- a/bin/build-electron
+++ b/bin/build-electron
@@ -1,6 +1,7 @@
#!/bin/bash
-
+set -e
+set -x
if [ "$BUILD" = "windows" ]; then
args="-w --ia32"
@@ -11,6 +12,6 @@ elif [ "$BUILD" = "osx" ]; then
fi
cd electron
-npm install -g yarn
+which yarn > /dev/null 2>&1 || npm install -g yarn
yarn --link-duplicates --pure-lockfile
yarn run dist ${args}
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
*