diff --git a/CMakeLists.txt b/CMakeLists.txt index 9524e703..70491220 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -330,7 +330,7 @@ set(SRC_FILES src/ui/ToggleButton.cpp src/ui/UserProfile.cpp - # Generic notification stuff + # Generic notification stuff src/notifications/Manager.cpp src/AvatarProvider.cpp @@ -355,7 +355,6 @@ set(SRC_FILES src/Olm.cpp src/ReadReceiptsModel.cpp src/RegisterPage.cpp - src/SSOHandler.cpp src/CombinedImagePackModel.cpp src/SingleImagePackModel.cpp src/ImagePackListModel.cpp @@ -372,6 +371,11 @@ set(SRC_FILES third_party/blurhash/blurhash.cpp ) +# Android currently doesn't support SSO. +if(NOT ANDROID) + set(SRC_FILES ${SRC_FILES} src/SSOHandler.cpp) +endif() + include(FeatureSummary) @@ -566,7 +570,6 @@ qt5_wrap_cpp(MOC_HEADERS src/Olm.h src/RegisterPage.h src/RoomsModel.h - src/SSOHandler.h src/SingleImagePackModel.h src/TrayIcon.h src/UserSettingsPage.h @@ -578,6 +581,11 @@ qt5_wrap_cpp(MOC_HEADERS src/ReadReceiptsModel.h ) +# Android currently doesn't support SSO. +if(NOT ANDROID) + qt5_wrap_cpp(MOC_HEADERS src/SSOHandler.h) +endif() + # # Bundle translations. # @@ -603,7 +611,7 @@ elseif (WIN32) set(SRC_FILES ${SRC_FILES} src/notifications/ManagerWin.cpp src/wintoastlib.cpp) elseif(ANDROID) - #set(SRC_FILES ${SRC_FILES} src/notifications/ManagerAndroid.cpp) # does nothing ATM + set(SRC_FILES ${SRC_FILES} src/notifications/ManagerAndroid.cpp) # does nothing ATM else () set(SRC_FILES ${SRC_FILES} src/notifications/ManagerLinux.cpp) endif () @@ -641,7 +649,7 @@ elseif(WIN32) target_compile_options(nheko PUBLIC "/Zc:__cplusplus") endif() elseif(ANDROID) - # link with nothing at all + # link with nothing extra at all else() target_link_libraries (nheko PRIVATE Qt5::DBus) endif() @@ -666,8 +674,11 @@ target_link_libraries(nheko PRIVATE qt5keychain nlohmann_json::nlohmann_json lmdbxx::lmdbxx - liblmdb::lmdb - SingleApplication::SingleApplication) + liblmdb::lmdb) + +if(NOT ANDROID) + target_link_libraries(nheko PRIVATE SingleApplication::SingleApplication) +endif() if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0") target_precompile_headers(nheko diff --git a/src/Cache.cpp b/src/Cache.cpp index 9ebc61b9..d96ac391 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -46,7 +46,12 @@ static const std::string_view CURRENT_ONLINE_BACKUP_VERSION("current_online_back constexpr size_t MAX_RESTORED_MESSAGES = 30'000; -constexpr auto DB_SIZE = 32ULL * 1024ULL * 1024ULL * 1024ULL; // 32 GB +// Android builds don't like this to be constexpr +#ifndef Q_OS_ANDROID +constexpr +#endif + auto DB_SIZE = 32ULL * 1024ULL * 1024ULL * 1024ULL; // 32 GB + constexpr auto MAX_DBS = 32384UL; constexpr auto BATCH_SIZE = 100; diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp index f53d81ba..20992472 100644 --- a/src/LoginPage.cpp +++ b/src/LoginPage.cpp @@ -18,7 +18,6 @@ #include "Logging.h" #include "LoginPage.h" #include "MatrixClient.h" -#include "SSOHandler.h" #include "UserSettingsPage.h" #include "ui/FlatButton.h" #include "ui/LoadingIndicator.h" @@ -26,6 +25,10 @@ #include "ui/RaisedButton.h" #include "ui/TextField.h" +#ifndef Q_OS_ANDROID +#include "SSOHandler.h" +#endif + Q_DECLARE_METATYPE(LoginPage::LoginMethod) using namespace mtx::identifiers; @@ -144,15 +147,19 @@ LoginPage::LoginPage(QWidget *parent) login_button_->setFontSize(20); login_button_->setCornerRadius(3); +#ifndef Q_OS_ANDROID sso_login_button_ = new RaisedButton(tr("SSO LOGIN"), this); sso_login_button_->setMinimumSize(150, 65); sso_login_button_->setFontSize(20); sso_login_button_->setCornerRadius(3); sso_login_button_->setVisible(false); +#endif button_layout_->addStretch(1); button_layout_->addWidget(login_button_); +#ifndef Q_OS_ANDROID button_layout_->addWidget(sso_login_button_); +#endif button_layout_->addStretch(1); error_label_ = new QLabel(this); @@ -178,9 +185,12 @@ LoginPage::LoginPage(QWidget *parent) connect(login_button_, &RaisedButton::clicked, this, [this]() { onLoginButtonClicked(passwordSupported ? LoginMethod::Password : LoginMethod::SSO); }); + +#ifndef Q_OS_ANDROID connect(sso_login_button_, &RaisedButton::clicked, this, [this]() { onLoginButtonClicked(LoginMethod::SSO); }); +#endif connect(this, &LoginPage::showErrorMessage, this, @@ -375,7 +385,9 @@ LoginPage::versionOk(bool passwordSupported_, bool ssoSupported_) matrixidLayout_->removeWidget(spinner_); spinner_->stop(); +#ifndef Q_OS_ANDROID sso_login_button_->setVisible(ssoSupported); +#endif login_button_->setVisible(passwordSupported); if (serverInput_->isVisible()) @@ -435,6 +447,7 @@ LoginPage::onLoginButtonClicked(LoginMethod loginMethod) emit loginOk(res); }); } else { +#ifndef Q_OS_ANDROID auto sso = new SSOHandler(); connect(sso, &SSOHandler::ssoSuccess, this, [this, sso](std::string token) { mtx::requests::Login req{}; @@ -472,6 +485,7 @@ LoginPage::onLoginButtonClicked(LoginMethod loginMethod) QDesktopServices::openUrl( QString::fromStdString(http::client()->login_sso_redirect(sso->url()))); +#endif } emit loggingIn(); diff --git a/src/LoginPage.h b/src/LoginPage.h index 2e1eb9b9..61ae38a7 100644 --- a/src/LoginPage.h +++ b/src/LoginPage.h @@ -81,6 +81,9 @@ private: { #if defined(Q_OS_MAC) return "Nheko on macOS"; +// Android is before Linux because it is also detected as Linux +#elif defined(Q_OS_ANDROID) + return "Nheko on Android"; #elif defined(Q_OS_LINUX) return "Nheko on Linux"; #elif defined(Q_OS_WIN) diff --git a/src/SSOHandler.cpp b/src/SSOHandler.cpp index 8fd0828c..dfd1b524 100644 --- a/src/SSOHandler.cpp +++ b/src/SSOHandler.cpp @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: GPL-3.0-or-later +#include // for platform definitions + +#ifndef Q_OS_ANDROID // sso is currently not supported for Android #include "SSOHandler.h" #include @@ -55,3 +58,5 @@ SSOHandler::url() const { return "http://localhost:" + std::to_string(port) + "/sso"; } + +#endif diff --git a/src/SSOHandler.h b/src/SSOHandler.h index bd0d424d..01835c92 100644 --- a/src/SSOHandler.h +++ b/src/SSOHandler.h @@ -2,6 +2,11 @@ // // SPDX-License-Identifier: GPL-3.0-or-later +#pragma once + +#include // for OS defines + +#ifndef Q_OS_ANDROID #include "httplib.h" #include @@ -26,3 +31,4 @@ private: httplib::Server svr; int port = 0; }; +#endif diff --git a/src/main.cpp b/src/main.cpp index 09168e0c..c6d085c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,7 +28,10 @@ #include "MatrixClient.h" #include "Utils.h" #include "config/nheko.h" + +#ifndef Q_OS_ANDROID #include "singleapplication.h" +#endif #if defined(Q_OS_MAC) #include "emoji/MacHelper.h" @@ -168,6 +171,9 @@ main(int argc, char *argv[]) } } +#ifdef Q_OS_ANDROID + QApplication app(argc, argv); +#else SingleApplication app(argc, argv, true, @@ -183,6 +189,7 @@ main(int argc, char *argv[]) app.sendMessage(matrixUri.toUtf8()); return 0; } +#endif QCommandLineParser parser; parser.addHelpOption(); @@ -268,6 +275,8 @@ main(int argc, char *argv[]) nhlog::net()->debug("bye"); } }); + +#ifndef Q_OS_ANDROID QObject::connect(&app, &SingleApplication::instanceStarted, &w, [&w]() { w.show(); w.raise(); @@ -291,6 +300,7 @@ main(int argc, char *argv[]) QObject::disconnect(uriConnection); }); } +#endif QDesktopServices::setUrlHandler("matrix", ChatPage::instance(), "handleMatrixUri"); #if defined(Q_OS_MAC) diff --git a/src/notifications/ManagerAndroid.cpp b/src/notifications/ManagerAndroid.cpp index cc942a12..67f7e6f4 100644 --- a/src/notifications/ManagerAndroid.cpp +++ b/src/notifications/ManagerAndroid.cpp @@ -3,6 +3,9 @@ // // SPDX-License-Identifier: GPL-3.0-or-later +// This is a dummy file because there is currently no working backend for Android notifications. +// This is simply provided so that Android builds will compile. + #include "notifications/Manager.h" #include @@ -12,37 +15,48 @@ #include "Cache.h" #include "EventAccessors.h" +#include "Logging.h" #include "MxcImageProvider.h" #include "Utils.h" NotificationsManager::NotificationsManager(QObject *parent) : QObject(parent) { + nhlog::ui()->warn("Notifications disabled (no Android backend available)"); } void NotificationsManager::postNotification(const mtx::responses::Notification ¬ification, const QImage &icon) { + Q_UNUSED(notification) + Q_UNUSED(icon) } void NotificationsManager::removeNotification(const QString &roomId, const QString &eventId) { + Q_UNUSED(roomId) + Q_UNUSED(eventId) } void NotificationsManager::actionInvoked(uint id, QString action) { + Q_UNUSED(id) + Q_UNUSED(action) } void NotificationsManager::notificationReplied(uint id, QString reply) { + Q_UNUSED(id) + Q_UNUSED(reply) } void NotificationsManager::notificationClosed(uint id, uint reason) { + Q_UNUSED(id) + Q_UNUSED(reason) } -