Create working Android build

"Working" in this case means it compiles and runs.
android
Loren Burkholder 4 years ago
parent 4af80be02d
commit 9a6f53e8b2
  1. 25
      CMakeLists.txt
  2. 7
      src/Cache.cpp
  3. 16
      src/LoginPage.cpp
  4. 3
      src/LoginPage.h
  5. 5
      src/SSOHandler.cpp
  6. 6
      src/SSOHandler.h
  7. 10
      src/main.cpp
  8. 16
      src/notifications/ManagerAndroid.cpp

@ -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

@ -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;

@ -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();

@ -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)

@ -2,6 +2,9 @@
//
// 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 <QTimer>
@ -55,3 +58,5 @@ SSOHandler::url() const
{
return "http://localhost:" + std::to_string(port) + "/sso";
}
#endif

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

@ -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)

@ -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 <functional>
@ -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 &notification,
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)
}

Loading…
Cancel
Save