kopia lustrzana https://github.com/inkstitch/inkstitch
enable print button
rodzic
785e3798c4
commit
9b2a47136b
|
@ -6,12 +6,19 @@
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"pack": "electron-builder --dir",
|
"pack": "electron-builder --dir",
|
||||||
"dist": "electron-builder"
|
"dist": "electron-builder",
|
||||||
|
"dev": "electron ."
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
"linux": { "target": "dir" },
|
"linux": {
|
||||||
"win": { "target": "dir" },
|
"target": "dir"
|
||||||
"mac": { "target": "dir" }
|
},
|
||||||
|
"win": {
|
||||||
|
"target": "dir"
|
||||||
|
},
|
||||||
|
"mac": {
|
||||||
|
"target": "dir"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "lex",
|
"author": "lex",
|
||||||
|
|
|
@ -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
|
// 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.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
|
@ -11,7 +12,15 @@ const createWindow = () => {
|
||||||
mainWindow.maximize();
|
mainWindow.maximize();
|
||||||
|
|
||||||
// and load the index.html of the app.
|
// 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.
|
// Emitted when the window is closed.
|
||||||
mainWindow.on('closed', () => {
|
mainWindow.on('closed', () => {
|
||||||
|
@ -31,3 +40,11 @@ app.on('ready', createWindow);
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
app.quit();
|
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');
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -88,18 +88,6 @@ class PrintPreviewServer(Thread):
|
||||||
def resources(resource):
|
def resources(resource):
|
||||||
return send_from_directory(self.resources_path, resource, cache_timeout=1)
|
return send_from_directory(self.resources_path, resource, cache_timeout=1)
|
||||||
|
|
||||||
@self.app.route('/printing/start')
|
|
||||||
def printing_start():
|
|
||||||
# temporarily turn off the watcher while the print dialog is up,
|
|
||||||
# because javascript will be frozen
|
|
||||||
self.last_request_time = None
|
|
||||||
return "OK"
|
|
||||||
|
|
||||||
@self.app.route('/printing/end')
|
|
||||||
def printing_end():
|
|
||||||
# nothing to do here -- request_started() will restart the watcher
|
|
||||||
return "OK"
|
|
||||||
|
|
||||||
@self.app.route('/settings/<field_name>', methods=['POST'])
|
@self.app.route('/settings/<field_name>', methods=['POST'])
|
||||||
def set_field(field_name):
|
def set_field(field_name):
|
||||||
self.metadata[field_name] = request.json['value']
|
self.metadata[field_name] = request.json['value']
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from glob import glob
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
@ -14,21 +13,14 @@ def open_url(url):
|
||||||
|
|
||||||
if getattr(sys, 'frozen', None) is not None:
|
if getattr(sys, 'frozen', None) is not None:
|
||||||
electron_path = os.path.join(get_bundled_dir("electron"), "inkstitch-gui")
|
electron_path = os.path.join(get_bundled_dir("electron"), "inkstitch-gui")
|
||||||
|
|
||||||
|
if sys.platform == "darwin":
|
||||||
|
electron_path += ".app/Contents/MacOS/inkstitch-gui"
|
||||||
|
subprocess.Popen(["open", "-a", electron_path, "--args", url])
|
||||||
|
else:
|
||||||
|
app_process = subprocess.Popen([electron_path, url])
|
||||||
else:
|
else:
|
||||||
# It's a bit trickier to find the electron app in a development environment.
|
# if we're not running in a pyinstaller bundle, run electron directly
|
||||||
base_dir = get_bundled_dir("electron")
|
app_process = subprocess.Popen(["yarn", "dev", url], cwd=get_bundled_dir("electron"))
|
||||||
|
|
||||||
try:
|
|
||||||
package_dir = glob(os.path.join(base_dir, 'dist', '*-unpacked'))[0]
|
|
||||||
except IndexError:
|
|
||||||
raise Exception("Electron app not found. Be sure to run 'yarn; yarn dist' in %s." % base_dir)
|
|
||||||
|
|
||||||
electron_path = os.path.join(base_dir, package_dir, "inkstitch-gui")
|
|
||||||
|
|
||||||
if sys.platform == "darwin":
|
|
||||||
electron_path += ".app/Contents/MacOS/inkstitch-gui"
|
|
||||||
app_process = subprocess.Popen(["open", "-a", electron_path, "--args", url])
|
|
||||||
else:
|
|
||||||
app_process = subprocess.Popen([electron_path, url])
|
|
||||||
|
|
||||||
return app_process
|
return app_process
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
var electron = require('electron');
|
||||||
|
|
||||||
$.postJSON = function(url, data, success=null) {
|
$.postJSON = function(url, data, success=null) {
|
||||||
return $.ajax(url, {
|
return $.ajax(url, {
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
|
@ -366,13 +368,8 @@ $(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
$('button.print').click(function() {
|
$('button.print').click(function() {
|
||||||
// printing halts all javascript activity, so we need to tell the backend
|
var pageSize = $('select#printing-size').find(':selected').text();
|
||||||
// not to shut down until we're done.
|
electron.ipcRenderer.send('print', pageSize)
|
||||||
$.get("/printing/start")
|
|
||||||
.done(function() {
|
|
||||||
window.print();
|
|
||||||
$.get("/printing/end");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('button.settings').click(function(){
|
$('button.settings').click(function(){
|
||||||
|
|
Ładowanie…
Reference in New Issue