From 4392b1fcc9576594cd56ee7f99803e29cf8eaf2a Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Fri, 24 Jan 2020 23:03:18 +0100 Subject: [PATCH] Add shutdown command --- app/SysTray-X/systrayx.cpp | 13 ++++++ app/SysTray-X/systrayx.h | 5 +++ app/SysTray-X/systrayxlink.cpp | 5 +++ app/SysTray-X/systrayxlink.h | 73 ++++++++++++++++++---------------- webext/background.js | 12 ++++++ 5 files changed, 74 insertions(+), 34 deletions(-) diff --git a/app/SysTray-X/systrayx.cpp b/app/SysTray-X/systrayx.cpp index a3a4261..f5f5b19 100644 --- a/app/SysTray-X/systrayx.cpp +++ b/app/SysTray-X/systrayx.cpp @@ -94,6 +94,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) * Connect link signals */ connect( m_link, &SysTrayXLink::signalUnreadMail, m_tray_icon, &SysTrayXIcon::slotSetUnreadMail ); + connect( m_link, &SysTrayXLink::signalShutdown, this, &SysTrayX::slotShutdown ); /* * Request preferences from add-on @@ -191,3 +192,15 @@ void SysTrayX::createTrayIcon() m_tray_icon->setIconData( m_preferences->getIconData() ); m_tray_icon->setIconType( m_preferences->getIconType() ); } + + +/* + * Quit the app + */ +void SysTrayX::slotShutdown() +{ + /* + * Let's quit + */ + QCoreApplication::quit(); +} diff --git a/app/SysTray-X/systrayx.h b/app/SysTray-X/systrayx.h index 849a0a2..2a0551e 100644 --- a/app/SysTray-X/systrayx.h +++ b/app/SysTray-X/systrayx.h @@ -77,6 +77,11 @@ class SysTrayX : public QObject private slots: + /** + * @brief slotShutdown Shutdown the app. + */ + void slotShutdown(); + private: /** diff --git a/app/SysTray-X/systrayxlink.cpp b/app/SysTray-X/systrayxlink.cpp index bd99020..27a18f0 100644 --- a/app/SysTray-X/systrayxlink.cpp +++ b/app/SysTray-X/systrayxlink.cpp @@ -141,6 +141,11 @@ void SysTrayXLink::DecodeMessage( const QByteArray& message ) { QJsonObject jsonObject = jsonResponse.object(); + if( jsonObject.contains( "shutdown" ) && jsonObject[ "shutdown" ].isString() ) + { + emit signalShutdown(); + } + if( jsonObject.contains( "unreadMail" ) && jsonObject[ "unreadMail" ].isDouble() ) { int unreadMail = jsonObject[ "unreadMail" ].toInt(); diff --git a/app/SysTray-X/systrayxlink.h b/app/SysTray-X/systrayxlink.h index c4e8d7a..f428474 100644 --- a/app/SysTray-X/systrayxlink.h +++ b/app/SysTray-X/systrayxlink.h @@ -68,42 +68,13 @@ class SysTrayXLink : public QObject */ void EncodePreferences( const Preferences& pref ); - public slots: - - /** - * @brief slotDebugChange. Handle a change in debug state. - */ - void slotDebugChange(); - - /** - * @brief slotLinkWrite. Write the link. - */ - void slotLinkWrite( QByteArray message ); - - /** - * @brief slotIconTypeChange. Slot for handling icon type change signals. - */ - void slotIconTypeChange(); - - /** - * @brief slotIconDataChange. Slot for handling icon data change signals. - */ - void slotIconDataChange(); - - private slots: - - /** - * @brief slotLinkRead. Read the link. - */ - void slotLinkRead(); - - /** - * @brief slotLinkReadException. Handle a read link exception. - */ - void slotLinkReadException(); - signals: + /** + * @brief signalShutdown. Signal to shutdown the app. + */ + void signalShutdown(); + /** * @brief signalReceivedMessageLength * @@ -139,6 +110,40 @@ class SysTrayXLink : public QObject */ void signalUnreadMail( int unread_mail ); + public slots: + + /** + * @brief slotDebugChange. Handle a change in debug state. + */ + void slotDebugChange(); + + /** + * @brief slotLinkWrite. Write the link. + */ + void slotLinkWrite( QByteArray message ); + + /** + * @brief slotIconTypeChange. Slot for handling icon type change signals. + */ + void slotIconTypeChange(); + + /** + * @brief slotIconDataChange. Slot for handling icon data change signals. + */ + void slotIconDataChange(); + + private slots: + + /** + * @brief slotLinkRead. Read the link. + */ + void slotLinkRead(); + + /** + * @brief slotLinkReadException. Handle a read link exception. + */ + void slotLinkReadException(); + private: /** diff --git a/webext/background.js b/webext/background.js index 28b52ef..6a8de7c 100644 --- a/webext/background.js +++ b/webext/background.js @@ -22,6 +22,18 @@ SysTrayX.Messaging = { // this.unReadMessages(this.unreadFiltersTest).then(this.unreadCb); window.setInterval(SysTrayX.Messaging.pollAccounts, 10000); + + // Semd the app a close command + browser.windows.onRemoved.addListener(SysTrayX.Messaging.closeApp); + }, + + closeApp: function() { + console.debug("Shutting down"); + + // Send it to the app + SysTrayX.Link.postSysTrayXMessage({ + shutdown: "" + }); }, //