feat: add macOS notification handler and install event filter on main window
This commit is contained in:
parent
9b89237f54
commit
4f2d9b4fa9
3 changed files with 58 additions and 9 deletions
|
@ -21,6 +21,8 @@
|
|||
#include "platforms/ios/QRCodeReaderBase.h"
|
||||
|
||||
#include "protocols/qml_register_protocols.h"
|
||||
#include <QtQuick/QQuickWindow> // for QQuickWindow
|
||||
#include <QWindow> // for qobject_cast<QWindow*>
|
||||
|
||||
AmneziaApplication::AmneziaApplication(int &argc, char *argv[]) : AMNEZIA_BASE_CLASS(argc, argv)
|
||||
{
|
||||
|
@ -63,12 +65,19 @@ void AmneziaApplication::init()
|
|||
|
||||
const QUrl url(QStringLiteral("qrc:/ui/qml/main2.qml"));
|
||||
QObject::connect(
|
||||
m_engine, &QQmlApplicationEngine::objectCreated, this,
|
||||
[url](QObject *obj, const QUrl &objUrl) {
|
||||
if (!obj && url == objUrl)
|
||||
QCoreApplication::exit(-1);
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
m_engine, &QQmlApplicationEngine::objectCreated, this,
|
||||
[this, url](QObject *obj, const QUrl &objUrl) {
|
||||
if (!obj && url == objUrl) {
|
||||
QCoreApplication::exit(-1);
|
||||
return;
|
||||
}
|
||||
// install filter on main window
|
||||
if (auto win = qobject_cast<QQuickWindow*>(obj)) {
|
||||
win->installEventFilter(this);
|
||||
win->show();
|
||||
}
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
|
||||
m_engine->rootContext()->setContextProperty("Debug", &Logger::Instance());
|
||||
|
||||
|
|
|
@ -8,8 +8,9 @@ set(APPLE_PROJECT_VERSION ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION
|
|||
enable_language(OBJC)
|
||||
enable_language(Swift)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS ShaderTools)
|
||||
set(LIBS ${LIBS} Qt6::ShaderTools)
|
||||
find_package(Qt6 REQUIRED COMPONENTS ShaderTools Widgets)
|
||||
# Link Qt Widgets for QWidget, QMenu, QAction etc.
|
||||
set(LIBS ${LIBS} Qt6::ShaderTools Qt6::Widgets)
|
||||
|
||||
find_library(FW_AUTHENTICATIONSERVICES AuthenticationServices)
|
||||
find_library(FW_AVFOUNDATION AVFoundation)
|
||||
|
@ -55,7 +56,10 @@ set_source_files_properties(${ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Reso
|
|||
set(SOURCES ${SOURCES} ${ICON_FILE})
|
||||
|
||||
|
||||
target_include_directories(${PROJECT} PRIVATE ${Qt6Gui_PRIVATE_INCLUDE_DIRS})
|
||||
target_include_directories(${PROJECT} PRIVATE
|
||||
${Qt6Gui_PRIVATE_INCLUDE_DIRS}
|
||||
${Qt6Widgets_PRIVATE_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
|
||||
set_target_properties(${PROJECT} PROPERTIES
|
||||
|
|
36
client/ui/ne_notificationhandler.h
Normal file
36
client/ui/ne_notificationhandler.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef NE_NOTIFICATION_HANDLER_H
|
||||
#define NE_NOTIFICATION_HANDLER_H
|
||||
|
||||
#include "notificationhandler.h"
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
||||
class MacOSStatusIcon;
|
||||
|
||||
class NEStatusBarNotificationHandler : public NotificationHandler {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NEStatusBarNotificationHandler(QObject* parent);
|
||||
~NEStatusBarNotificationHandler() override;
|
||||
|
||||
void setConnectionState(Vpn::ConnectionState state) override;
|
||||
void onTranslationsUpdated() override;
|
||||
|
||||
protected:
|
||||
void notify(Message type, const QString& title,
|
||||
const QString& message, int timerMsec) override;
|
||||
|
||||
private:
|
||||
void buildMenu();
|
||||
|
||||
QMenu m_menu;
|
||||
MacOSStatusIcon* m_statusIcon;
|
||||
|
||||
QAction* m_actionShow;
|
||||
QAction* m_actionConnect;
|
||||
QAction* m_actionDisconnect;
|
||||
QAction* m_actionVisitWebsite;
|
||||
QAction* m_actionQuit;
|
||||
};
|
||||
|
||||
#endif // NE_NOTIFICATION_HANDLER_H
|
Loading…
Add table
Add a link
Reference in a new issue