Skip to content

Commit a743db1

Browse files
committed
crossplatform index.html
1 parent 394327e commit a743db1

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

CREDITS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ wouldn't be created without his assistance.
3535
## Qt
3636

3737
https://github.com/richmoore/qt-examples/tree/master/sitespecificbrowser
38-
https://github.com/NixOS/nixpkgs/issues/16327
3938

4039
https://doc.qt.io/archives/qt-5.5/qwebpage.html#windowCloseRequested
4140
https://doc.qt.io/qt-4.8/qmake-advanced-usage.html
@@ -55,7 +54,6 @@ https://wiki.qt.io/Open_Web_Page_in_QWebView
5554

5655
https://forum.qt.io/topic/18879/relative-path-on-qmake-pro-file
5756
https://forum.qt.io/topic/551/get-filename-without-extension
58-
https://forum.qt.io/topic/3314/qwebelement-set-and-get-attribute
5957

6058
http://www.qtcentre.org/threads/46016-Place-QMessageBox-on-middle-of-screen
6159
http://www.qtcentre.org/threads/18146-String-operations-printing-to-stdout
@@ -91,6 +89,7 @@ https://stackoverflow.com/questions/24899558/how-to-check-qt-version-to-include-
9189
https://stackoverflow.com/questions/19822211/qt-parsing-json-using-qjsondocument-qjsonobject-qjsonarray
9290
https://stackoverflow.com/questions/2241808/checking-if-a-folder-exists-and-creating-folders-in-qt-c
9391
https://stackoverflow.com/questions/9641807/qdir-mkdir-with-absolutepath
92+
https://stackoverflow.com/questions/4916193/creating-writing-into-a-new-file-in-qt
9493

9594
http://www.java2s.com/Code/Cpp/Qt/CheckfileexistanceandfilenamewithQFile.htm
9695
http://webkit.sed.hu/content/disabling-cache
@@ -137,6 +136,8 @@ https://stackoverflow.com/questions/42053775/getting-error-form-submission-cance
137136
https://jquery.com/
138137
http://youmightnotneedjquery.com/
139138

139+
https://www.geeksforgeeks.org/detect-the-operating-system-of-user-using-javascript/
140+
140141
## Bootstrap
141142

142143
https://getbootstrap.com/docs/4.0/components/buttons/

doc/INTERACTIVE.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,20 @@ PEB interactive Perl scripts are able to receive user input multiple times after
3030
}
3131
```
3232

33+
* **Temporary File Full Path Message**
34+
Every interactive script using temporary file must send the full path of its temporary file to PEB using the following simple JSON message:
35+
36+
```javascript
37+
{"tempfile":"/path/to/tempfile"}
38+
```
39+
3340
## Examples of Interactive Perl Scripts
3441

3542
The [index.htm](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/index.html) file demonstrates how to start automatically one Perl interactive script in two instances.
3643

3744
The [interactive.pl](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/perl-scripts/interactive.pl) is a Perl interactive script using STDIN input.
3845

3946
The [interactive-tempfile.pl](https://github.com/ddmitov/perl-executing-browser/blob/master/resources/app/perl-scripts/interactive-tempfile.pl) is a Perl interactive script using a temporary file.
40-
This script creates a temporary file on startup and sends to PEB its full path in the following JSON format:
41-
42-
```javascript
43-
{"tempfile":"/path/to/tempfile"}
44-
```
45-
46-
PEB sends data to the script by writing in its temporary file and the script checks periodically its temporary file for new messages.
47+
* This script creates a temporary file on startup and sends its full path to PEB.
48+
* PEB sends data to the script by writing in its temporary file.
49+
* The script checks periodically its temporary file for any new messages.

resources/app/index.html

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,30 @@
2323
<meta charset="utf-8">
2424

2525
<script>
26+
// Change file paths according to the operating suystem:
27+
var operating_system = '';
28+
var perl_interpreter = '';
29+
var interactive_script = '';
30+
31+
if (navigator.userAgent.indexOf('Linux') != -1) {
32+
operating_system = 'Linux'
33+
perl_interpreter = 'perl/bin/perl';
34+
interactive_script = 'perl-scripts/interactive.pl';
35+
}
36+
37+
if (navigator.userAgent.indexOf('Win') != -1) {
38+
operating_system = 'Windows'
39+
perl_interpreter = 'perl/perl/bin/wperl.exe';
40+
interactive_script = 'perl-scripts/interactive-tempfile.pl';
41+
}
42+
43+
console.log('Operating system: ' + operating_system)
44+
console.log('Perl interpreter: ' + perl_interpreter)
45+
console.log('Interactive script: ' + interactive_script)
46+
2647
// PEB page settings:
2748
var pebSettings = {}; // 'pebSettings' object name is hard-coded.
28-
pebSettings.perlInterpreter = 'perl/bin/perl';
29-
// pebSettings.perlInterpreter = 'perl/perl/bin/wperl.exe';
49+
pebSettings.perlInterpreter = perl_interpreter;
3050
pebSettings.autoStartScripts = ['interactive_one', 'interactive_two'];
3151
pebSettings.cutLabel = '- Cut -';
3252
pebSettings.copyLabel = '- Copy -';
@@ -42,7 +62,7 @@
4262

4363
// PEB settings objects for auto-started Perl interactive scripts:
4464
var interactive_one = {};
45-
interactive_one.scriptRelativePath = 'perl-scripts/interactive-tempfile.pl';
65+
interactive_one.scriptRelativePath = interactive_script;
4666

4767
interactive_one.inputData = function() {
4868
var data = {}
@@ -56,7 +76,7 @@
5676
var target = document.getElementById('instance-one-output');
5777
var output = JSON.parse(stdout);
5878
var html;
59-
if(("user_input" in output)) {
79+
if ("user_input" in output) {
6080
html = output.time + '<br>' + output.user_input;
6181
} else {
6282
html = output.time;
@@ -71,7 +91,7 @@
7191
}
7292

7393
var interactive_two = {};
74-
interactive_two.scriptRelativePath = 'perl-scripts/interactive-tempfile.pl';
94+
interactive_two.scriptRelativePath = interactive_script;
7595

7696
interactive_two.inputData = function() {
7797
var data = {}
@@ -85,7 +105,7 @@
85105
var target = document.getElementById('instance-two-output');
86106
var output = JSON.parse(stdout);
87107
var html;
88-
if(("user_input" in output)) {
108+
if ("user_input" in output) {
89109
html = output.time + '<br>' + output.user_input;
90110
} else {
91111
html = output.time;

resources/app/perl-scripts/interactive.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
chomp $stdin;
5050

5151
my $input = get_input($stdin);
52-
$user_input = decode('UTF-8', $input->{user_input});
52+
$user_input = decode('UTF-8', $input->{user_input});
5353

5454
if ($user_input =~ "exit") {
5555
shutdown_procedure();

0 commit comments

Comments
 (0)