diff --git a/linux/Main.qml b/linux/Main.qml index d824edd..aa8e115 100644 --- a/linux/Main.qml +++ b/linux/Main.qml @@ -194,8 +194,15 @@ ApplicationWindow { onCheckedChanged: airPodsTrayApp.autoStartManager.autoStartEnabled = checked } + Switch { + text: "Enable System Notifications" + checked: airPodsTrayApp.notificationsEnabled + onCheckedChanged: airPodsTrayApp.notificationsEnabled = checked + } + Row { spacing: 10 + visible: airPodsTrayApp.airpodsConnected TextField { id: newNameField diff --git a/linux/main.cpp b/linux/main.cpp index 57b0f55..37e098b 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -33,6 +33,7 @@ class AirPodsTrayApp : public QObject { Q_PROPERTY(int earDetectionBehavior READ earDetectionBehavior WRITE setEarDetectionBehavior NOTIFY earDetectionBehaviorChanged) Q_PROPERTY(bool crossDeviceEnabled READ crossDeviceEnabled WRITE setCrossDeviceEnabled NOTIFY crossDeviceEnabledChanged) Q_PROPERTY(AutoStartManager *autoStartManager READ autoStartManager CONSTANT) + Q_PROPERTY(bool notificationsEnabled READ notificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged) public: AirPodsTrayApp(bool debugMode, QObject *parent = nullptr) @@ -52,12 +53,15 @@ public: // Initialize tray icon and connect signals trayManager = new TrayIconManager(this); + trayManager->setNotificationsEnabled(loadNotificationsEnabled()); connect(trayManager, &TrayIconManager::trayClicked, this, &AirPodsTrayApp::onTrayIconActivated); connect(trayManager, &TrayIconManager::noiseControlChanged, this, qOverload(&AirPodsTrayApp::setNoiseControlMode)); connect(trayManager, &TrayIconManager::conversationalAwarenessToggled, this, &AirPodsTrayApp::setConversationalAwareness); connect(this, &AirPodsTrayApp::batteryStatusChanged, trayManager, &TrayIconManager::updateBatteryStatus); connect(this, &AirPodsTrayApp::noiseControlModeChanged, trayManager, &TrayIconManager::updateNoiseControlState); connect(this, &AirPodsTrayApp::conversationalAwarenessChanged, trayManager, &TrayIconManager::updateConversationalAwareness); + connect(trayManager, &TrayIconManager::notificationsEnabledChanged, this, &AirPodsTrayApp::saveNotificationsEnabled); + connect(trayManager, &TrayIconManager::notificationsEnabledChanged, this, &AirPodsTrayApp::notificationsEnabledChanged); // Initialize MediaController and connect signals mediaController = new MediaController(this); @@ -130,6 +134,8 @@ public: int earDetectionBehavior() const { return mediaController->getEarDetectionBehavior(); } bool crossDeviceEnabled() const { return CrossDevice.isEnabled; } AutoStartManager *autoStartManager() const { return m_autoStartManager; } + bool notificationsEnabled() const { return trayManager->notificationsEnabled(); } + void setNotificationsEnabled(bool enabled) { trayManager->setNotificationsEnabled(enabled); } private: bool debugMode; @@ -310,6 +316,9 @@ public slots: int loadEarDetectionSettings() { return m_settings->value("earDetection/setting", MediaController::EarDetectionBehavior::PauseWhenOneRemoved).toInt(); } void saveEarDetectionSettings() { m_settings->setValue("earDetection/setting", mediaController->getEarDetectionBehavior()); } + bool loadNotificationsEnabled() const { return m_settings->value("notifications/enabled", true).toBool(); } + void saveNotificationsEnabled(bool enabled) { m_settings->setValue("notifications/enabled", enabled); } + private slots: void onTrayIconActivated() { @@ -856,6 +865,7 @@ signals: void airPodsStatusChanged(); void earDetectionBehaviorChanged(int behavior); void crossDeviceEnabledChanged(bool enabled); + void notificationsEnabledChanged(bool enabled); private: QBluetoothSocket *socket = nullptr; diff --git a/linux/trayiconmanager.cpp b/linux/trayiconmanager.cpp index ca62087..137a841 100644 --- a/linux/trayiconmanager.cpp +++ b/linux/trayiconmanager.cpp @@ -29,6 +29,8 @@ TrayIconManager::TrayIconManager(QObject *parent) : QObject(parent) void TrayIconManager::showNotification(const QString &title, const QString &message) { + if (!m_notificationsEnabled) + return; trayIcon->showMessage(title, message, QSystemTrayIcon::Information, 3000); } diff --git a/linux/trayiconmanager.h b/linux/trayiconmanager.h index ac27b35..adcdbdb 100644 --- a/linux/trayiconmanager.h +++ b/linux/trayiconmanager.h @@ -10,6 +10,7 @@ class QActionGroup; class TrayIconManager : public QObject { Q_OBJECT + Q_PROPERTY(bool notificationsEnabled READ notificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged) public: explicit TrayIconManager(QObject *parent = nullptr); @@ -22,6 +23,19 @@ public: void showNotification(const QString &title, const QString &message); + bool notificationsEnabled() const { return m_notificationsEnabled; } + void setNotificationsEnabled(bool enabled) + { + if (m_notificationsEnabled != enabled) + { + m_notificationsEnabled = enabled; + emit notificationsEnabledChanged(enabled); + } + } + +signals: + void notificationsEnabledChanged(bool enabled); + private slots: void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason); @@ -30,6 +44,7 @@ private: QMenu *trayMenu; QAction *caToggleAction; QActionGroup *noiseControlGroup; + bool m_notificationsEnabled = true; void setupMenuActions();