diff --git a/app/app.pri b/app/app.pri index 737e3eba34ea71dcc522e3e8a1f466a72023b313..5495172d96673f2b36daadf58ce583280ca3cd8d 100644 --- a/app/app.pri +++ b/app/app.pri @@ -1,10 +1,9 @@ QT += \ core \ + gui \ network \ websockets -QT -= gui - HEADERS += \ $${PWD}/src/websockets/websocketserver.h \ $${PWD}/src/handlers/confighandler.h \ diff --git a/app/src/handlers/systemhandler.cpp b/app/src/handlers/systemhandler.cpp index b7b95ae612ad117f55182713ee9ec9f7b9211a91..2230d8d3c6352e192f27711674b0d04bab382531 100644 --- a/app/src/handlers/systemhandler.cpp +++ b/app/src/handlers/systemhandler.cpp @@ -1,5 +1,8 @@ #include "systemhandler.h" +#include <QUrl> +#include <QDesktopServices> + #ifdef QTLIB_UNIX #include <QFileInfo> #include <QProcess> @@ -9,6 +12,10 @@ #include <QDebug> #endif +#ifdef Q_OS_ANDROID +#include "qtlib_package.h" +#endif + SystemHandler::SystemHandler(QObject *parent) : QObject(parent) {} @@ -21,6 +28,40 @@ bool SystemHandler::isUnix() return false; } +bool SystemHandler::isMobileDevice() +{ +#if defined(APP_MOBILE) + return true; +#elif defined(Q_OS_IOS) || defined(Q_OS_ANDROID) || defined(Q_OS_WINPHONE) + return true; +#elif defined(Q_OS_LINUX) && defined(Q_PROCESSOR_ARM) // Ubuntu Phone, Plasma Phone + return true; +#endif + return false; +} + +bool SystemHandler::openUrl(const QString &url) +{ + QString path = url; + path.replace("file://localhost", "", Qt::CaseInsensitive); + path.replace("file://", "", Qt::CaseInsensitive); + +#ifdef QTLIB_UNIX + if ((path.endsWith(".appimage", Qt::CaseInsensitive) || path.endsWith(".exe", Qt::CaseInsensitive)) + && QFileInfo(path).isExecutable()) { + return QProcess::startDetached(path); + } +#endif + +#ifdef Q_OS_ANDROID + if (path.endsWith(".apk", Qt::CaseInsensitive)) { + return qtlib::Package(path).installAsApk(); + } +#endif + + return QDesktopServices::openUrl(QUrl(url)); +} + QString SystemHandler::desktopEnvironment() { QString desktop = "unknown"; diff --git a/app/src/handlers/systemhandler.h b/app/src/handlers/systemhandler.h index a49f9a6a6b7a1aff0ee9e9036eea2a40a8e625cd..f291c8a89551809a8c0c0ab1d573906ff62405e0 100644 --- a/app/src/handlers/systemhandler.h +++ b/app/src/handlers/systemhandler.h @@ -11,6 +11,8 @@ public: public slots: bool isUnix(); + bool isMobileDevice(); + bool openUrl(const QString &url); QString desktopEnvironment(); bool isApplicableType(const QString &installType); diff --git a/ocs-manager.pro b/ocs-manager.pro index f1df8facfdf0c4aa4a68db2cf30d7e1ae4d708f7..c2e4aab786f32cdfeb4ffd09e330802f5f633ee6 100644 --- a/ocs-manager.pro +++ b/ocs-manager.pro @@ -1,5 +1,11 @@ message("Please execute scripts/import.sh for build dependencies") +ios|android|!isEmpty(APP_MOBILE) { + DEFINES += APP_MOBILE +} else { + DEFINES += APP_DESKTOP +} + TARGET = ocs-manager TEMPLATE = app