Skip to content

Commit 6e1cdb0

Browse files
committed
better AppImage support
1 parent 8c83388 commit 6e1cdb0

File tree

12 files changed

+88
-42
lines changed

12 files changed

+88
-42
lines changed

CONSTANTS.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@ Perl Executing Browser - Constants
33

44
## Hard Coded Files and Folders
55
* **Perl interpreter:**
6-
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.
6+
PEB expects to find a Perl interpreter in the ``{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 use the first Perl interpreter on PATH.
7+
8+
* **Resources directory:**
9+
Resources directory is ``{PEB_binary_directory}/resources`` or ``{AppImage_binary_directory}/resources`` if a PEB-based application is packed as an [AppImage](https://appimage.org/). Application, data and logs directories, as well as icon file of a PEB application must be located in this folder.
710

811
* **Application directory:**
912
Application directory is ``{PEB_binary_directory}/resources/app``.
10-
All files used by PEB, with the exception of data files, should be located within this folder.
13+
All files used by PEB, with the exception of data files, must be located within this folder.
1114

1215
Application directory is hard coded in C++ code for compatibility with the [Electron](http://electron.atom.io/) framework.
1316
[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/).
1417

1518
By default the working directory of all Perl scripts run by PEB is the application directory.
1619

1720
* **Data Directory:**
18-
Data directory should contain any files used or produced by a PEB-based application.
19-
The data directory path is ``{PEB_binary_directory}/resources/data``.
20-
Perl scripts can access this folder using the environment variable ``PEB_DATA_DIR``:
21+
Data directory must contain any writable files used or produced by a PEB-based application.
22+
The data directory path is ``{PEB_binary_directory}/resources/data`` or ``{AppImage_binary_directory}/resources/data`` if a PEB-based application is packed as an [AppImage](https://appimage.org/). Perl scripts can access this folder using the environment variable ``PEB_DATA_DIR``:
2123

2224
```perl
2325
my $data_directory = $ENV{'PEB_DATA_DIR'};

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ https://stackoverflow.com/questions/23174393/parse-jsonarray
145145
https://stackoverflow.com/questions/24899558/how-to-check-qt-version-to-include-different-header
146146
https://stackoverflow.com/questions/19822211/qt-parsing-json-using-qjsondocument-qjsonobject-qjsonarray
147147
https://stackoverflow.com/questions/2241808/checking-if-a-folder-exists-and-creating-folders-in-qt-c
148+
https://stackoverflow.com/questions/9641807/qdir-mkdir-with-absolutepath
148149

149150
http://www.java2s.com/Code/Cpp/Qt/CheckfileexistanceandfilenamewithQFile.htm
150151
http://webkit.sed.hu/content/disabling-cache

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Inspired by [Electron](http://electron.atom.io/) and [NW.js](http://nwjs.io/), P
3333
* [Starting Local Server](./SETTINGS.md#starting-local-server)
3434
* [Selecting Files and Folders](./SETTINGS.md#selecting-files-and-folders)
3535
* [Minimal Portable Perl Distribution for PEB](./SETTINGS.md#minimal-portable-perl-distribution-for-peb)
36+
* [AppImage Support](./SETTINGS.md#appimage-support)
3637
* [Log Files](./SETTINGS.md#log-files)
3738
* [History](#history)
3839
* [License](./LICENSE.md)

REQUIREMENTS.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@ Perl Executing Browser - Requirements
22
--------------------------------------------------------------------------------
33

44
## Compile-Time Requirements
5-
The only Linux and Macintosh compile-time requirement of PEB is a GCC-based Qt development bundle version 5.2 or any later version.
5+
The only Linux and Macintosh compile-time requirement of PEB is a Qt development bundle version 5.2 or any later version.
66

7-
The source code of PEB is not MSVC-compatible and PEB can not be compiled using any MSVC-based Windows version of Qt. Only applications build for a MSVC-based Qt version 5.6.x or higher can use ```QtWebEngine``` on the Windows platform. Windows GCC-based Qt development bundles version 5.6.x or higher have neither ```QtWebEngine```, nor ```QtWebKit```.
8-
This means that:
9-
* Windows builds of PEB can only be compiled by a GCC-based Qt development bundle.
10-
* Windows builds of PEB can only use ```QtWebKit``` web engine.
11-
* Updated ``QtWebKit`` have to be manually added from the
12-
[QtWebKit repository of Konstantin Tokarev (annulen)](https://github.com/annulen/webkit/releases) to all Windows GCC-based Qt development bundles version 5.6.x or higher.
7+
PEB Windows binary can be compiled using any MinGW (GCC-based) Qt development bundle version 5.2.x - 5.8.x.
8+
9+
Compiling Windows binaries of PEB is subject to the following restrictions:
10+
11+
* The source code of PEB is not MSVC-compatible and Windows builds of PEB can only be compiled by a MinGW (GCC-based) Qt development bundle.
12+
* Only MSVC-based Qt development bundles version 5.6.x or higher include the ```QtWebEngine``` on the Windows platform and Windows builds of PEB can only use the ```QtWebKit``` web engine.
13+
* Windows MinGW Qt development bundles version 5.6.x - 5.8.x have neither ```QtWebEngine```, nor ```QtWebKit``` and an updated ``QtWebKit`` has to be manually added from the [QtWebKit repository of Konstantin Tokarev (annulen)](https://github.com/annulen/webkit/releases).
14+
* There are no MinGW Qt development bundles for any version 5.9.x or higher.
1315

1416
Compiled and tested successfully using:
15-
* [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
16-
* [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
17-
* [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
18-
* [Qt Creator 3.1.1 and Qt 5.4.1](http://download.qt.io/archive/qt/5.4/5.4.1/) on 64-bit Lubuntu 15.04
19-
* [Qt Creator 3.5.1 and Qt 5.5.1](http://download.qt.io/archive/qt/5.5/5.5.1/) on 64-bit Lubuntu 15.04 and 16.04
20-
* [Qt Creator 4.2.1 and Qt 5.8.0](http://download.qt.io/archive/qt/5.5/5.5.1/) on 64-bit Lubuntu 16.04
17+
* [Qt 5.2.0 and Qt Creator 3.0.0](http://download.qt.io/archive/qt/5.2/5.2.0/) on 32-bit Debian and 32-bit Windows XP
18+
* [Qt 5.2.1 and Qt Creator 3.0.1](http://download.qt.io/archive/qt/5.2/5.2.1/) on 64-bit OS X 10.9.1, i5
19+
* [Qt 5.3.0 and Qt Creator 3.1.1](http://download.qt.io/archive/qt/5.3/5.3.0/) on 64-bit Lubuntu 14.10
20+
* [Qt 5.4.1 and Qt Creator 3.1.1](http://download.qt.io/archive/qt/5.4/5.4.1/) on 64-bit Lubuntu 15.04
21+
* [Qt 5.5.1 and Qt Creator 3.5.1](http://download.qt.io/archive/qt/5.5/5.5.1/) on 64-bit Lubuntu 15.04 and 16.04
22+
* [Qt 5.8.0 and Qt Creator 4.2.1](http://download.qt.io/archive/qt/5.8/5.8.0/) on 64-bit Lubuntu 16.04
23+
* [Qt 5.9.1 and Qt Creator 4.3.1](http://download.qt.io/archive/qt/5.9/5.9.1/) on 64-bit Lubuntu 16.04
2124

2225
To compile PEB type in a terminal started in the ``src`` folder:
2326

@@ -62,11 +65,10 @@ All compile-time settings require editing the ``src/peb.pro`` project file accor
6265
CONFIG += app_bundle
6366
```
6467

65-
## Runtime Requirements
66-
* Qt 5 libraries.
68+
To make automatically a bundled binary (peb.app) use the [dmg-maker.sh](sdk/dmg-maker.sh) script by Valcho Nedelchev.
6769

68-
Their full list for a QtWebKit Linux build of PEB can be found inside the [start-peb-webkit.sh](start-peb-webkit.sh) script.
69-
Their full list for a QtWebEngine Linux build of PEB can be found inside the [start-peb-webengine.sh](start-peb-webengine.sh) script.
70+
## Runtime Requirements
71+
* Qt 5 libraries.
7072

7173
* Perl 5 distribution - any Linux, Mac or Windows Perl standard or relocatable distribution.
7274

SETTINGS.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,14 @@ select_file.receiverFunction = function (file) {
216216
Any new directory will be created immediately by PEB.
217217

218218
## Minimal Portable Perl Distribution for PEB
219-
Sometimes it is important to minimize the size of the relocatable (or portable) Perl distribution used by a PEB-based application. [Perl Distribution Compactor](sdk/compactor.pl) is one solution to this problem. It finds all dependencies of all Perl scripts in the ``{PEB_binary_directory}/resources/app`` directory and copies them in a new ``{PEB_binary_directory}/perl/lib`` folder; a new ``{PEB_binary_directory}/perl/bin`` is also created. The original ``bin`` and ``lib`` folders may be saved as ``bin-original`` and ``lib-original`` respectively.
219+
Sometimes it is important to minimize the size of the relocatable (or portable) Perl distribution used by a PEB-based application. [Perl Distribution Compactor](sdk/compactor.pl) is one solution for this problem. It finds all dependencies of all Perl scripts in the ``{PEB_binary_directory}/resources/app`` directory and copies them in a new ``{PEB_binary_directory}/perl/lib`` folder; a new ``{PEB_binary_directory}/perl/bin`` is also created. The original ``bin`` and ``lib`` folders may be saved as ``bin-original`` and ``lib-original`` respectively.
220220

221-
Perl Distribution Compactor should be started using [compactor.sh](sdk/compactor.sh) on a Linux or a Mac machine or [compactor.cmd](sdk/compactor.cmd) on a Windows machine to ensure that only the Perl distribution of PEB is used. This is necessary to avoid dependency mismatches with any other Perl on PATH.
221+
Perl Distribution Compactor should be started using [compactor.sh](sdk/compactor.sh) on a Linux machine or [compactor.cmd](sdk/compactor.cmd) on a Windows machine to ensure that only the Perl distribution of PEB is used. This is necessary to avoid dependency mismatches with any other Perl on PATH.
222222

223223
Perl Distribution Compactor depends on [Module::ScanDeps](https://metacpan.org/pod/Module::ScanDeps) and [File::Copy::Recursive](https://metacpan.org/pod/File::Copy::Recursive) CPAN modules, which are included in the ``{PEB_binary_directory}/sdk/lib`` folder.
224224

225+
## AppImage Support
226+
Any PEB-based application can be easily packed as a single executable Linux [AppImage](https://appimage.org/) file including the PEB binary, all necessary Qt libraries, relocatable Perl distribution and all application files. This can be easily achieved by the [AppImage Maker](sdk/appimage-maker.sh) script. It finds all dependencies of all Perl scripts in the ``{PEB_binary_directory}/resources/app`` directory and copies only the necessary Perl modules using the [Perl Distribution Compactor](sdk/compactor.pl). All Qt dependencies are detected and the final image is built using a special version of the [linuxdeployqt](https://github.com/probonopd/linuxdeployqt/releases/) binary.
227+
225228
## Log Files
226-
If log files are needed for debugging of PEB or a PEB-based application, they can easily be turned on by manually creating ``{PEB_binary_directory}/logs``. If this directory is found during application startup, the browser assumes that logging is required and a separate log file is created for every browser session following the naming convention: ``{application_name}-started-at-{four_digit_year}-{month}-{day}--{hour}-{minute}-{second}.log``. PEB will not create ``{PEB_binary_directory}/logs`` on its own and if this directory is missing no logs will be written.
229+
If log files are needed for debugging of PEB or a PEB-based application, they can easily be turned on by manually creating ``{PEB_binary_directory}/resources/logs`` or ``{AppImage_binary_directory}/resources/logs`` if a PEB-based application is packed as an [AppImage](https://appimage.org/). If this directory is found during application startup, the browser assumes that logging is required and a separate log file is created for every browser session following the naming convention: ``{application_name}-started-at-{four_digit_year}-{month}-{day}--{hour}-{minute}-{second}.log``. PEB will not create ``{PEB_binary_directory}/logs`` on its own and if this directory is missing, no logs will be written.

resources/app.png

552 Bytes
Loading

resources/app/perl/interactive.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
}
7272
);
7373

74-
my $wait_one_second = AnyEvent->timer (
74+
my $half_second_wait = AnyEvent->timer (
7575
after => 0,
7676
interval => 0.5,
7777
cb => sub {

sdk/appimage-maker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ else
1919
fi
2020

2121
cp ./sdk/peb.desktop ./peb.app/peb.desktop
22-
cp ./src/resources/icon/camel.png ./peb.app/peb.png
22+
cp ./resources/app.png ./peb.app/peb.png
2323

2424
cp -rf ./resources ./peb.app/resources
2525

File renamed without changes.

src/main.cpp

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
https://github.com/ddmitov/perl-executing-browser
1616
*/
1717

18-
#include <QApplication>
18+
#include <QtWidgets/QApplication>
1919
#include <QDateTime>
2020
#include <QDebug>
2121
#include <QTextCodec>
2222
#include <QtGlobal>
23-
#include <QtWidgets>
2423

2524
#include "port-scanner.h"
2625

@@ -173,6 +172,23 @@ int main(int argc, char **argv)
173172
QDir::toNativeSeparators(
174173
browserDirectory + QDir::separator() + "resources");
175174

175+
#ifdef Q_OS_LINUX
176+
QByteArray appImageEnvVariable = qgetenv("APPIMAGE");
177+
QString appImageResourcesDirectory;
178+
179+
if (appImageEnvVariable.length() > 0) {
180+
QFileInfo appImageFileInfo =
181+
QFileInfo(QString::fromLatin1(appImageEnvVariable));
182+
183+
QString appImageDirectory = appImageFileInfo.path();
184+
QString appImageName = appImageFileInfo.baseName();
185+
186+
appImageResourcesDirectory =
187+
appImageDirectory + QDir::separator()
188+
+ appImageName + "-resources";
189+
}
190+
#endif
191+
176192
// ==============================
177193
// Application directory:
178194
// ==============================
@@ -185,12 +201,24 @@ int main(int argc, char **argv)
185201
// ==============================
186202
// Data directory:
187203
// ==============================
188-
QString dataDirName = QDir::toNativeSeparators(
189-
resourcesDirectory + QDir::separator()
190-
+ "data");
191-
QByteArray dataDirNameArray = dataDirName.toLatin1();
204+
QString dataDirName =
205+
QDir::toNativeSeparators(
206+
resourcesDirectory + QDir::separator() + "data");
192207

193-
qputenv("PEB_DATA_DIR", dataDirNameArray);
208+
#ifdef Q_OS_LINUX
209+
if (appImageEnvVariable.length() > 0) {
210+
dataDirName =
211+
appImageResourcesDirectory + QDir::separator() + "data";
212+
213+
QDir dataDir(dataDirName);
214+
215+
if (!dataDir.exists()) {
216+
dataDir.mkpath(dataDirName);
217+
}
218+
}
219+
#endif
220+
221+
qputenv("PEB_DATA_DIR", dataDirName.toLatin1());
194222

195223
// ==============================
196224
// Application icon:
@@ -214,11 +242,20 @@ int main(int argc, char **argv)
214242
// ==============================
215243
// Logging:
216244
// ==============================
217-
// If 'logs' directory is found in the directory of the browser binary,
245+
// If 'logs' directory is found in the resources directory,
218246
// all program messages will be redirected to log files,
219247
// otherwise no log files will be created and
220-
// program messages could be seen inside Qt Creator.
221-
QString logDirFullPath = browserDirectory + QDir::separator() + "logs";
248+
// program messages could be seen inside Qt Creator during development.
249+
250+
QString logDirFullPath = resourcesDirectory + QDir::separator() + "logs";
251+
252+
#ifdef Q_OS_LINUX
253+
if (appImageEnvVariable.length() > 0) {
254+
logDirFullPath =
255+
appImageResourcesDirectory + QDir::separator() + "logs";
256+
}
257+
#endif
258+
222259
QDir logDir(logDirFullPath);
223260
if (logDir.exists()) {
224261
application.setProperty("logDirFullPath", logDirFullPath);

src/peb.pro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ greaterThan (QT_MAJOR_VERSION, 4) {
9393
}
9494

9595
greaterThan (QT_MINOR_VERSION, 5) {
96-
equals (QTWEBKIT, 0) {
96+
equals (ANNULEN_QTWEBKIT, 0) {
9797
QT += widgets webenginewidgets
9898
}
9999

100-
equals (QTWEBKIT, 1) {
100+
equals (ANNULEN_QTWEBKIT, 1) {
101101
QT += widgets webkitwidgets
102102
}
103103
}
@@ -108,7 +108,7 @@ greaterThan (QT_MAJOR_VERSION, 4) {
108108
}
109109

110110
greaterThan (QT_MINOR_VERSION, 5) {
111-
equals (QTWEBKIT, 1) {
111+
equals (ANNULEN_QTWEBKIT, 1) {
112112
QT += printsupport
113113
}
114114
}

src/webengine-main-window.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#ifndef MAINWINDOW_H
1919
#define MAINWINDOW_H
2020

21-
#include <QApplication>
22-
#include <QMainWindow>
21+
#include <QtWidgets/QApplication>
22+
#include <QtWidgets/QMainWindow>
2323
#include <QWebEngineFullScreenRequest>
2424

2525
#include "webengine-view.h"

0 commit comments

Comments
 (0)