[Linux] Add setting to disable notifications

This commit is contained in:
Tim Gromeyer
2025-04-22 13:06:20 +02:00
committed by Tim Gromeyer
parent ec1b0c47ca
commit 913e1a5aff
4 changed files with 34 additions and 0 deletions

View File

@@ -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

View File

@@ -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<NoiseControlMode>(&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;

View File

@@ -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);
}

View File

@@ -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();