From dc547108e1d85c2dd241d329e0858dced90bf92c Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 18 Apr 2018 22:30:26 -0400 Subject: [PATCH] handle firefox's window.close() permission denied --- embroider_print.py | 2 +- messages.po | 8 +++++++- print/resources/inkstitch.js | 13 ++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/embroider_print.py b/embroider_print.py index 0dbff9296..cbdaeb09d 100644 --- a/embroider_print.py +++ b/embroider_print.py @@ -133,7 +133,7 @@ class PrintPreviewServer(Thread): def shutdown(): self.shutting_down = True request.environ.get('werkzeug.server.shutdown')() - return 'Server shutting down...' + return _('Closing...') + '

' + _('It is safe to close this window now.') @self.app.route('/resources/', methods=['GET']) def resources(resource): diff --git a/messages.po b/messages.po index ce85878dd..27a25d3ea 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-04-18 16:29-0400\n" +"POT-Creation-Date: 2018-04-18 22:30-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -98,6 +98,12 @@ msgid "" "\"Overwrite\"" msgstr "" +msgid "Closing..." +msgstr "" + +msgid "It is safe to close this window now." +msgstr "" + msgid "" "A print preview has been opened in your web browser. This window will " "stay open in order to communicate with the JavaScript code running in " diff --git a/print/resources/inkstitch.js b/print/resources/inkstitch.js index 25a5354e3..498b12112 100644 --- a/print/resources/inkstitch.js +++ b/print/resources/inkstitch.js @@ -213,6 +213,18 @@ $(function() { $.post('/shutdown', {}) .done(function(data) { window.close(); + + /* Chrome and Firefox both have a rule: scripts can only close windows + * that they opened. Chrome seems to have an exception for windows that + * were opened by an outside program, so the above works fine. Firefox + * steadfastly refuses to allow us to close the window, so we'll tell + * the user (in their language) that they can close it. + */ + setTimeout(function() { + document.open(); + document.write("" + data + ""); + document.close(); + }, 1000); }); }); @@ -240,7 +252,6 @@ $(function() { $('select#printing-size').change(function(){ var size = $(this).find(':selected').val(); $('.page').toggleClass('a4', size == 'a4'); - console.log("" + Date.now() + "paper size changed"); $.postJSON('/settings/paper-size', {value: size}); });