Skip to content

Commit f8bd151

Browse files
committed
better code for closing PEB
1 parent 8aa1630 commit f8bd151

File tree

13 files changed

+85
-98
lines changed

13 files changed

+85
-98
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Perl Executing Browser (PEB) is an HTML5 user interface for [Perl 5](https://www
2727
* [HTML Page API](./doc/SETTINGS.md#html-page-api)
2828
* [Perl Scripts API](./doc/SETTINGS.md#perl-scripts-api)
2929
* [Interactive Perl Scripts](./doc/SETTINGS.md#interactive-perl-scripts)
30-
* [Long-Running Windows Perl Scripts](./doc/SETTINGS.md#long-running-windows-perl-scripts)
3130
* [Selecting Files and Folders](./doc/SETTINGS.md#selecting-files-and-folders)
3231
* [LOGGING](./doc/LOGGING.md)
3332
* [PACKAGING](./doc/PACKAGING.md)

doc/PACKAGING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
* **PEB AppImage Configuration Files**
3232

33-
``{PEB_executable_directory}/resources/app/{application_name}.desktop``
34-
``{PEB_executable_directory}/resources/app/{application_name}.appdata.xml``
33+
``{PEB_executable_directory}/resources/app/appimage/{application_name}.desktop``
34+
``{PEB_executable_directory}/resources/app/appimage/{application_name}.appdata.xml``
3535

3636
``{PEB_executable_directory}/resources/app/{application_name}.desktop``
3737
is mandatory for any PEB-based application which will be packed by the PEB AppImage Maker.

doc/SETTINGS.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The ``pebSettings`` JavaScript object may have the following properties:
5454
``String`` displayed as a label for the 'No' button on JavaScript Confirm popup box.
5555

5656
* **closeConfirmation**
57-
``String`` displayed in a JavaScript Confirm popup box when the close button is pressed, but unsaved data in local HTML forms is detected. If no ``closeConfirmation`` object property is found, PEB exits immediately.
57+
``String`` displayed in a JavaScript Confirm popup box when the close button is pressed, but unsaved data in local HTML forms is detected. If no ``closeConfirmation`` object property is found, PEB shuts down all running Perl scripts and exits.
5858

5959
## Perl Scripts API
6060

@@ -148,17 +148,15 @@ A JavaScript settings object for a Perl script run by PEB has the following prop
148148

149149
## Interactive Perl Scripts
150150

151-
Each PEB interactive Perl script must have its own event loop waiting constantly for new data on STDIN for a bidirectional connection with PEB. Many interactive scripts can be started simultaneously in one PEB instance. One script may be started in many instances, provided that each of them has a uniquely named JavaScript settings object.
152-
153-
Please note that interactive Perl scripts are not supported by the Windows builds of PEB.
151+
Each PEB interactive Perl script must have its own event loop waiting constantly for new data on STDIN or in a temporary file for a bidirectional connection with PEB. Many interactive scripts can be started simultaneously in one PEB instance. One script may be started in many instances, provided that each of them has an uniquely named JavaScript settings object.
154152

155153
A PEB interactive Perl script should have the following features:
156154

157155
* **No buffering**
158156
PEB interactive scripts should have ``$|=1;`` among their first lines to disable the built-in buffering of the Perl interpreter, which prevents any output before the script has ended.
159157

160158
* **Failsafe print**
161-
Failsafe print is necessary for a graceful shutdown of Perl scripts on normal PEB exit and when PEB unexpectedly crashes. PEB closes the STDOUT and STDERR channels of all running Perl scripts when the close button is pressed - they must exit in 3 seconds or any unresponsive scripts are killed.
159+
Failsafe print is necessary for a graceful shutdown of Perl scripts on normal PEB exit and when PEB unexpectedly crashes. When the close button is pressed, PEB closes the STDOUT and STDERR channels of all running Perl scripts and within 3 seconds they must detect their inability to print messages and exit or any unresponsive scripts will be killed.
162160

163161
Failsafe print could be implemented using the following code:
164162

@@ -171,7 +169,7 @@ A PEB interactive Perl script should have the following features:
171169
}
172170
```
173171

174-
The following code shows how to start a PEB interactive Perl script right after a local page is loaded:
172+
The following code shows how to start a PEB interactive Perl script right after the PEB index page is loaded:
175173

176174
```html
177175
<!DOCTYPE html>
@@ -209,15 +207,9 @@ The following code shows how to start a PEB interactive Perl script right after
209207
</html>
210208
```
211209

212-
The [index.htm of the demo package](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/index.html) shows how to start one Perl script in two instances right after the PEB index page is loaded.
213-
214-
The [interactive.pl](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/perl/interactive.pl) script of the demo package is an example of a Perl interactive script for PEB.
215-
216-
## Long-Running Windows Perl Scripts
217-
218-
Long-running Windows Perl scripts are supported provided that they also have ``$|=1;`` among their first lines to disable the built-in buffering of the Perl interpreter.
210+
The [index.htm of the demo package](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/index.html) demonstrates how to start one Perl interactive script in two instances immediately after the PEB index page is loaded.
219211

220-
Windows Perl scripts can not receive the ``SIGTERM`` signal and if they are still running when PEB is closed, they can only be killed with no mechanism for a graceful shutdown.
212+
The [interactive.pl script of the demo package](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/perl/interactive.pl) is an example of a Perl interactive script for PEB.
221213

222214
## Selecting Files and Folders
223215

File renamed without changes.
Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,78 +23,50 @@
2323
'Are you sure you want to close the application?';
2424

2525
// PEB settings objects for auto-started Perl interactive scripts:
26-
var messenger_one = {};
27-
messenger_one.scriptRelativePath = 'perl-scripts/messenger.pl';
28-
29-
messenger_one.inputData = function() {
30-
var message = {};
31-
if(("tempfile" in messenger_one)) {
32-
message.tempfile = messenger_one.tempfile;
33-
}
34-
message.user_input = document.getElementById("interactive-one-input").value;
35-
$('#form-one').trigger('reset');
36-
return JSON.stringify(message);
37-
}
38-
39-
var messenger_two = {};
40-
messenger_two.scriptRelativePath = 'perl-scripts/messenger.pl';
41-
42-
messenger_two.inputData = function() {
43-
var message = {};
44-
if(("tempfile" in messenger_two)) {
45-
message.tempfile = messenger_two.tempfile;
46-
}
47-
message.user_input = document.getElementById("interactive-two-input").value;
48-
$('#form-two').trigger('reset');
49-
return JSON.stringify(message);
50-
}
51-
5226
var interactive_one = {};
53-
interactive_one.scriptRelativePath = 'perl-scripts/interactive-windows.pl';
27+
interactive_one.scriptRelativePath = 'perl-scripts/interactive.pl';
5428

5529
interactive_one.inputData = function() {
56-
var input = {};
30+
var input = {}
5731
input.mode = "unix-epoch";
32+
input.user_input = document.getElementById("interactive-one-input").value;
33+
$('#form-one').trigger('reset');
5834
return JSON.stringify(input);
5935
}
6036

6137
interactive_one.stdoutFunction = function (stdout) {
6238
var target = document.getElementById('instance-one-output');
6339
var output = JSON.parse(stdout);
6440
var html;
65-
messenger_one.tempfile = output.tempfile;
6641
if(("user_input" in output)) {
67-
if (output.user_input != undefined) {
68-
html = output.time + '<br>' + output.user_input;
69-
} else {
70-
html = output.time;
71-
}
72-
target.innerHTML = html;
42+
html = output.time + '<br>' + output.user_input;
43+
} else {
44+
html = output.time;
7345
};
46+
target.innerHTML = html;
7447
}
7548

7649
var interactive_two = {};
77-
interactive_two.scriptRelativePath = 'perl-scripts/interactive-windows.pl';
50+
interactive_two.scriptRelativePath = 'perl-scripts/interactive.pl';
7851

7952
interactive_two.inputData = function() {
80-
var input = {};
53+
var input = {}
8154
input.mode = "local-time";
55+
input.user_input = document.getElementById("interactive-two-input").value;
56+
$('#form-one').trigger('reset');
8257
return JSON.stringify(input);
8358
}
8459

8560
interactive_two.stdoutFunction = function (stdout) {
8661
var target = document.getElementById('instance-two-output');
8762
var output = JSON.parse(stdout);
8863
var html;
89-
messenger_two.tempfile = output.tempfile;
9064
if(("user_input" in output)) {
91-
if (output.user_input != undefined) {
92-
html = output.time + '<br>' + output.user_input;
93-
} else {
94-
html = output.time;
95-
}
96-
target.innerHTML = html;
65+
html = output.time + '<br>' + output.user_input;
66+
} else {
67+
html = output.time;
9768
};
69+
target.innerHTML = html;
9870
}
9971
</script>
10072

@@ -192,7 +164,7 @@ <h3>Interactive Script Demo</h3>
192164

193165
<div class="row">
194166
<div class="col-xs-12 form-group">
195-
<form action="messenger_one.script" id="form-one">
167+
<form action="interactive_one.script" id="form-one">
196168
<div class="input-group">
197169
<input type="text" id="interactive-one-input" name="input" class="form-control"
198170
placeholder="Press Enter to send data to the first interactive script instance">
@@ -215,7 +187,7 @@ <h3>Interactive Script Demo</h3>
215187

216188
<div class="row">
217189
<div class="col-xs-12 form-group">
218-
<form action="messenger_two.script" id="form-two">
190+
<form action="interactive_two.script" id="form-two">
219191
<div class="input-group">
220192
<input type="text" id="interactive-two-input" name="input" class="form-control"
221193
placeholder="Press Enter to send data to the second interactive script instance">

resources/app/index.html

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,74 @@
2323
'Are you sure you want to close the application?';
2424

2525
// PEB settings objects for auto-started Perl interactive scripts:
26+
var messenger_one = {};
27+
messenger_one.scriptRelativePath = 'perl-scripts/messenger.pl';
28+
29+
messenger_one.message = {};
30+
messenger_one.inputData = function() {
31+
messenger_one.message.user_input =
32+
document.getElementById("interactive-one-input").value;
33+
$('#form-one').trigger('reset');
34+
return JSON.stringify(messenger_one.message);
35+
}
36+
37+
var messenger_two = {};
38+
messenger_two.scriptRelativePath = 'perl-scripts/messenger.pl';
39+
40+
messenger_two.message = {};
41+
messenger_two.inputData = function() {
42+
messenger_two.message.user_input =
43+
document.getElementById("interactive-two-input").value;
44+
$('#form-two').trigger('reset');
45+
return JSON.stringify(messenger_two.message);
46+
}
47+
2648
var interactive_one = {};
27-
interactive_one.scriptRelativePath = 'perl-scripts/interactive.pl';
49+
interactive_one.scriptRelativePath = 'perl-scripts/interactive-windows.pl';
2850

2951
interactive_one.inputData = function() {
30-
var input = {}
52+
var input = {};
3153
input.mode = "unix-epoch";
32-
input.user_input = document.getElementById("interactive-one-input").value;
33-
$('#form-one').trigger('reset');
3454
return JSON.stringify(input);
3555
}
3656

3757
interactive_one.stdoutFunction = function (stdout) {
3858
var target = document.getElementById('instance-one-output');
3959
var output = JSON.parse(stdout);
4060
var html;
61+
messenger_one.message.tempfile = output.tempfile;
4162
if(("user_input" in output)) {
42-
html = output.time + '<br>' + output.user_input;
43-
} else {
44-
html = output.time;
63+
if (output.user_input != undefined) {
64+
html = output.time + '<br>' + output.user_input;
65+
} else {
66+
html = output.time;
67+
}
68+
target.innerHTML = html;
4569
};
46-
target.innerHTML = html;
4770
}
4871

4972
var interactive_two = {};
50-
interactive_two.scriptRelativePath = 'perl-scripts/interactive.pl';
73+
interactive_two.scriptRelativePath = 'perl-scripts/interactive-windows.pl';
5174

5275
interactive_two.inputData = function() {
53-
var input = {}
76+
var input = {};
5477
input.mode = "local-time";
55-
input.user_input = document.getElementById("interactive-two-input").value;
56-
$('#form-one').trigger('reset');
5778
return JSON.stringify(input);
5879
}
5980

6081
interactive_two.stdoutFunction = function (stdout) {
6182
var target = document.getElementById('instance-two-output');
6283
var output = JSON.parse(stdout);
6384
var html;
85+
messenger_two.message.tempfile = output.tempfile;
6486
if(("user_input" in output)) {
65-
html = output.time + '<br>' + output.user_input;
66-
} else {
67-
html = output.time;
87+
if (output.user_input != undefined) {
88+
html = output.time + '<br>' + output.user_input;
89+
} else {
90+
html = output.time;
91+
}
92+
target.innerHTML = html;
6893
};
69-
target.innerHTML = html;
7094
}
7195
</script>
7296

@@ -164,7 +188,7 @@ <h3>Interactive Script Demo</h3>
164188

165189
<div class="row">
166190
<div class="col-xs-12 form-group">
167-
<form action="interactive_one.script" id="form-one">
191+
<form action="messenger_one.script" id="form-one">
168192
<div class="input-group">
169193
<input type="text" id="interactive-one-input" name="input" class="form-control"
170194
placeholder="Press Enter to send data to the first interactive script instance">
@@ -187,7 +211,7 @@ <h3>Interactive Script Demo</h3>
187211

188212
<div class="row">
189213
<div class="col-xs-12 form-group">
190-
<form action="interactive_two.script" id="form-two">
214+
<form action="messenger_two.script" id="form-two">
191215
<div class="input-group">
192216
<input type="text" id="interactive-two-input" name="input" class="form-control"
193217
placeholder="Press Enter to send data to the second interactive script instance">

sdk/appimage-maker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fi
9090
# Pack PEB and include the 'resources' folder in the resulting AppImage:
9191
if [ $mode == "include-resources" ]; then
9292
# AppImage desktop file is mandatory:
93-
package_desktop_file="$(ls ./resources/app/*.desktop)"
93+
package_desktop_file="$(ls ./resources/app/appimage/*.desktop)"
9494
if [ ! -e "$package_desktop_file" ]; then
9595
printf "\\nPackage .desktop file is missing!\\n"
9696
exit 1
@@ -115,7 +115,7 @@ if [ $mode == "include-resources" ]; then
115115
fi
116116

117117
# AppImage metadata file:
118-
if [ -e "$(pwd)/resources/app/$appimage_name.appdata.xml" ]; then
118+
if [ -e "$(pwd)/resources/app/appimage/$appimage_name.appdata.xml" ]; then
119119
mkdir -p "$(pwd)/$appimage_name.app/usr/share/metainfo"
120120
cp -f "$(pwd)/resources/app/$appimage_name.appdata.xml" "$(pwd)/$appimage_name.app/usr/share/metainfo/$appimage_name.appdata.xml"
121121
fi

src/main.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ int main(int argc, char **argv)
169169

170170
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
171171
if (ANNULEN_QTWEBKIT == 0) {
172-
// Signal and slot for fullscreen video:
172+
// Signal and slot for QtWebEngine fullscreen signal:
173173
QObject::connect(mainWindow.webViewWidget->page(),
174174
SIGNAL(fullScreenRequested(QWebEngineFullScreenRequest)),
175175
&mainWindow,
@@ -183,10 +183,6 @@ int main(int argc, char **argv)
183183
mainWindow.webViewWidget->page(),
184184
SLOT(qStartWindowClosingSlot()));
185185

186-
// Signal and slot for actions taken before application exit:
187-
QObject::connect(qApp, SIGNAL(aboutToQuit()),
188-
&mainWindow, SLOT(qExitApplicationSlot()));
189-
190186
// ==============================
191187
// Start page:
192188
// ==============================

src/webengine-main-window.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ public slots:
6363
event->ignore();
6464
emit startMainWindowClosingSignal();
6565
}
66-
}
6766

68-
void qExitApplicationSlot()
69-
{
70-
QApplication::exit();
67+
if (qApp->property("windowCloseRequested").toBool() == true) {
68+
event->accept();
69+
}
7170
}
7271

7372
public:

0 commit comments

Comments
 (0)