Merge pull request #769 from inkstitch/lexelby/fix-save-print-pdf

fix save and print PDF buttons
pull/792/head
Lex Neva 2020-08-18 16:06:21 -04:00 zatwierdzone przez GitHub
commit 21a8da80e1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 30 dodań i 7 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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}

Wyświetl plik

@ -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
*