Create working Android build

"Working" in this case means it compiles and runs.
This commit is contained in:
Loren Burkholder 2021-03-27 22:42:01 -04:00
parent 4af80be02d
commit 9a6f53e8b2
8 changed files with 78 additions and 10 deletions

View file

@ -355,7 +355,6 @@ set(SRC_FILES
src/Olm.cpp src/Olm.cpp
src/ReadReceiptsModel.cpp src/ReadReceiptsModel.cpp
src/RegisterPage.cpp src/RegisterPage.cpp
src/SSOHandler.cpp
src/CombinedImagePackModel.cpp src/CombinedImagePackModel.cpp
src/SingleImagePackModel.cpp src/SingleImagePackModel.cpp
src/ImagePackListModel.cpp src/ImagePackListModel.cpp
@ -372,6 +371,11 @@ set(SRC_FILES
third_party/blurhash/blurhash.cpp 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) include(FeatureSummary)
@ -566,7 +570,6 @@ qt5_wrap_cpp(MOC_HEADERS
src/Olm.h src/Olm.h
src/RegisterPage.h src/RegisterPage.h
src/RoomsModel.h src/RoomsModel.h
src/SSOHandler.h
src/SingleImagePackModel.h src/SingleImagePackModel.h
src/TrayIcon.h src/TrayIcon.h
src/UserSettingsPage.h src/UserSettingsPage.h
@ -578,6 +581,11 @@ qt5_wrap_cpp(MOC_HEADERS
src/ReadReceiptsModel.h src/ReadReceiptsModel.h
) )
# Android currently doesn't support SSO.
if(NOT ANDROID)
qt5_wrap_cpp(MOC_HEADERS src/SSOHandler.h)
endif()
# #
# Bundle translations. # Bundle translations.
# #
@ -603,7 +611,7 @@ elseif (WIN32)
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerWin.cpp src/wintoastlib.cpp) set(SRC_FILES ${SRC_FILES} src/notifications/ManagerWin.cpp src/wintoastlib.cpp)
elseif(ANDROID) 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 () else ()
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerLinux.cpp) set(SRC_FILES ${SRC_FILES} src/notifications/ManagerLinux.cpp)
endif () endif ()
@ -641,7 +649,7 @@ elseif(WIN32)
target_compile_options(nheko PUBLIC "/Zc:__cplusplus") target_compile_options(nheko PUBLIC "/Zc:__cplusplus")
endif() endif()
elseif(ANDROID) elseif(ANDROID)
# link with nothing at all # link with nothing extra at all
else() else()
target_link_libraries (nheko PRIVATE Qt5::DBus) target_link_libraries (nheko PRIVATE Qt5::DBus)
endif() endif()
@ -666,8 +674,11 @@ target_link_libraries(nheko PRIVATE
qt5keychain qt5keychain
nlohmann_json::nlohmann_json nlohmann_json::nlohmann_json
lmdbxx::lmdbxx lmdbxx::lmdbxx
liblmdb::lmdb liblmdb::lmdb)
SingleApplication::SingleApplication)
if(NOT ANDROID)
target_link_libraries(nheko PRIVATE SingleApplication::SingleApplication)
endif()
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0") if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
target_precompile_headers(nheko target_precompile_headers(nheko

View file

@ -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 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 MAX_DBS = 32384UL;
constexpr auto BATCH_SIZE = 100; constexpr auto BATCH_SIZE = 100;

View file

@ -18,7 +18,6 @@
#include "Logging.h" #include "Logging.h"
#include "LoginPage.h" #include "LoginPage.h"
#include "MatrixClient.h" #include "MatrixClient.h"
#include "SSOHandler.h"
#include "UserSettingsPage.h" #include "UserSettingsPage.h"
#include "ui/FlatButton.h" #include "ui/FlatButton.h"
#include "ui/LoadingIndicator.h" #include "ui/LoadingIndicator.h"
@ -26,6 +25,10 @@
#include "ui/RaisedButton.h" #include "ui/RaisedButton.h"
#include "ui/TextField.h" #include "ui/TextField.h"
#ifndef Q_OS_ANDROID
#include "SSOHandler.h"
#endif
Q_DECLARE_METATYPE(LoginPage::LoginMethod) Q_DECLARE_METATYPE(LoginPage::LoginMethod)
using namespace mtx::identifiers; using namespace mtx::identifiers;
@ -144,15 +147,19 @@ LoginPage::LoginPage(QWidget *parent)
login_button_->setFontSize(20); login_button_->setFontSize(20);
login_button_->setCornerRadius(3); login_button_->setCornerRadius(3);
#ifndef Q_OS_ANDROID
sso_login_button_ = new RaisedButton(tr("SSO LOGIN"), this); sso_login_button_ = new RaisedButton(tr("SSO LOGIN"), this);
sso_login_button_->setMinimumSize(150, 65); sso_login_button_->setMinimumSize(150, 65);
sso_login_button_->setFontSize(20); sso_login_button_->setFontSize(20);
sso_login_button_->setCornerRadius(3); sso_login_button_->setCornerRadius(3);
sso_login_button_->setVisible(false); sso_login_button_->setVisible(false);
#endif
button_layout_->addStretch(1); button_layout_->addStretch(1);
button_layout_->addWidget(login_button_); button_layout_->addWidget(login_button_);
#ifndef Q_OS_ANDROID
button_layout_->addWidget(sso_login_button_); button_layout_->addWidget(sso_login_button_);
#endif
button_layout_->addStretch(1); button_layout_->addStretch(1);
error_label_ = new QLabel(this); error_label_ = new QLabel(this);
@ -178,9 +185,12 @@ LoginPage::LoginPage(QWidget *parent)
connect(login_button_, &RaisedButton::clicked, this, [this]() { connect(login_button_, &RaisedButton::clicked, this, [this]() {
onLoginButtonClicked(passwordSupported ? LoginMethod::Password : LoginMethod::SSO); onLoginButtonClicked(passwordSupported ? LoginMethod::Password : LoginMethod::SSO);
}); });
#ifndef Q_OS_ANDROID
connect(sso_login_button_, &RaisedButton::clicked, this, [this]() { connect(sso_login_button_, &RaisedButton::clicked, this, [this]() {
onLoginButtonClicked(LoginMethod::SSO); onLoginButtonClicked(LoginMethod::SSO);
}); });
#endif
connect(this, connect(this,
&LoginPage::showErrorMessage, &LoginPage::showErrorMessage,
this, this,
@ -375,7 +385,9 @@ LoginPage::versionOk(bool passwordSupported_, bool ssoSupported_)
matrixidLayout_->removeWidget(spinner_); matrixidLayout_->removeWidget(spinner_);
spinner_->stop(); spinner_->stop();
#ifndef Q_OS_ANDROID
sso_login_button_->setVisible(ssoSupported); sso_login_button_->setVisible(ssoSupported);
#endif
login_button_->setVisible(passwordSupported); login_button_->setVisible(passwordSupported);
if (serverInput_->isVisible()) if (serverInput_->isVisible())
@ -435,6 +447,7 @@ LoginPage::onLoginButtonClicked(LoginMethod loginMethod)
emit loginOk(res); emit loginOk(res);
}); });
} else { } else {
#ifndef Q_OS_ANDROID
auto sso = new SSOHandler(); auto sso = new SSOHandler();
connect(sso, &SSOHandler::ssoSuccess, this, [this, sso](std::string token) { connect(sso, &SSOHandler::ssoSuccess, this, [this, sso](std::string token) {
mtx::requests::Login req{}; mtx::requests::Login req{};
@ -472,6 +485,7 @@ LoginPage::onLoginButtonClicked(LoginMethod loginMethod)
QDesktopServices::openUrl( QDesktopServices::openUrl(
QString::fromStdString(http::client()->login_sso_redirect(sso->url()))); QString::fromStdString(http::client()->login_sso_redirect(sso->url())));
#endif
} }
emit loggingIn(); emit loggingIn();

View file

@ -81,6 +81,9 @@ private:
{ {
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
return "Nheko on macOS"; 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) #elif defined(Q_OS_LINUX)
return "Nheko on Linux"; return "Nheko on Linux";
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)

View file

@ -2,6 +2,9 @@
// //
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
#include <Qt> // for platform definitions
#ifndef Q_OS_ANDROID // sso is currently not supported for Android
#include "SSOHandler.h" #include "SSOHandler.h"
#include <QTimer> #include <QTimer>
@ -55,3 +58,5 @@ SSOHandler::url() const
{ {
return "http://localhost:" + std::to_string(port) + "/sso"; return "http://localhost:" + std::to_string(port) + "/sso";
} }
#endif

View file

@ -2,6 +2,11 @@
// //
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <Qt> // for OS defines
#ifndef Q_OS_ANDROID
#include "httplib.h" #include "httplib.h"
#include <QObject> #include <QObject>
@ -26,3 +31,4 @@ private:
httplib::Server svr; httplib::Server svr;
int port = 0; int port = 0;
}; };
#endif

View file

@ -28,7 +28,10 @@
#include "MatrixClient.h" #include "MatrixClient.h"
#include "Utils.h" #include "Utils.h"
#include "config/nheko.h" #include "config/nheko.h"
#ifndef Q_OS_ANDROID
#include "singleapplication.h" #include "singleapplication.h"
#endif
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
#include "emoji/MacHelper.h" #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, SingleApplication app(argc,
argv, argv,
true, true,
@ -183,6 +189,7 @@ main(int argc, char *argv[])
app.sendMessage(matrixUri.toUtf8()); app.sendMessage(matrixUri.toUtf8());
return 0; return 0;
} }
#endif
QCommandLineParser parser; QCommandLineParser parser;
parser.addHelpOption(); parser.addHelpOption();
@ -268,6 +275,8 @@ main(int argc, char *argv[])
nhlog::net()->debug("bye"); nhlog::net()->debug("bye");
} }
}); });
#ifndef Q_OS_ANDROID
QObject::connect(&app, &SingleApplication::instanceStarted, &w, [&w]() { QObject::connect(&app, &SingleApplication::instanceStarted, &w, [&w]() {
w.show(); w.show();
w.raise(); w.raise();
@ -291,6 +300,7 @@ main(int argc, char *argv[])
QObject::disconnect(uriConnection); QObject::disconnect(uriConnection);
}); });
} }
#endif
QDesktopServices::setUrlHandler("matrix", ChatPage::instance(), "handleMatrixUri"); QDesktopServices::setUrlHandler("matrix", ChatPage::instance(), "handleMatrixUri");
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)

View file

@ -3,6 +3,9 @@
// //
// SPDX-License-Identifier: GPL-3.0-or-later // 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 "notifications/Manager.h"
#include <functional> #include <functional>
@ -12,37 +15,48 @@
#include "Cache.h" #include "Cache.h"
#include "EventAccessors.h" #include "EventAccessors.h"
#include "Logging.h"
#include "MxcImageProvider.h" #include "MxcImageProvider.h"
#include "Utils.h" #include "Utils.h"
NotificationsManager::NotificationsManager(QObject *parent) NotificationsManager::NotificationsManager(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
nhlog::ui()->warn("Notifications disabled (no Android backend available)");
} }
void void
NotificationsManager::postNotification(const mtx::responses::Notification &notification, NotificationsManager::postNotification(const mtx::responses::Notification &notification,
const QImage &icon) const QImage &icon)
{ {
Q_UNUSED(notification)
Q_UNUSED(icon)
} }
void void
NotificationsManager::removeNotification(const QString &roomId, const QString &eventId) NotificationsManager::removeNotification(const QString &roomId, const QString &eventId)
{ {
Q_UNUSED(roomId)
Q_UNUSED(eventId)
} }
void void
NotificationsManager::actionInvoked(uint id, QString action) NotificationsManager::actionInvoked(uint id, QString action)
{ {
Q_UNUSED(id)
Q_UNUSED(action)
} }
void void
NotificationsManager::notificationReplied(uint id, QString reply) NotificationsManager::notificationReplied(uint id, QString reply)
{ {
Q_UNUSED(id)
Q_UNUSED(reply)
} }
void void
NotificationsManager::notificationClosed(uint id, uint reason) NotificationsManager::notificationClosed(uint id, uint reason)
{ {
Q_UNUSED(id)
Q_UNUSED(reason)
} }