]> repos.lx-s.de Git - winmute.git/commitdiff
Integrated mute logic for bluetooth detector
authorAlexander Steinhöfer <kontakt@lx-s.de>
Fri, 29 Jul 2022 13:38:55 +0000 (15:38 +0200)
committerAlexander Steinhöfer <kontakt@lx-s.de>
Fri, 29 Jul 2022 13:38:55 +0000 (15:38 +0200)
WinMute/BluetoothDetector.cpp
WinMute/WMSettings.cpp
WinMute/WMSettings.h
WinMute/WinMute.cpp
WinMute/WinMute.h
WinMute/WinMute.rc
WinMute/resource.h

index b18f7fb8c575a52e02bedaef36e6c98133ed9e1e..bfa8b95847a1dae8b051220fed385ead8e052339 100644 (file)
@@ -109,6 +109,13 @@ bool BluetoothDetector::Init(HWND hNotifyWnd)
    return initialized_;
 }
 
+void BluetoothDetector::Unload()
+{
+   UnloadRadioNotifications();
+   hNotifyWnd_ = NULL;
+   initialized_ = false;
+}
+
 BluetoothDetector::BluetoothStatus BluetoothDetector::GetBluetoothStatus(
    const UINT message, const WPARAM wParam, const LPARAM lParam)
 {
index ca7d655861354045f42ef5dd4ec786875c83ebb7..e6626740dd12cd9e2850df3fdf9405c17e11bccb 100644 (file)
@@ -69,6 +69,9 @@ static LPCWSTR KeyToStr(SettingsKey key)
    case SettingsKey::MUTE_ON_LOGOUT:
       keyStr = _T("MuteOnLogout");
       break;
+   case SettingsKey::MUTE_ON_BLUETOOTH:
+      keyStr = _T("MuteOnBluetooth");
+      break;
    case SettingsKey::MUTE_ON_WLAN:
       keyStr = _T("MuteOnWlan");
       break;
index c0b3722ee56c8272f0617719bd445e0d0be4ec0b..169d2db438fd134a0ff9ed4719d7d6e151574f07 100644 (file)
@@ -44,6 +44,7 @@ enum class SettingsKey {
    , MUTE_ON_SUSPEND
    , MUTE_ON_SHUTDOWN
    , MUTE_ON_LOGOUT
+   , MUTE_ON_BLUETOOTH
    , MUTE_ON_WLAN
    , MUTE_ON_WLAN_ALLOWLIST
    , QUIETHOURS_ENABLE
index dfa859737ae0f70a7f4fc9f83fdec42ca424be53..90a6c2a892ceb850de624c67dad50ce10cb2b8bb 100644 (file)
@@ -135,7 +135,7 @@ static bool IsCurrentSessionRemoteable()
 }
 
 WinMute::MuteConfig::MuteConfig()
-   : muteOnWlan(false), showNotifications(false)
+   : muteOnWlan(false), muteOnBluetooth(false), showNotifications(false)
 {
 }
 
@@ -330,8 +330,23 @@ bool WinMute::LoadSettings()
 
    muteConfig_.showNotifications = settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED);
 
+   muteConfig_.muteOnBluetooth = settings_.QueryValue(SettingsKey::MUTE_ON_BLUETOOTH);
+   if (!muteConfig_.muteOnBluetooth) {
+      btDetector_.Unload();
+   } else if (!btDetector_.Init(hWnd_)) {
+      TaskDialog(nullptr, nullptr, PROGRAM_NAME,
+         _T("Bluetooth not available"),
+         _T("Either the Bluetooth service has not been started, ")
+         _T("or your device is not capable of using bluetooth connections. ")
+         _T("This feature will be disabled for this computer."),
+         TDCBF_OK_BUTTON, TD_INFORMATION_ICON, nullptr);
+      settings_.SetValue(SettingsKey::MUTE_ON_BLUETOOTH, FALSE);
+   }
+
    muteConfig_.muteOnWlan = settings_.QueryValue(SettingsKey::MUTE_ON_WLAN);
-   if (muteConfig_.muteOnWlan) {
+   if (!muteConfig_.muteOnWlan) {
+      wifiDetector_.Unload();
+   } else {
       if (!wifiDetector_.Init(hWnd_)) {
          TaskDialog(nullptr, nullptr, PROGRAM_NAME,
             _T("WLAN not available"),
@@ -345,8 +360,6 @@ bool WinMute::LoadSettings()
          wifiDetector_.SetNetworkList(settings_.GetWifiNetworks(), isMuteList);
          wifiDetector_.CheckNetwork();
       }
-   } else {
-      wifiDetector_.Unload();
    }
 
    return true;
@@ -444,7 +457,7 @@ LRESULT CALLBACK WinMute::WindowProc(
          }
          break;
       }
-      case ID_TRAYMENU_SCREENSUSPEND: {
+      case ID_TRAYMENU_MUTEONSCREENSUSPEND: {
          bool checked = false;
          ToggleMenuCheck(ID_TRAYMENU_SCREENSUSPEND, &checked);
          muteCtrl_.SetMuteOnDisplayStandby(checked);
@@ -467,15 +480,16 @@ LRESULT CALLBACK WinMute::WindowProc(
       }
       case ID_TRAYMENU_MUTEONLOGOUT: {
          bool checked = false;
-         ToggleMenuCheck(ID_TRAYMENU_MUTEONLOGOUT, &checked);
+         ToggleMenuCheck(ID_TRAYMENU_MUTEONBLUETOOTH, &checked);
          muteCtrl_.SetMuteOnLogout(checked);
          settings_.SetValue(SettingsKey::MUTE_ON_LOGOUT, checked);
          break;
       }
       case ID_TRAYMENU_BLUETOOTH: {
          bool checked = false;
-         ToggleMenuCheck(ID_TRAYMENU_MUTEONLOGOUT, &checked);
-         
+         ToggleMenuCheck(ID_TRAYMENU_MUTEON, &checked);
+         settings_.SetValue(SettingsKey::MUTE_ON_BLUETOOTH, checked);
+
          break;
       }
       default:
@@ -566,11 +580,13 @@ LRESULT CALLBACK WinMute::WindowProc(
       return 0;
    }
    case WM_DEVICECHANGE: {
-      const auto btStatus = btDetector_.GetBluetoothStatus(msg, wParam, lParam);
-      if (btStatus == BluetoothDetector::BluetoothStatus::Connected) {
-         MessageBox(hWnd, L"CONNECTED!", NULL, 0);
-      } else if (btStatus == BluetoothDetector::BluetoothStatus::Disconnected) {
-         MessageBox(hWnd, L"DIS-CONNECTED!", NULL, 0);
+      if (muteConfig_.muteOnBluetooth) {
+         const auto btStatus = btDetector_.GetBluetoothStatus(msg, wParam, lParam);
+         if (btStatus == BluetoothDetector::BluetoothStatus::Connected) {
+            muteCtrl_.SetMute(false);
+         } else if (btStatus == BluetoothDetector::BluetoothStatus::Disconnected) {
+            muteCtrl_.SetMute(true);
+         }
       }
       return TRUE;
    }
index a6501efd7a0bc4d623ec28a44e65a9e1a43bb838..47c14b2f7aac41ea0ed934eadc65c8ba83570996 100644 (file)
@@ -57,6 +57,7 @@ private:
       MuteConfig();
       bool showNotifications;
       bool muteOnWlan;
+      bool muteOnBluetooth;
    } muteConfig_;
 
    TrayIcon trayIcon_;
index 8b8dbe09853b8b03bca120df560f46c181589192..589e635d86f4e65f6a913573fb7bac23e30d8983 100644 (file)
@@ -338,8 +338,8 @@ BEGIN
         MENUITEM "Mute when...",                40003, INACTIVE
         MENUITEM "... Workstation is locked",   ID_TRAYMENU_MUTEONLOCK, CHECKED
         MENUITEM "... Screensaver starts",      ID_TRAYMENU_MUTEONSCREENSAVER, CHECKED
-        MENUITEM "... Screen turns off",        ID_TRAYMENU_SCREENSUSPEND, CHECKED
-        MENUITEM "...Bluetooth Device disconnects", ID_TRAYMENU_BLUETOOTH
+        MENUITEM "... Screen turns off",        ID_TRAYMENU_MUTEONSCREENSUSPEND, CHECKED
+        MENUITEM "...Bluetooth Device disconnects", ID_TRAYMENU_MUTEONBLUETOOTH
         MENUITEM SEPARATOR
         MENUITEM "Restore volume afterwards",   ID_TRAYMENU_RESTOREAUDIO, CHECKED
         MENUITEM SEPARATOR
index 62084ac75d86f1917ece21b6e0609ff780fba74a..620db5c88650eb3d12bc36c7413cd5c46c5719b1 100644 (file)
 #define ID_TRAYMENU_40028               40028
 #define ID_TRAYMENU_40029               40029
 #define ID_TRAYMENU_BLUETOOTH           40030
+#define ID_TRAYMENU_MUTEONBLUETOOTH     40031
+#define ID_TRAYMENU_MUTEONSCREENSUSPEND 40032
 
 // Next default values for new objects
 // 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        131
-#define _APS_NEXT_COMMAND_VALUE         40031
+#define _APS_NEXT_COMMAND_VALUE         40033
 #define _APS_NEXT_CONTROL_VALUE         1030
 #define _APS_NEXT_SYMED_VALUE           101
 #endif