Tray fix
This commit is contained in:
parent
9dee7bb7e7
commit
3a49d5fdc4
5 changed files with 42 additions and 119 deletions
|
@ -177,6 +177,10 @@ int main(int argc, char *argv[])
|
|||
delete uiLogic;
|
||||
});
|
||||
|
||||
if (engine->rootObjects().size() > 0) {
|
||||
uiLogic->setQmlRoot(engine->rootObjects().at(0));
|
||||
}
|
||||
|
||||
// TODO - fix
|
||||
//#ifdef Q_OS_WIN
|
||||
// if (parser.isSet("a")) mainWindow.showOnStartup();
|
||||
|
|
|
@ -126,7 +126,7 @@ PageBase {
|
|||
}
|
||||
ImageButtonType {
|
||||
id: pushButtonSetting
|
||||
x: parent.width - 60
|
||||
x: parent.width - 70
|
||||
y: 15
|
||||
width: 30
|
||||
height: 30
|
||||
|
|
|
@ -239,6 +239,11 @@ Window {
|
|||
function onHide() {
|
||||
root.hide()
|
||||
}
|
||||
function onRaise() {
|
||||
root.show()
|
||||
root.raise()
|
||||
root.requestActivate()
|
||||
}
|
||||
}
|
||||
|
||||
MessageDialog {
|
||||
|
@ -253,62 +258,6 @@ Window {
|
|||
}
|
||||
visible: false
|
||||
}
|
||||
SystemTrayIcon {
|
||||
visible: true
|
||||
icon.source: UiLogic.trayIconUrl
|
||||
onActivated: {
|
||||
if (Qt.platform.os == "osx" ||
|
||||
Qt.platform.os == "linux") {
|
||||
if (reason === SystemTrayIcon.DoubleClick ||
|
||||
reason === SystemTrayIcon.Trigger) {
|
||||
root.show()
|
||||
root.raise()
|
||||
root.requestActivate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
menu: Menu {
|
||||
MenuItem {
|
||||
iconSource: "qrc:/images/tray/application.png"
|
||||
text: qsTr("Show") + " " + "AmneziaVPN"
|
||||
onTriggered: {
|
||||
root.show()
|
||||
root.raise()
|
||||
}
|
||||
}
|
||||
MenuSeparator { }
|
||||
MenuItem {
|
||||
text: qsTr("Connect")
|
||||
enabled: UiLogic.trayActionConnectEnabled
|
||||
onTriggered: {
|
||||
UiLogic.onConnect()
|
||||
}
|
||||
}
|
||||
MenuItem {
|
||||
text: qsTr("Disconnect")
|
||||
enabled: UiLogic.trayActionDisconnectEnabled
|
||||
onTriggered: {
|
||||
UiLogic.onDisconnect()
|
||||
}
|
||||
}
|
||||
MenuSeparator { }
|
||||
MenuItem {
|
||||
iconSource: "qrc:/images/tray/link.png"
|
||||
text: qsTr("Visit Website")
|
||||
onTriggered: {
|
||||
Qt.openUrlExternally("https://amnezia.org")
|
||||
}
|
||||
}
|
||||
MenuItem {
|
||||
iconSource: "qrc:/images/tray/cancel.png"
|
||||
text: qsTr("Quit") + " " + "AmneziaVPN"
|
||||
onTriggered: {
|
||||
closePrompt.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
MessageDialog {
|
||||
id: publicKeyWarning
|
||||
title: "AmneziaVPN"
|
||||
|
|
|
@ -69,9 +69,6 @@ using namespace PageEnumNS;
|
|||
|
||||
UiLogic::UiLogic(QObject *parent) :
|
||||
QObject(parent),
|
||||
m_trayIconUrl{},
|
||||
m_trayActionDisconnectEnabled{true},
|
||||
m_trayActionConnectEnabled{true},
|
||||
m_dialogConnectErrorText{}
|
||||
{
|
||||
m_containersModel = new ContainersModel(this);
|
||||
|
@ -193,45 +190,6 @@ void UiLogic::initalizeUiLogic()
|
|||
|
||||
}
|
||||
|
||||
QString UiLogic::getTrayIconUrl() const
|
||||
{
|
||||
return m_trayIconUrl;
|
||||
}
|
||||
|
||||
void UiLogic::setTrayIconUrl(const QString &trayIconUrl)
|
||||
{
|
||||
if (m_trayIconUrl != trayIconUrl) {
|
||||
m_trayIconUrl = trayIconUrl;
|
||||
emit trayIconUrlChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool UiLogic::getTrayActionDisconnectEnabled() const
|
||||
{
|
||||
return m_trayActionDisconnectEnabled;
|
||||
}
|
||||
|
||||
void UiLogic::setTrayActionDisconnectEnabled(bool trayActionDisconnectEnabled)
|
||||
{
|
||||
if (m_trayActionDisconnectEnabled != trayActionDisconnectEnabled) {
|
||||
m_trayActionDisconnectEnabled = trayActionDisconnectEnabled;
|
||||
emit trayActionDisconnectEnabledChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool UiLogic::getTrayActionConnectEnabled() const
|
||||
{
|
||||
return m_trayActionConnectEnabled;
|
||||
}
|
||||
|
||||
void UiLogic::setTrayActionConnectEnabled(bool trayActionConnectEnabled)
|
||||
{
|
||||
if (m_trayActionConnectEnabled != trayActionConnectEnabled) {
|
||||
m_trayActionConnectEnabled = trayActionConnectEnabled;
|
||||
emit trayActionConnectEnabledChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QString UiLogic::getDialogConnectErrorText() const
|
||||
{
|
||||
return m_dialogConnectErrorText;
|
||||
|
@ -641,12 +599,22 @@ ErrorCode UiLogic::doInstallAction(const std::function<ErrorCode()> &action,
|
|||
|
||||
void UiLogic::setupTray()
|
||||
{
|
||||
setTrayState(VpnProtocol::Disconnected);
|
||||
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)
|
||||
{
|
||||
setTrayIconUrl(iconPath);
|
||||
m_tray->setIcon(QIcon(QPixmap(iconPath).scaled(128,128)));
|
||||
}
|
||||
|
||||
void UiLogic::onTrayActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
emit raise();
|
||||
}
|
||||
|
||||
PageProtocolLogicBase *UiLogic::protocolLogic(Protocol p) {
|
||||
|
@ -658,6 +626,16 @@ PageProtocolLogicBase *UiLogic::protocolLogic(Protocol p) {
|
|||
}
|
||||
}
|
||||
|
||||
QObject *UiLogic::qmlRoot() const
|
||||
{
|
||||
return m_qmlRoot;
|
||||
}
|
||||
|
||||
void UiLogic::setQmlRoot(QObject *newQmlRoot)
|
||||
{
|
||||
m_qmlRoot = newQmlRoot;
|
||||
}
|
||||
|
||||
PageEnumNS::Page UiLogic::currentPage()
|
||||
{
|
||||
return static_cast<PageEnumNS::Page>(currentPageValue());
|
||||
|
@ -665,10 +643,7 @@ PageEnumNS::Page UiLogic::currentPage()
|
|||
|
||||
void UiLogic::setTrayState(VpnProtocol::ConnectionState state)
|
||||
{
|
||||
QString resourcesPath = "qrc:/images/tray/%1";
|
||||
|
||||
setTrayActionDisconnectEnabled(state == VpnProtocol::Connected);
|
||||
setTrayActionConnectEnabled(state == VpnProtocol::Disconnected);
|
||||
QString resourcesPath = ":/images/tray/%1";
|
||||
|
||||
switch (state) {
|
||||
case VpnProtocol::Disconnected:
|
||||
|
@ -704,7 +679,6 @@ void UiLogic::setTrayState(VpnProtocol::ConnectionState state)
|
|||
// resourcesPath = ":/images_mac/tray_icon/%1";
|
||||
// useIconName = useIconName.replace(".png", darkTaskBar ? "@2x.png" : " dark@2x.png");
|
||||
//#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <functional>
|
||||
#include <QKeyEvent>
|
||||
#include <QThread>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#include "property_helper.h"
|
||||
#include "pages.h"
|
||||
|
@ -53,9 +54,6 @@ class UiLogic : public QObject
|
|||
READONLY_PROPERTY(QObject *, protocolsModel)
|
||||
|
||||
// TODO: review
|
||||
Q_PROPERTY(QString trayIconUrl READ getTrayIconUrl WRITE setTrayIconUrl NOTIFY trayIconUrlChanged)
|
||||
Q_PROPERTY(bool trayActionDisconnectEnabled READ getTrayActionDisconnectEnabled WRITE setTrayActionDisconnectEnabled NOTIFY trayActionDisconnectEnabledChanged)
|
||||
Q_PROPERTY(bool trayActionConnectEnabled READ getTrayActionConnectEnabled WRITE setTrayActionConnectEnabled NOTIFY trayActionConnectEnabledChanged)
|
||||
Q_PROPERTY(QString dialogConnectErrorText READ getDialogConnectErrorText WRITE setDialogConnectErrorText NOTIFY dialogConnectErrorTextChanged)
|
||||
|
||||
public:
|
||||
|
@ -105,13 +103,6 @@ public:
|
|||
Q_INVOKABLE bool saveBinaryFile(const QString& desc, const QString& ext, const QString& data);
|
||||
Q_INVOKABLE void copyToClipboard(const QString& text);
|
||||
|
||||
QString getTrayIconUrl() const;
|
||||
void setTrayIconUrl(const QString &trayIconUrl);
|
||||
bool getTrayActionDisconnectEnabled() const;
|
||||
void setTrayActionDisconnectEnabled(bool trayActionDisconnectEnabled);
|
||||
bool getTrayActionConnectEnabled() const;
|
||||
void setTrayActionConnectEnabled(bool trayActionConnectEnabled);
|
||||
|
||||
QString getDialogConnectErrorText() const;
|
||||
void setDialogConnectErrorText(const QString &dialogConnectErrorText);
|
||||
|
||||
|
@ -132,11 +123,10 @@ signals:
|
|||
void showConnectErrorDialog();
|
||||
void show();
|
||||
void hide();
|
||||
void raise();
|
||||
|
||||
private:
|
||||
QString m_trayIconUrl;
|
||||
bool m_trayActionDisconnectEnabled;
|
||||
bool m_trayActionConnectEnabled;
|
||||
QSystemTrayIcon *m_tray;
|
||||
|
||||
QString m_dialogConnectErrorText;
|
||||
|
||||
|
@ -145,6 +135,7 @@ private slots:
|
|||
void installServer(QMap<DockerContainer, QJsonObject> &containers);
|
||||
|
||||
void setTrayState(VpnProtocol::ConnectionState state);
|
||||
void onTrayActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
private:
|
||||
PageEnumNS::Page currentPage();
|
||||
|
@ -201,7 +192,12 @@ public:
|
|||
|
||||
Q_INVOKABLE PageProtocolLogicBase *protocolLogic(Protocol p);
|
||||
|
||||
QObject *qmlRoot() const;
|
||||
void setQmlRoot(QObject *newQmlRoot);
|
||||
|
||||
private:
|
||||
QObject *m_qmlRoot{nullptr};
|
||||
|
||||
AppSettingsLogic *m_appSettingsLogic;
|
||||
GeneralSettingsLogic *m_generalSettingsLogic;
|
||||
NetworkSettingsLogic *m_networkSettingsLogic;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue