Skip to content

Commit 5f728f6

Browse files
committed
better code for auto-start scripts
1 parent addf2c7 commit 5f728f6

File tree

4 files changed

+31
-39
lines changed

4 files changed

+31
-39
lines changed

README.md

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Inspired by [Electron](http://electron.atom.io/) and [NW.js](http://nwjs.io/), P
3232
* [What PEB Is Not](#what-peb-is-not)
3333
* [Limitations](#limitations)
3434
* [History](#history)
35-
* [Applications Based on PEB](#applications-based-on-peb)
3635
* [License](#license)
3736
* [Authors](#authors)
3837

@@ -87,10 +86,9 @@ Note that PEB is created to work from any folder without installation and all fi
8786
* Files or folders can not be selected with their full paths from web pages.
8887

8988
## Compiling
90-
The only compile-time requirement of PEB is a Qt development bundle version 5.0 or any later version.
89+
The only compile-time requirement of PEB is a Qt development bundle version 5.2 or any later version.
9190

9291
Compiled and tested successfully using:
93-
* [Qt Creator 2.8.1 and Qt 5.1.1](http://download.qt.io/archive/qt/5.1/5.1.1/) on 32-bit Debian
9492
* [Qt Creator 3.0.0 and Qt 5.2.0](http://download.qt.io/archive/qt/5.2/5.2.0/) on 32-bit Debian and 32-bit Windows XP
9593
* [Qt Creator 3.0.1 and Qt 5.2.1](http://download.qt.io/archive/qt/5.2/5.2.1/) on 64-bit OS X 10.9.1, i5
9694
* [Qt Creator 3.1.1 and Qt 5.3.0](http://download.qt.io/archive/qt/5.3/5.3.0/) on 64-bit Lubuntu 14.10
@@ -150,26 +148,26 @@ A minimal example of a Perl script settings object:
150148

151149
```javascript
152150
var perlScriptObject = {};
153-
perlScriptObject.path = '{app}/test/test.pl';
151+
perlScriptObject.path = '{app}/perl/test.pl';
154152
perlScriptObject.stdout = 'test';
155153
```
156154

157-
* **path:**
155+
* ``path``
158156
This is the path of the Perl script that is going to be executed.
159157
The keyword ``{app}`` will be replaced by the the full path of the application directory.
160158
*This object property is mandatory.*
161159

162-
* **stdout:**
163-
The ``stdout`` object property must be an unique name of a valid HTML DOM element or JavaScript function. Every piece of script output is immediately inserted into the specified DOM element or passed to the specified JavaScript function as its only argument.
160+
* ``stdout``
161+
The ``stdout`` object property must be an id of a valid HTML DOM element or the name of a JavaScript function. Every piece of script output is immediately inserted into the DOM element or passed to the JavaScript function as its only argument.
164162
*This object property is mandatory.*
165163

166-
* **requestMethod:**
164+
* ``requestMethod``
167165
Only ``GET`` or ``POST`` are recognized.
168166

169-
* **inputData:**
167+
* ``inputData``
170168
This object property is useless if ``requestMethod`` is not set.
171169

172-
* **inputDataHarvester:**
170+
* ``inputDataHarvester``
173171
This object property is a function that can get input data from an HTML form or other data source and supply it to PEB.
174172

175173
Single input box example with no dependencies:
@@ -190,10 +188,10 @@ perlScriptObject.stdout = 'test';
190188
}
191189
```
192190

193-
* **close_command:**
191+
* ``close_command``
194192
The ``close_command`` object property designates the command used to gracefully shut down an interactive script when the containing PEB window is going to be closed. Upon receiving it, the interactive script must start its shutdown procedure.
195193

196-
* **close_confirmation:**
194+
* ``close_confirmation``
197195
Just before exiting an interactive script must print on STDOUT its ``close_confirmation`` to signal PEB that it completed its shutdown. All interactive scripts must exit in 5 seconds after ``close_command`` is given or any unresponsive scripts will be killed and PEB will exit.
198196

199197
Perl scripts running for a long time should have ``$|=1;`` among their first lines to disable the built-in buffering of the Perl interpreter. Some builds of Perl may not give any output until the script is finished when buffering is enabled.
@@ -241,7 +239,7 @@ The following code shows how to start an interactive Perl script right after a l
241239
The ``index.htm`` file of the demo package demonstrates how to start one script in two instances immediately after a page is loaded.
242240

243241
## Selecting Files and Folders
244-
Selecting files or folders with their full paths is performed by clicking a link to a pseudo filename composed from the name of the JavaScript object with the settings of the wanted dialog and a ``.dialog`` extension. Selected files or folders are seamlessly inserted into the HTML DOM of the local page using the ``target`` object property. ``target`` must be an unique name of a valid HTML DOM element or JavaScript function. All selected files or folders are inserted into the specified DOM element or passed to the specified JavaScript function as its only argument.
242+
Selecting files or folders with their full paths is performed by clicking a link to a pseudo filename composed from the name of the JavaScript object with the settings of the wanted dialog and a ``.dialog`` extension. Selected files or folders are seamlessly inserted in any local page using the ``target`` object property. ``target`` must be an id of a valid HTML DOM element or the name of a JavaScript function which receives all selected files or folders as its only argument.
245243

246244
```html
247245
<a href="select_file.dialog">Select existing file</a>
@@ -266,16 +264,16 @@ select_file.target = 'tests';
266264
The binary file of the browser, ``peb``, ``peb.app``, ``peb.dmg`` or ``peb.exe`` by default, can be renamed without restrictions. It can take the name of the PEB-based application it is going to run. No additional adjustments are necessary after renaming the binary. If log files are wanted, they will take the name of the binary file (without the filename extension), whatever the name may be.
267265

268266
## Hard Coded Files and Folders
267+
* **Perl interpreter:**
268+
PEB expects to find Perl interpreter in ``{PEB_binary_directory}/perl/bin`` folder. The interpreter must be named ``perl`` on Linux and Mac machines and ``perl.exe`` on Windows machines. If Perl interpreter is not found in the above location, PEB will try to find the first Perl interpreter on PATH. If no Perl interpreter is found, an error page is displayed instead of the start page. No Perl interpreter is a showstopper for PEB.
269+
269270
* **Application directory:**
270271
Application directory is ``{PEB_binary_directory}/resources/app``.
271272
All files used by PEB, with the exception of data files, should be located within this folder.
272273

273274
Application directory is hard coded in C++ code for compatibility with the [Electron](http://electron.atom.io/) framework.
274275
[Epigraphista](https://github.com/ddmitov/epigraphista) is an example of a PEB-based application, that is also compatible with [Electron](http://electron.atom.io/) and [NW.js](http://nwjs.io/).
275276

276-
* **Perl interpreter:**
277-
PEB expects to find Perl interpreter in ``{PEB_binary_directory}/perl/bin`` folder. The interpreter must be named ``perl`` on Linux and Mac machines and ``perl.exe`` on Windows machines. If Perl interpreter is not found in the above location, PEB will try to find the first Perl interpreter on PATH. If no Perl interpreter is found, an error page is displayed instead of the start page. No Perl interpreter is a showstopper for PEB.
278-
279277
* **Start page:**
280278
PEB starts always with ``{PEB_binary_directory}/resources/app/index.html``. If this file is missing, an error message is displayed. No start page is a showstopper for PEB.
281279
Note that start page pathname is case sensitive.
@@ -316,10 +314,10 @@ pebSettings.closeConfirmation =
316314
```
317315

318316
* ``autoStartScripts``
319-
These are Perl scripts that will be started immediately after the local page is loaded.
317+
These are Perl scripts that are started immediately after a local page is loaded.
320318

321319
* ``closeConfirmation``
322-
When user starts closing PEB, it checks for any unsaved data in all forms. If any user data in HTML forms is detected, PEB displays a warning using the text of ``pebSettings.closeConfirmation``. If no warning text is found, PEB assumes that no warning has to be displayed and exits immediately.
320+
This is the text displayed when user has pressed the close button, but unsaved data in local HTML forms is detected. If no warning text is found, PEB assumes that no warning has to be displayed and exits immediately.
323321

324322
## Functional Pseudo Filenames
325323
* **About PEB dialog:** ``about-browser.function``
@@ -347,11 +345,6 @@ pebSettings.closeConfirmation =
347345
## History
348346
PEB was started as a simple GUI for personal databases in 2013 by Dimitar D. Mitov.
349347

350-
## Applications Based on PEB
351-
* [Epigraphista](https://github.com/ddmitov/epigraphista) is an [EpiDoc](https://sourceforge.net/p/epidoc/wiki/Home/) XML file creator.
352-
It is a hybrid desktop or server application using [Perl Executing Browser](https://github.com/ddmitov/perl-executing-browser), [Electron](http://electron.atom.io/) or [NW.js](http://nwjs.io/) as a desktop GUI framework.
353-
* [Camel Doctor](https://github.com/ddmitov/camel-doctor) is a Linux and Mac serverless HTML user interface for the [default Perl debugger](http://perldoc.perl.org/perldebug.html).
354-
355348
## License
356349
This program is free software;
357350
you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License,

REQUIREMENTS.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
## Compile-time Requirements
2-
The only compile-time requirement of PEB is a Qt development bundle version 5.0 or any later version.
2+
The only compile-time requirement of PEB is a Qt development bundle version 5.2 or any later version.
33

44
Compiled and tested successfully using:
5-
* [Qt Creator 2.8.1 and Qt 5.1.1](http://download.qt.io/archive/qt/5.1/5.1.1/) on 32-bit Debian
65
* [Qt Creator 3.0.0 and Qt 5.2.0](http://download.qt.io/archive/qt/5.2/5.2.0/) on 32-bit Debian and 32-bit Windows XP
76
* [Qt Creator 3.0.1 and Qt 5.2.1](http://download.qt.io/archive/qt/5.2/5.2.1/) on 64-bit OS X 10.9.1, i5
87
* [Qt Creator 3.1.1 and Qt 5.3.0](http://download.qt.io/archive/qt/5.3/5.3.0/) on 64-bit Lubuntu 14.10

src/webengine-page.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <QFileDialog>
2222
#include <QInputDialog>
23+
#include <QJsonArray>
2324
#include <QJsonDocument>
2425
#include <QJsonObject>
2526
#include <QMessageBox>
@@ -73,14 +74,13 @@ public slots:
7374
QJsonObject settingsJsonObject = settingsJsonDocument.object();
7475

7576
// Get auto-start scripts:
76-
QStringList autoStartScripts =
77-
settingsJsonObject["autoStartScripts"]
78-
.toVariant().toStringList();
77+
QJsonArray autoStartScripts =
78+
settingsJsonObject["autoStartScripts"].toArray();
7979

80-
if (!autoStartScripts.isEmpty()) {
81-
foreach (QString autoStartScript, autoStartScripts) {
82-
qHandleScripts(autoStartScript);
83-
}
80+
foreach (const QJsonValue &value, autoStartScripts) {
81+
QString autoStartScript = value.toString();
82+
qDebug() << "Auto-start script:" << autoStartScript;
83+
qHandleScripts(autoStartScript);
8484
}
8585

8686
// Get dialog and context menu labels:

src/webkit-page.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <QFileDialog>
2222
#include <QInputDialog>
23+
#include <QJsonArray>
2324
#include <QJsonDocument>
2425
#include <QJsonObject>
2526
#include <QMessageBox>
@@ -74,14 +75,13 @@ public slots:
7475
QJsonObject settingsJsonObject = settingsJsonDocument.object();
7576

7677
// Get auto-start scripts:
77-
QStringList autoStartScripts =
78-
settingsJsonObject["autoStartScripts"]
79-
.toVariant().toStringList();
78+
QJsonArray autoStartScripts =
79+
settingsJsonObject["autoStartScripts"].toArray();
8080

81-
if (!autoStartScripts.isEmpty()) {
82-
foreach (QString autoStartScript, autoStartScripts) {
83-
qHandleScripts(autoStartScript);
84-
}
81+
foreach (const QJsonValue &value, autoStartScripts) {
82+
QString autoStartScript = value.toString();
83+
qDebug() << "Auto-start script:" << autoStartScript;
84+
qHandleScripts(autoStartScript);
8585
}
8686

8787
// Get dialog and context menu labels:

0 commit comments

Comments
 (0)