AndroidController reimpl
This commit is contained in:
parent
0291ba8cb5
commit
67d413956d
38 changed files with 955 additions and 417 deletions
124
client/ui/notificationhandler.cpp
Normal file
124
client/ui/notificationhandler.cpp
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include <QDebug>
|
||||
#include "notificationhandler.h"
|
||||
|
||||
#if defined(Q_OS_IOS)
|
||||
# include "platforms/ios/iosnotificationhandler.h"
|
||||
#elif defined(Q_OS_ANDROID)
|
||||
# include "platforms/android/android_notificationhandler.h"
|
||||
#else
|
||||
|
||||
# if defined(Q_OS_LINUX)
|
||||
# include "platforms/linux/linuxsystemtraynotificationhandler.h"
|
||||
# endif
|
||||
|
||||
# include "systemtraynotificationhandler.h"
|
||||
#endif
|
||||
|
||||
// static
|
||||
NotificationHandler* NotificationHandler::create(QObject* parent) {
|
||||
#if defined(Q_OS_IOS)
|
||||
return new IOSNotificationHandler(parent);
|
||||
#elif defined(Q_OS_ANDROID)
|
||||
return new AndroidNotificationHandler(parent);
|
||||
#else
|
||||
|
||||
# if defined(Q_OS_LINUX)
|
||||
if (LinuxSystemTrayNotificationHandler::requiredCustomImpl()) {
|
||||
return new LinuxSystemTrayNotificationHandler(parent);
|
||||
}
|
||||
# endif
|
||||
|
||||
return new SystemTrayNotificationHandler(parent);
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace {
|
||||
NotificationHandler* s_instance = nullptr;
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
NotificationHandler* NotificationHandler::instance() {
|
||||
Q_ASSERT(s_instance);
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
NotificationHandler::NotificationHandler(QObject* parent) : QObject(parent) {
|
||||
Q_ASSERT(!s_instance);
|
||||
s_instance = this;
|
||||
}
|
||||
|
||||
NotificationHandler::~NotificationHandler() {
|
||||
Q_ASSERT(s_instance == this);
|
||||
s_instance = nullptr;
|
||||
}
|
||||
|
||||
void NotificationHandler::showVpnStateNotification(VpnProtocol::ConnectionState state)
|
||||
{
|
||||
if (state != VpnProtocol::Connected && state != VpnProtocol::Disconnected) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString title;
|
||||
QString message;
|
||||
|
||||
switch (state) {
|
||||
case VpnProtocol::ConnectionState::Connected:
|
||||
m_connected = true;
|
||||
|
||||
title = tr("AmneziaVPN");
|
||||
message = tr("VPN Connected");
|
||||
break;
|
||||
|
||||
case VpnProtocol::ConnectionState::Disconnected:
|
||||
if (m_connected) {
|
||||
m_connected = false;
|
||||
title = tr("AmneziaVPN");
|
||||
message = tr("VPN Disconnected");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Q_ASSERT(title.isEmpty() == message.isEmpty());
|
||||
|
||||
if (!title.isEmpty()) {
|
||||
notifyInternal(VpnState, title, message, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationHandler::unsecuredNetworkNotification(const QString& networkName) {
|
||||
qDebug() << "Unsecured network notification shown";
|
||||
|
||||
|
||||
QString title = tr("AmneziaVPN notification");
|
||||
QString message = tr("Unsucured network detected: ") + networkName;
|
||||
|
||||
notifyInternal(UnsecuredNetwork, title, message, 2000);
|
||||
}
|
||||
|
||||
void NotificationHandler::notifyInternal(Message type, const QString& title,
|
||||
const QString& message,
|
||||
int timerMsec) {
|
||||
m_lastMessage = type;
|
||||
|
||||
emit notificationShown(title, message);
|
||||
notify(type, title, message, timerMsec);
|
||||
}
|
||||
|
||||
void NotificationHandler::messageClickHandle() {
|
||||
qDebug() << "Message clicked";
|
||||
|
||||
if (m_lastMessage == VpnState) {
|
||||
qCritical() << "Random message clicked received";
|
||||
return;
|
||||
}
|
||||
|
||||
emit notificationClicked(m_lastMessage);
|
||||
m_lastMessage = VpnState;
|
||||
}
|
||||
61
client/ui/notificationhandler.h
Normal file
61
client/ui/notificationhandler.h
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef NOTIFICATIONHANDLER_H
|
||||
#define NOTIFICATIONHANDLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include "protocols/vpnprotocol.h"
|
||||
|
||||
class QMenu;
|
||||
|
||||
class NotificationHandler : public QObject {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY_MOVE(NotificationHandler)
|
||||
|
||||
public:
|
||||
enum Message {
|
||||
VpnState,
|
||||
UnsecuredNetwork
|
||||
};
|
||||
|
||||
static NotificationHandler* create(QObject* parent);
|
||||
|
||||
static NotificationHandler* instance();
|
||||
|
||||
virtual ~NotificationHandler();
|
||||
|
||||
void unsecuredNetworkNotification(const QString& networkName);
|
||||
|
||||
void messageClickHandle();
|
||||
|
||||
public slots:
|
||||
void showVpnStateNotification(VpnProtocol::ConnectionState state);
|
||||
|
||||
signals:
|
||||
void notificationShown(const QString& title, const QString& message);
|
||||
|
||||
void notificationClicked(Message message);
|
||||
|
||||
protected:
|
||||
explicit NotificationHandler(QObject* parent);
|
||||
|
||||
virtual void notify(Message type, const QString& title,
|
||||
const QString& message, int timerMsec) = 0;
|
||||
|
||||
private:
|
||||
virtual void notifyInternal(Message type, const QString& title,
|
||||
const QString& message, int timerMsec);
|
||||
|
||||
protected:
|
||||
Message m_lastMessage = VpnState;
|
||||
|
||||
private:
|
||||
|
||||
// We want to show a 'disconnected' notification only if we were actually
|
||||
// connected.
|
||||
bool m_connected = false;
|
||||
};
|
||||
|
||||
#endif // NOTIFICATIONHANDLER_H
|
||||
127
client/ui/systemtray_notificationhandler.cpp
Normal file
127
client/ui/systemtray_notificationhandler.cpp
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include <QDebug>
|
||||
#include "systemtray_notificationhandler.h"
|
||||
|
||||
|
||||
#ifdef MVPN_MACOS
|
||||
# include "platforms/macos/macosutils.h"
|
||||
#endif
|
||||
|
||||
#include <QIcon>
|
||||
#include <QWindow>
|
||||
|
||||
|
||||
SystemTrayNotificationHandler::SystemTrayNotificationHandler(QObject* parent)
|
||||
: NotificationHandler(parent) {
|
||||
|
||||
// MozillaVPN* vpn = MozillaVPN::instance();
|
||||
// Q_ASSERT(vpn);
|
||||
|
||||
// connect(vpn, &MozillaVPN::stateChanged, this,
|
||||
// &SystemTrayNotificationHandler::updateContextMenu);
|
||||
|
||||
// connect(vpn->currentServer(), &ServerData::changed, this,
|
||||
// &SystemTrayNotificationHandler::updateContextMenu);
|
||||
|
||||
// connect(vpn->controller(), &Controller::stateChanged, this,
|
||||
// &SystemTrayNotificationHandler::updateContextMenu);
|
||||
|
||||
// connect(vpn->statusIcon(), &StatusIcon::iconChanged, this,
|
||||
// &SystemTrayNotificationHandler::updateIcon);
|
||||
|
||||
// m_systemTrayIcon.setToolTip(qtTrId("vpn.main.productName"));
|
||||
|
||||
// // Status label
|
||||
// m_statusLabel = m_menu.addAction("");
|
||||
// m_statusLabel->setEnabled(false);
|
||||
|
||||
// m_lastLocationLabel =
|
||||
// m_menu.addAction("", vpn->controller(), &Controller::activate);
|
||||
// m_lastLocationLabel->setEnabled(false);
|
||||
|
||||
// m_disconnectAction =
|
||||
// m_menu.addAction("", vpn->controller(), &Controller::deactivate);
|
||||
|
||||
// m_separator = m_menu.addSeparator();
|
||||
|
||||
// m_showHideLabel = m_menu.addAction(
|
||||
// "", this, &SystemTrayNotificationHandler::showHideWindow);
|
||||
|
||||
// m_menu.addSeparator();
|
||||
|
||||
// m_helpMenu = m_menu.addMenu("");
|
||||
|
||||
// m_preferencesAction = m_menu.addAction("", vpn, &MozillaVPN::requestSettings);
|
||||
|
||||
// m_menu.addSeparator();
|
||||
|
||||
// m_quitAction = m_menu.addAction("", vpn->controller(), &Controller::quit);
|
||||
// m_systemTrayIcon.setContextMenu(&m_menu);
|
||||
|
||||
// updateIcon(vpn->statusIcon()->iconString());
|
||||
|
||||
// connect(QmlEngineHolder::instance()->window(), &QWindow::visibleChanged, this,
|
||||
// &SystemTrayNotificationHandler::updateContextMenu);
|
||||
|
||||
// connect(&m_systemTrayIcon, &QSystemTrayIcon::activated, this,
|
||||
// &SystemTrayNotificationHandler::maybeActivated);
|
||||
|
||||
// connect(&m_systemTrayIcon, &QSystemTrayIcon::messageClicked, this,
|
||||
// &SystemTrayNotificationHandler::messageClickHandle);
|
||||
|
||||
// retranslate();
|
||||
|
||||
// m_systemTrayIcon.show();
|
||||
}
|
||||
|
||||
SystemTrayNotificationHandler::~SystemTrayNotificationHandler() {
|
||||
}
|
||||
|
||||
void SystemTrayNotificationHandler::notify(NotificationHandler::Message type,
|
||||
const QString& title,
|
||||
const QString& message,
|
||||
int timerMsec) {
|
||||
Q_UNUSED(type);
|
||||
|
||||
// QIcon icon(Constants::LOGO_URL);
|
||||
// m_systemTrayIcon.showMessage(title, message, icon, timerMsec);
|
||||
}
|
||||
|
||||
void SystemTrayNotificationHandler::updateIcon(const QString& icon) {
|
||||
QIcon trayIconMask(icon);
|
||||
trayIconMask.setIsMask(true);
|
||||
m_systemTrayIcon.setIcon(trayIconMask);
|
||||
}
|
||||
|
||||
void SystemTrayNotificationHandler::showHideWindow() {
|
||||
// QmlEngineHolder* engine = QmlEngineHolder::instance();
|
||||
// if (engine->window()->isVisible()) {
|
||||
// engine->hideWindow();
|
||||
//#ifdef MVPN_MACOS
|
||||
// MacOSUtils::hideDockIcon();
|
||||
//#endif
|
||||
// } else {
|
||||
// engine->showWindow();
|
||||
//#ifdef MVPN_MACOS
|
||||
// MacOSUtils::showDockIcon();
|
||||
//#endif
|
||||
// }
|
||||
}
|
||||
|
||||
void SystemTrayNotificationHandler::maybeActivated(
|
||||
QSystemTrayIcon::ActivationReason reason) {
|
||||
qDebug() << "Activated";
|
||||
|
||||
#if defined(MVPN_WINDOWS) || defined(MVPN_LINUX)
|
||||
if (reason == QSystemTrayIcon::DoubleClick ||
|
||||
reason == QSystemTrayIcon::Trigger) {
|
||||
QmlEngineHolder* engine = QmlEngineHolder::instance();
|
||||
engine->showWindow();
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(reason);
|
||||
#endif
|
||||
}
|
||||
45
client/ui/systemtray_notificationhandler.h
Normal file
45
client/ui/systemtray_notificationhandler.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef SYSTEMTRAY_NOTIFICATIONHANDLER_H
|
||||
#define SYSTEMTRAY_NOTIFICATIONHANDLER_H
|
||||
|
||||
#include "notificationhandler.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
class SystemTrayNotificationHandler : public NotificationHandler {
|
||||
public:
|
||||
explicit SystemTrayNotificationHandler(QObject* parent);
|
||||
~SystemTrayNotificationHandler();
|
||||
|
||||
protected:
|
||||
virtual void notify(Message type, const QString& title,
|
||||
const QString& message, int timerMsec) override;
|
||||
|
||||
private:
|
||||
void updateIcon(const QString& icon);
|
||||
|
||||
void updateContextMenu();
|
||||
|
||||
void showHideWindow();
|
||||
|
||||
void maybeActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
private:
|
||||
QMenu m_menu;
|
||||
QSystemTrayIcon m_systemTrayIcon;
|
||||
|
||||
QAction* m_statusLabel = nullptr;
|
||||
QAction* m_lastLocationLabel = nullptr;
|
||||
QAction* m_disconnectAction = nullptr;
|
||||
QAction* m_separator = nullptr;
|
||||
QAction* m_preferencesAction = nullptr;
|
||||
QAction* m_showHideLabel = nullptr;
|
||||
QAction* m_quitAction = nullptr;
|
||||
QMenu* m_helpMenu = nullptr;
|
||||
};
|
||||
|
||||
#endif // SYSTEMTRAY_NOTIFICATIONHANDLER_H
|
||||
|
|
@ -44,6 +44,10 @@
|
|||
#include "ui/macos_util.h"
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "platforms/android/android_controller.h"
|
||||
#endif
|
||||
|
||||
#include "pages_logic/AppSettingsLogic.h"
|
||||
#include "pages_logic/GeneralSettingsLogic.h"
|
||||
#include "pages_logic/NetworkSettingsLogic.h"
|
||||
|
|
@ -128,9 +132,18 @@ UiLogic::~UiLogic()
|
|||
|
||||
void UiLogic::initalizeUiLogic()
|
||||
{
|
||||
if (!AndroidController::instance()->initialize()) {
|
||||
qDebug() << QString("Init failed") ;
|
||||
emit VpnProtocol::Error;
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "UiLogic::initalizeUiLogic()";
|
||||
setupTray();
|
||||
|
||||
notificationHandler = NotificationHandler::create(this);
|
||||
|
||||
connect(m_vpnConnection, &VpnConnection::connectionStateChanged, notificationHandler, &NotificationHandler::showVpnStateNotification);
|
||||
|
||||
// if (QOperatingSystemVersion::current() <= QOperatingSystemVersion::Windows7) {
|
||||
// needToHideCustomTitlebar = true;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include "models/containers_model.h"
|
||||
#include "models/protocols_model.h"
|
||||
|
||||
#include "notificationhandler.h"
|
||||
#include "settings.h"
|
||||
|
||||
class AppSettingsLogic;
|
||||
|
|
@ -218,6 +219,8 @@ private:
|
|||
QThread m_vpnConnectionThread;
|
||||
Settings m_settings;
|
||||
|
||||
NotificationHandler* notificationHandler;
|
||||
|
||||
|
||||
// QRegExpValidator m_ipAddressValidator;
|
||||
// QRegExpValidator m_ipAddressPortValidator;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue