NotificationHandler systemtray
This commit is contained in:
parent
67d413956d
commit
d28a2ebc57
9 changed files with 211 additions and 216 deletions
|
@ -64,7 +64,6 @@ HEADERS += \
|
|||
ui/pages_logic/protocols/ShadowSocksLogic.h \
|
||||
ui/property_helper.h \
|
||||
ui/models/servers_model.h \
|
||||
ui/systemtray_notificationhandler.h \
|
||||
ui/uilogic.h \
|
||||
ui/qautostart.h \
|
||||
ui/models/sites_model.h \
|
||||
|
@ -115,7 +114,6 @@ SOURCES += \
|
|||
ui/pages_logic/protocols/PageProtocolLogicBase.cpp \
|
||||
ui/pages_logic/protocols/ShadowSocksLogic.cpp \
|
||||
ui/models/servers_model.cpp \
|
||||
ui/systemtray_notificationhandler.cpp \
|
||||
ui/uilogic.cpp \
|
||||
ui/qautostart.cpp \
|
||||
ui/models/sites_model.cpp \
|
||||
|
@ -184,6 +182,7 @@ linux:!android {
|
|||
win32|macx|linux:!android {
|
||||
|
||||
HEADERS += \
|
||||
ui/systemtray_notificationhandler.h \
|
||||
protocols/openvpnprotocol.h \
|
||||
protocols/ikev2_vpn_protocol.h \
|
||||
protocols/openvpnovercloakprotocol.h \
|
||||
|
@ -191,6 +190,7 @@ win32|macx|linux:!android {
|
|||
protocols/wireguardprotocol.h \
|
||||
|
||||
SOURCES += \
|
||||
ui/systemtray_notificationhandler.cpp \
|
||||
protocols/openvpnprotocol.cpp \
|
||||
protocols/ikev2_vpn_protocol.cpp \
|
||||
protocols/openvpnovercloakprotocol.cpp \
|
||||
|
|
|
@ -15,24 +15,24 @@
|
|||
# include "platforms/linux/linuxsystemtraynotificationhandler.h"
|
||||
# endif
|
||||
|
||||
# include "systemtraynotificationhandler.h"
|
||||
# include "systemtray_notificationhandler.h"
|
||||
#endif
|
||||
|
||||
// static
|
||||
NotificationHandler* NotificationHandler::create(QObject* parent) {
|
||||
#if defined(Q_OS_IOS)
|
||||
return new IOSNotificationHandler(parent);
|
||||
return new IOSNotificationHandler(parent);
|
||||
#elif defined(Q_OS_ANDROID)
|
||||
return new AndroidNotificationHandler(parent);
|
||||
return new AndroidNotificationHandler(parent);
|
||||
#else
|
||||
|
||||
# if defined(Q_OS_LINUX)
|
||||
if (LinuxSystemTrayNotificationHandler::requiredCustomImpl()) {
|
||||
return new LinuxSystemTrayNotificationHandler(parent);
|
||||
}
|
||||
if (LinuxSystemTrayNotificationHandler::requiredCustomImpl()) {
|
||||
return new LinuxSystemTrayNotificationHandler(parent);
|
||||
}
|
||||
# endif
|
||||
|
||||
return new SystemTrayNotificationHandler(parent);
|
||||
return new SystemTrayNotificationHandler(parent);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -42,83 +42,83 @@ NotificationHandler* s_instance = nullptr;
|
|||
|
||||
// static
|
||||
NotificationHandler* NotificationHandler::instance() {
|
||||
Q_ASSERT(s_instance);
|
||||
return s_instance;
|
||||
Q_ASSERT(s_instance);
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
NotificationHandler::NotificationHandler(QObject* parent) : QObject(parent) {
|
||||
Q_ASSERT(!s_instance);
|
||||
s_instance = this;
|
||||
Q_ASSERT(!s_instance);
|
||||
s_instance = this;
|
||||
}
|
||||
|
||||
NotificationHandler::~NotificationHandler() {
|
||||
Q_ASSERT(s_instance == this);
|
||||
s_instance = nullptr;
|
||||
Q_ASSERT(s_instance == this);
|
||||
s_instance = nullptr;
|
||||
}
|
||||
|
||||
void NotificationHandler::showVpnStateNotification(VpnProtocol::ConnectionState state)
|
||||
void NotificationHandler::setConnectionState(VpnProtocol::ConnectionState state)
|
||||
{
|
||||
if (state != VpnProtocol::Connected && state != VpnProtocol::Disconnected) {
|
||||
return;
|
||||
}
|
||||
if (state != VpnProtocol::Connected && state != VpnProtocol::Disconnected) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString title;
|
||||
QString message;
|
||||
QString title;
|
||||
QString message;
|
||||
|
||||
switch (state) {
|
||||
switch (state) {
|
||||
case VpnProtocol::ConnectionState::Connected:
|
||||
m_connected = true;
|
||||
m_connected = true;
|
||||
|
||||
title = tr("AmneziaVPN");
|
||||
message = tr("VPN Connected");
|
||||
break;
|
||||
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;
|
||||
if (m_connected) {
|
||||
m_connected = false;
|
||||
title = tr("AmneziaVPN");
|
||||
message = tr("VPN Disconnected");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Q_ASSERT(title.isEmpty() == message.isEmpty());
|
||||
Q_ASSERT(title.isEmpty() == message.isEmpty());
|
||||
|
||||
if (!title.isEmpty()) {
|
||||
notifyInternal(VpnState, title, message, 2000);
|
||||
}
|
||||
if (!title.isEmpty()) {
|
||||
notifyInternal(VpnState, title, message, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationHandler::unsecuredNetworkNotification(const QString& networkName) {
|
||||
qDebug() << "Unsecured network notification shown";
|
||||
qDebug() << "Unsecured network notification shown";
|
||||
|
||||
|
||||
QString title = tr("AmneziaVPN notification");
|
||||
QString message = tr("Unsucured network detected: ") + networkName;
|
||||
QString title = tr("AmneziaVPN notification");
|
||||
QString message = tr("Unsucured network detected: ") + networkName;
|
||||
|
||||
notifyInternal(UnsecuredNetwork, title, message, 2000);
|
||||
notifyInternal(UnsecuredNetwork, title, message, 2000);
|
||||
}
|
||||
|
||||
void NotificationHandler::notifyInternal(Message type, const QString& title,
|
||||
const QString& message,
|
||||
int timerMsec) {
|
||||
m_lastMessage = type;
|
||||
m_lastMessage = type;
|
||||
|
||||
emit notificationShown(title, message);
|
||||
notify(type, title, message, timerMsec);
|
||||
emit notificationShown(title, message);
|
||||
notify(type, title, message, timerMsec);
|
||||
}
|
||||
|
||||
void NotificationHandler::messageClickHandle() {
|
||||
qDebug() << "Message clicked";
|
||||
qDebug() << "Message clicked";
|
||||
|
||||
if (m_lastMessage == VpnState) {
|
||||
qCritical() << "Random message clicked received";
|
||||
return;
|
||||
}
|
||||
if (m_lastMessage == VpnState) {
|
||||
qCritical() << "Random message clicked received";
|
||||
return;
|
||||
}
|
||||
|
||||
emit notificationClicked(m_lastMessage);
|
||||
m_lastMessage = VpnState;
|
||||
emit notificationClicked(m_lastMessage);
|
||||
m_lastMessage = VpnState;
|
||||
}
|
||||
|
|
|
@ -31,13 +31,16 @@ public:
|
|||
void messageClickHandle();
|
||||
|
||||
public slots:
|
||||
void showVpnStateNotification(VpnProtocol::ConnectionState state);
|
||||
virtual void setConnectionState(VpnProtocol::ConnectionState state);
|
||||
|
||||
signals:
|
||||
void notificationShown(const QString& title, const QString& message);
|
||||
|
||||
void notificationClicked(Message message);
|
||||
|
||||
void raiseRequested();
|
||||
void connectRequested();
|
||||
void disconnectRequested();
|
||||
|
||||
protected:
|
||||
explicit NotificationHandler(QObject* parent);
|
||||
|
||||
|
|
|
@ -88,8 +88,6 @@ void VpnLogic::onConnectionStateChanged(VpnProtocol::ConnectionState state)
|
|||
bool pbConnectVisible = false;
|
||||
set_labelStateText(VpnProtocol::textConnectionState(state));
|
||||
|
||||
uiLogic()->setTrayState(state);
|
||||
|
||||
switch (state) {
|
||||
case VpnProtocol::Disconnected:
|
||||
onBytesChanged(0,0);
|
||||
|
|
|
@ -6,53 +6,47 @@
|
|||
#include "systemtray_notificationhandler.h"
|
||||
|
||||
|
||||
#ifdef MVPN_MACOS
|
||||
#ifdef Q_OS_MACOS
|
||||
# include "platforms/macos/macosutils.h"
|
||||
#endif
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopServices>
|
||||
#include <QIcon>
|
||||
#include <QWindow>
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
SystemTrayNotificationHandler::SystemTrayNotificationHandler(QObject* parent)
|
||||
: NotificationHandler(parent) {
|
||||
|
||||
// MozillaVPN* vpn = MozillaVPN::instance();
|
||||
// Q_ASSERT(vpn);
|
||||
SystemTrayNotificationHandler::SystemTrayNotificationHandler(QObject* parent) :
|
||||
NotificationHandler(parent),
|
||||
m_systemTrayIcon(parent)
|
||||
|
||||
// connect(vpn, &MozillaVPN::stateChanged, this,
|
||||
// &SystemTrayNotificationHandler::updateContextMenu);
|
||||
{
|
||||
m_systemTrayIcon.show();
|
||||
connect(&m_systemTrayIcon, &QSystemTrayIcon::activated, this, &SystemTrayNotificationHandler::onTrayActivated);
|
||||
|
||||
// connect(vpn->currentServer(), &ServerData::changed, this,
|
||||
// &SystemTrayNotificationHandler::updateContextMenu);
|
||||
|
||||
// connect(vpn->controller(), &Controller::stateChanged, this,
|
||||
// &SystemTrayNotificationHandler::updateContextMenu);
|
||||
m_menu.addAction(QIcon(":/images/tray/application.png"), tr("Show") + " " + APPLICATION_NAME, this, [this](){
|
||||
emit raiseRequested();
|
||||
});
|
||||
m_menu.addSeparator();
|
||||
m_trayActionConnect = m_menu.addAction(tr("Connect"), this, [this](){ emit connectRequested(); });
|
||||
m_trayActionDisconnect = m_menu.addAction(tr("Disconnect"), this, [this](){ emit disconnectRequested(); });
|
||||
|
||||
// connect(vpn->statusIcon(), &StatusIcon::iconChanged, this,
|
||||
// &SystemTrayNotificationHandler::updateIcon);
|
||||
m_menu.addSeparator();
|
||||
|
||||
// m_systemTrayIcon.setToolTip(qtTrId("vpn.main.productName"));
|
||||
m_menu.addAction(QIcon(":/images/tray/link.png"), tr("Visit Website"), [&](){
|
||||
QDesktopServices::openUrl(QUrl("https://amnezia.org"));
|
||||
});
|
||||
|
||||
// // Status label
|
||||
// m_statusLabel = m_menu.addAction("");
|
||||
// m_statusLabel->setEnabled(false);
|
||||
m_menu.addAction(QIcon(":/images/tray/cancel.png"), tr("Quit") + " " + APPLICATION_NAME, this, [&](){
|
||||
qApp->quit();
|
||||
});
|
||||
|
||||
// m_lastLocationLabel =
|
||||
// m_menu.addAction("", vpn->controller(), &Controller::activate);
|
||||
// m_lastLocationLabel->setEnabled(false);
|
||||
m_systemTrayIcon.setContextMenu(&m_menu);
|
||||
setTrayState(VpnProtocol::Disconnected);
|
||||
|
||||
// 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);
|
||||
|
||||
|
@ -80,20 +74,94 @@ SystemTrayNotificationHandler::SystemTrayNotificationHandler(QObject* parent)
|
|||
SystemTrayNotificationHandler::~SystemTrayNotificationHandler() {
|
||||
}
|
||||
|
||||
void SystemTrayNotificationHandler::setConnectionState(VpnProtocol::ConnectionState state)
|
||||
{
|
||||
setTrayState(state);
|
||||
NotificationHandler::setConnectionState(state);
|
||||
}
|
||||
|
||||
void SystemTrayNotificationHandler::setTrayIcon(const QString &iconPath)
|
||||
{
|
||||
QIcon trayIconMask(QPixmap(iconPath).scaled(128,128));
|
||||
trayIconMask.setIsMask(true);
|
||||
m_systemTrayIcon.setIcon(trayIconMask);
|
||||
}
|
||||
|
||||
void SystemTrayNotificationHandler::onTrayActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
#ifndef Q_OS_MAC
|
||||
if(reason == QSystemTrayIcon::DoubleClick || reason == QSystemTrayIcon::Trigger) {
|
||||
emit raiseRequested();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SystemTrayNotificationHandler::setTrayState(VpnProtocol::ConnectionState state)
|
||||
{
|
||||
qDebug() << "SystemTrayNotificationHandler::setTrayState" << state;
|
||||
QString resourcesPath = ":/images/tray/%1";
|
||||
|
||||
switch (state) {
|
||||
case VpnProtocol::Disconnected:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
m_trayActionConnect->setEnabled(true);
|
||||
m_trayActionDisconnect->setEnabled(false);
|
||||
break;
|
||||
case VpnProtocol::Preparing:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
m_trayActionConnect->setEnabled(false);
|
||||
m_trayActionDisconnect->setEnabled(true);
|
||||
break;
|
||||
case VpnProtocol::Connecting:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
m_trayActionConnect->setEnabled(false);
|
||||
m_trayActionDisconnect->setEnabled(true);
|
||||
break;
|
||||
case VpnProtocol::Connected:
|
||||
setTrayIcon(QString(resourcesPath).arg(ConnectedTrayIconName));
|
||||
m_trayActionConnect->setEnabled(false);
|
||||
m_trayActionDisconnect->setEnabled(true);
|
||||
break;
|
||||
case VpnProtocol::Disconnecting:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
m_trayActionConnect->setEnabled(false);
|
||||
m_trayActionDisconnect->setEnabled(true);
|
||||
break;
|
||||
case VpnProtocol::Reconnecting:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
m_trayActionConnect->setEnabled(false);
|
||||
m_trayActionDisconnect->setEnabled(true);
|
||||
break;
|
||||
case VpnProtocol::Error:
|
||||
setTrayIcon(QString(resourcesPath).arg(ErrorTrayIconName));
|
||||
m_trayActionConnect->setEnabled(true);
|
||||
m_trayActionDisconnect->setEnabled(false);
|
||||
break;
|
||||
case VpnProtocol::Unknown:
|
||||
default:
|
||||
m_trayActionConnect->setEnabled(false);
|
||||
m_trayActionDisconnect->setEnabled(true);
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
}
|
||||
|
||||
//#ifdef Q_OS_MAC
|
||||
// // Get theme from current user (note, this app can be launched as root application and in this case this theme can be different from theme of real current user )
|
||||
// bool darkTaskBar = MacOSFunctions::instance().isMenuBarUseDarkTheme();
|
||||
// darkTaskBar = forceUseBrightIcons ? true : darkTaskBar;
|
||||
// resourcesPath = ":/images_mac/tray_icon/%1";
|
||||
// useIconName = useIconName.replace(".png", darkTaskBar ? "@2x.png" : " dark@2x.png");
|
||||
//#endif
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
QIcon icon(ConnectedTrayIconName);
|
||||
m_systemTrayIcon.showMessage(title, message, icon, timerMsec);
|
||||
}
|
||||
|
||||
void SystemTrayNotificationHandler::showHideWindow() {
|
||||
|
@ -111,17 +179,3 @@ void SystemTrayNotificationHandler::showHideWindow() {
|
|||
// }
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -11,35 +11,39 @@
|
|||
#include <QSystemTrayIcon>
|
||||
|
||||
class SystemTrayNotificationHandler : public NotificationHandler {
|
||||
public:
|
||||
explicit SystemTrayNotificationHandler(QObject* parent);
|
||||
~SystemTrayNotificationHandler();
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
virtual void notify(Message type, const QString& title,
|
||||
const QString& message, int timerMsec) override;
|
||||
public:
|
||||
explicit SystemTrayNotificationHandler(QObject* parent);
|
||||
~SystemTrayNotificationHandler();
|
||||
|
||||
private:
|
||||
void updateIcon(const QString& icon);
|
||||
void setConnectionState(VpnProtocol::ConnectionState state) override;
|
||||
|
||||
void updateContextMenu();
|
||||
protected:
|
||||
virtual void notify(Message type, const QString& title,
|
||||
const QString& message, int timerMsec) override;
|
||||
|
||||
void showHideWindow();
|
||||
private:
|
||||
void showHideWindow();
|
||||
|
||||
void maybeActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
void setTrayState(VpnProtocol::ConnectionState state);
|
||||
void onTrayActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
private:
|
||||
QMenu m_menu;
|
||||
QSystemTrayIcon m_systemTrayIcon;
|
||||
void setTrayIcon(const QString &iconPath);
|
||||
|
||||
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;
|
||||
private:
|
||||
QMenu m_menu;
|
||||
QSystemTrayIcon m_systemTrayIcon;
|
||||
|
||||
QAction* m_trayActionConnect = nullptr;
|
||||
QAction* m_trayActionDisconnect = nullptr;
|
||||
QAction* m_preferencesAction = nullptr;
|
||||
QAction* m_statusLabel = nullptr;
|
||||
QAction* m_separator = nullptr;
|
||||
|
||||
const QString ConnectedTrayIconName = "active.png";
|
||||
const QString DisconnectedTrayIconName = "default.png";
|
||||
const QString ErrorTrayIconName = "error.png";
|
||||
};
|
||||
|
||||
#endif // SYSTEMTRAY_NOTIFICATIONHANDLER_H
|
||||
|
|
|
@ -108,8 +108,6 @@ UiLogic::UiLogic(QObject *parent) :
|
|||
|
||||
UiLogic::~UiLogic()
|
||||
{
|
||||
m_tray = nullptr;
|
||||
|
||||
emit hide();
|
||||
|
||||
if (m_vpnConnection->connectionState() != VpnProtocol::ConnectionState::Disconnected) {
|
||||
|
@ -132,18 +130,22 @@ UiLogic::~UiLogic()
|
|||
|
||||
void UiLogic::initalizeUiLogic()
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
if (!AndroidController::instance()->initialize()) {
|
||||
qDebug() << QString("Init failed") ;
|
||||
emit VpnProtocol::Error;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
qDebug() << "UiLogic::initalizeUiLogic()";
|
||||
setupTray();
|
||||
|
||||
notificationHandler = NotificationHandler::create(this);
|
||||
m_notificationHandler = NotificationHandler::create(qmlRoot());
|
||||
|
||||
connect(m_vpnConnection, &VpnConnection::connectionStateChanged, notificationHandler, &NotificationHandler::showVpnStateNotification);
|
||||
connect(m_vpnConnection, &VpnConnection::connectionStateChanged, m_notificationHandler, &NotificationHandler::setConnectionState);
|
||||
connect(m_notificationHandler, &NotificationHandler::raiseRequested, this, &UiLogic::raise);
|
||||
connect(m_notificationHandler, &NotificationHandler::connectRequested, vpnLogic(), &VpnLogic::onConnect);
|
||||
connect(m_notificationHandler, &NotificationHandler::disconnectRequested, vpnLogic(), &VpnLogic::onDisconnect);
|
||||
|
||||
// if (QOperatingSystemVersion::current() <= QOperatingSystemVersion::Windows7) {
|
||||
// needToHideCustomTitlebar = true;
|
||||
|
@ -613,26 +615,6 @@ ErrorCode UiLogic::doInstallAction(const std::function<ErrorCode()> &action,
|
|||
return ErrorCode::NoError;
|
||||
}
|
||||
|
||||
void UiLogic::setupTray()
|
||||
{
|
||||
m_tray = new QSystemTrayIcon(qmlRoot());
|
||||
setTrayState(VpnProtocol::Disconnected);
|
||||
|
||||
m_tray->show();
|
||||
|
||||
connect(m_tray, &QSystemTrayIcon::activated, this, &UiLogic::onTrayActivated);
|
||||
}
|
||||
|
||||
void UiLogic::setTrayIcon(const QString &iconPath)
|
||||
{
|
||||
if (m_tray) m_tray->setIcon(QIcon(QPixmap(iconPath).scaled(128,128)));
|
||||
}
|
||||
|
||||
void UiLogic::onTrayActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
emit raise();
|
||||
}
|
||||
|
||||
PageProtocolLogicBase *UiLogic::protocolLogic(Protocol p) {
|
||||
PageProtocolLogicBase *logic = m_protocolLogicMap.value(p);
|
||||
if (logic) return logic;
|
||||
|
@ -652,57 +634,23 @@ void UiLogic::setQmlRoot(QObject *newQmlRoot)
|
|||
m_qmlRoot = newQmlRoot;
|
||||
}
|
||||
|
||||
NotificationHandler *UiLogic::notificationHandler() const
|
||||
{
|
||||
return m_notificationHandler;
|
||||
}
|
||||
|
||||
PageEnumNS::Page UiLogic::currentPage()
|
||||
{
|
||||
return static_cast<PageEnumNS::Page>(currentPageValue());
|
||||
}
|
||||
|
||||
void UiLogic::setTrayState(VpnProtocol::ConnectionState state)
|
||||
{
|
||||
QString resourcesPath = ":/images/tray/%1";
|
||||
|
||||
switch (state) {
|
||||
case VpnProtocol::Disconnected:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
break;
|
||||
case VpnProtocol::Preparing:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
break;
|
||||
case VpnProtocol::Connecting:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
break;
|
||||
case VpnProtocol::Connected:
|
||||
setTrayIcon(QString(resourcesPath).arg(ConnectedTrayIconName));
|
||||
break;
|
||||
case VpnProtocol::Disconnecting:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
break;
|
||||
case VpnProtocol::Reconnecting:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
break;
|
||||
case VpnProtocol::Error:
|
||||
setTrayIcon(QString(resourcesPath).arg(ErrorTrayIconName));
|
||||
break;
|
||||
case VpnProtocol::Unknown:
|
||||
default:
|
||||
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||
}
|
||||
|
||||
//#ifdef Q_OS_MAC
|
||||
// // Get theme from current user (note, this app can be launched as root application and in this case this theme can be different from theme of real current user )
|
||||
// bool darkTaskBar = MacOSFunctions::instance().isMenuBarUseDarkTheme();
|
||||
// darkTaskBar = forceUseBrightIcons ? true : darkTaskBar;
|
||||
// resourcesPath = ":/images_mac/tray_icon/%1";
|
||||
// useIconName = useIconName.replace(".png", darkTaskBar ? "@2x.png" : " dark@2x.png");
|
||||
//#endif
|
||||
}
|
||||
|
||||
|
||||
bool UiLogic::saveTextFile(const QString& desc, const QString& ext, const QString& data)
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(nullptr, desc,
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), ext);
|
||||
|
||||
if (fileName.isEmpty()) return false;
|
||||
|
||||
QSaveFile save(fileName);
|
||||
save.open(QIODevice::WriteOnly);
|
||||
save.write(data.toUtf8());
|
||||
|
@ -718,6 +666,8 @@ bool UiLogic::saveBinaryFile(const QString &desc, const QString &ext, const QStr
|
|||
QString fileName = QFileDialog::getSaveFileName(nullptr, desc,
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), ext);
|
||||
|
||||
if (fileName.isEmpty()) return false;
|
||||
|
||||
QSaveFile save(fileName);
|
||||
save.open(QIODevice::WriteOnly);
|
||||
save.write(QByteArray::fromBase64(data.toUtf8()));
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <functional>
|
||||
#include <QKeyEvent>
|
||||
#include <QThread>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#include "property_helper.h"
|
||||
#include "pages.h"
|
||||
|
@ -108,12 +107,8 @@ public:
|
|||
void setDialogConnectErrorText(const QString &dialogConnectErrorText);
|
||||
|
||||
signals:
|
||||
void trayIconUrlChanged();
|
||||
void trayActionDisconnectEnabledChanged();
|
||||
void trayActionConnectEnabledChanged();
|
||||
void dialogConnectErrorTextChanged();
|
||||
|
||||
|
||||
void goToPage(PageEnumNS::Page page, bool reset = true, bool slide = true);
|
||||
void goToProtocolPage(Protocol protocol, bool reset = true, bool slide = true);
|
||||
void goToShareProtocolPage(Protocol protocol, bool reset = true, bool slide = true);
|
||||
|
@ -127,16 +122,12 @@ signals:
|
|||
void raise();
|
||||
|
||||
private:
|
||||
QSystemTrayIcon *m_tray;
|
||||
|
||||
QString m_dialogConnectErrorText;
|
||||
|
||||
private slots:
|
||||
// containers - INOUT arg
|
||||
void installServer(QMap<DockerContainer, QJsonObject> &containers);
|
||||
|
||||
void setTrayState(VpnProtocol::ConnectionState state);
|
||||
void onTrayActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
private:
|
||||
PageEnumNS::Page currentPage();
|
||||
|
@ -172,9 +163,6 @@ private:
|
|||
const ButtonFunc& button,
|
||||
const LabelFunc& info);
|
||||
|
||||
void setupTray();
|
||||
void setTrayIcon(const QString &iconPath);
|
||||
|
||||
|
||||
public:
|
||||
AppSettingsLogic *appSettingsLogic() { return m_appSettingsLogic; }
|
||||
|
@ -196,6 +184,8 @@ public:
|
|||
QObject *qmlRoot() const;
|
||||
void setQmlRoot(QObject *newQmlRoot);
|
||||
|
||||
NotificationHandler *notificationHandler() const;
|
||||
|
||||
private:
|
||||
QObject *m_qmlRoot{nullptr};
|
||||
|
||||
|
@ -219,7 +209,7 @@ private:
|
|||
QThread m_vpnConnectionThread;
|
||||
Settings m_settings;
|
||||
|
||||
NotificationHandler* notificationHandler;
|
||||
NotificationHandler* m_notificationHandler;
|
||||
|
||||
|
||||
// QRegExpValidator m_ipAddressValidator;
|
||||
|
@ -233,10 +223,6 @@ private:
|
|||
// void showEvent(QShowEvent *event) override;
|
||||
// void hideEvent(QHideEvent *event) override;
|
||||
|
||||
const QString ConnectedTrayIconName = "active.png";
|
||||
const QString DisconnectedTrayIconName = "default.png";
|
||||
const QString ErrorTrayIconName = "error.png";
|
||||
|
||||
|
||||
// QStack<Page> pagesStack;
|
||||
int selectedServerIndex = -1; // server index to use when proto settings page opened
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QJsonObject>
|
||||
#include <android_controller.h>
|
||||
|
||||
#include <configurators/openvpn_configurator.h>
|
||||
#include <configurators/cloak_configurator.h>
|
||||
|
@ -13,7 +12,8 @@
|
|||
#include <protocols/wireguardprotocol.h>
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include <protocols/android_vpnprotocol.h>
|
||||
#include "android_controller.h"
|
||||
#include "protocols/android_vpnprotocol.h"
|
||||
#endif
|
||||
|
||||
#include "ipc.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue