]> repos.lx-s.de Git - winmute.git/commitdiff
Added notifications for bt muting
authorlx-s <lx-s@users.noreply.github.com>
Mon, 1 Aug 2022 14:46:45 +0000 (16:46 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Mon, 1 Aug 2022 14:46:45 +0000 (16:46 +0200)
WinMute/Settings_BluetoothDlg.cpp
WinMute/WinMute.cpp

index 7f2723dc622bdc7e2fd883b6c01e86aa6342163a..b2da0859c7e5ffb5377b80844ed8aa6cec1a7c94 100644 (file)
@@ -117,16 +117,14 @@ static INT_PTR CALLBACK Settings_BluetoothAddDlgProc(HWND hDlg, UINT msg, WPARAM
             ebt.pszTitle = _T("Bluetooth Device Name");
             ebt.ttiIcon = TTI_INFO;
             Edit_ShowBalloonTip(hDevName, &ebt);
-         }
-         else {
+         } else {
             TCHAR devNameBuf[BT_DEV_NAME_MAX_LEN + 1];
             BtDeviceName* btDevName = reinterpret_cast<BtDeviceName*>(GetWindowLongPtr(hDlg, GWLP_USERDATA));
             if (btDevName != nullptr) {
                Edit_GetText(hDevName, devNameBuf, ARRAY_SIZE(devNameBuf));
                btDevName->devName = devNameBuf;
                EndDialog(hDlg, 0);
-            }
-            else {
+            } else { 
                EndDialog(hDlg, 1);
             }
          }
@@ -223,8 +221,7 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L
       if (LOWORD(wParam) == IDC_ENABLE_BLUETOOTH_MUTE) {
          DWORD checked = Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLE_BLUETOOTH_MUTE));
          Button_Enable(GetDlgItem(hDlg, IDC_ENABLE_BLUETOOTH_MUTE_DEVICE_LIST), checked == BST_CHECKED);
-      }
-      else if (LOWORD(wParam) == IDC_BLUETOOTH_LIST) {
+      } else if (LOWORD(wParam) == IDC_BLUETOOTH_LIST) {
          HWND hList = GetDlgItem(hDlg, IDC_BLUETOOTH_LIST);
          if (HIWORD(wParam) == LBN_SELCHANGE || HIWORD(wParam) == LBN_SELCANCEL) {
             bool entrySelected = (ListBox_GetCurSel(hList) != LB_ERR);
@@ -236,8 +233,7 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L
             Button_Enable(GetDlgItem(hDlg, IDC_BLUETOOTH_EDIT), entrySelected);
             Button_Enable(GetDlgItem(hDlg, IDC_BLUETOOTH_REMOVE), entrySelected);
          }
-      }
-      else if (LOWORD(wParam) == IDC_BLUETOOTH_ADD) {
+      } else if (LOWORD(wParam) == IDC_BLUETOOTH_ADD) {
          BtDeviceName btDeviceName;
          if (DialogBoxParam(
                NULL,
@@ -256,8 +252,7 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L
                }
             }
          }
-      }
-      else if (LOWORD(wParam) == IDC_BLUETOOTH_EDIT) {
+      } else if (LOWORD(wParam) == IDC_BLUETOOTH_EDIT) {
          HWND hList = GetDlgItem(hDlg, IDC_BLUETOOTH_LIST);
          WPARAM sel = ListBox_GetCurSel(hList);
          if (sel != LB_ERR) {
@@ -289,9 +284,8 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L
                }
             }
          }
-      }
-      else if (LOWORD(wParam) == IDC_WIFI_REMOVE) {
-         HWND hList = GetDlgItem(hDlg, IDC_WIFI_LIST);
+      } else if (LOWORD(wParam) == IDC_BLUETOOTH_REMOVE) {
+         HWND hList = GetDlgItem(hDlg, IDC_BLUETOOTH_LIST);
          WPARAM sel = ListBox_GetCurSel(hList);
          if (sel != LB_ERR) {
             ListBox_DeleteString(hList, sel);
@@ -301,8 +295,7 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L
                Button_Enable(GetDlgItem(hDlg, IDC_BLUETOOTH_REMOVEALL), FALSE);
             }
          }
-      }
-      else if (LOWORD(wParam) == IDC_BLUETOOTH_REMOVEALL) {
+      } else if (LOWORD(wParam) == IDC_BLUETOOTH_REMOVEALL) {
          ListBox_ResetContent(GetDlgItem(hDlg, IDC_BLUETOOTH_LIST));
          Button_Enable(GetDlgItem(hDlg, IDC_BLUETOOTH_EDIT), FALSE);
          Button_Enable(GetDlgItem(hDlg, IDC_BLUETOOTH_REMOVE), FALSE);
index 9e75d7f1275f3e35e7e2e8793bc869cf6f1fd290..ec8f7a6fa5583057147aab77ad1434191809f6d8 100644 (file)
@@ -322,12 +322,17 @@ bool WinMute::LoadSettings()
    muteConfig_.muteOnBluetooth = settings_.QueryValue(SettingsKey::MUTE_ON_BLUETOOTH);
    if (!muteConfig_.muteOnBluetooth) {
       btDetector_.Unload();
-   } else if (!btDetector_.Init(hWnd_)) {
-      trayIcon_.ShowPopup(
-         _T("Bluetooth muting disabled"),
-         _T("Bluetooth is not available or disabled. ")
-         _T("Bluetooth muting will be disabled on this computer"));
-      settings_.SetValue(SettingsKey::MUTE_ON_BLUETOOTH, FALSE);
+   } else {
+      if (!btDetector_.Init(hWnd_)) {
+         trayIcon_.ShowPopup(
+            _T("Bluetooth muting disabled"),
+            _T("Bluetooth is not available or disabled. ")
+            _T("Bluetooth muting will be disabled on this computer"));
+         settings_.SetValue(SettingsKey::MUTE_ON_BLUETOOTH, FALSE);
+      } else {
+         bool muteOnWithDeviceList = settings_.QueryValue(SettingsKey::MUTE_ON_BLUETOOTH_DEVICELIST);
+         btDetector_.SetDeviceList(settings_.GetBluetoothDevicesA(), muteOnWithDeviceList);
+      }
    }
 
    muteConfig_.muteOnWlan = settings_.QueryValue(SettingsKey::MUTE_ON_WLAN);
@@ -568,8 +573,18 @@ LRESULT CALLBACK WinMute::WindowProc(
       if (muteConfig_.muteOnBluetooth) {
          const auto btStatus = btDetector_.GetBluetoothStatus(msg, wParam, lParam);
          if (btStatus == BluetoothDetector::BluetoothStatus::Connected) {
+            if (settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED)) {
+               trayIcon_.ShowPopup(
+                  _T("Bluetooth muting"),
+                  _T("Bluetooth device connected: Restoring audio"));
+            }
             muteCtrl_.SetMute(false);
          } else if (btStatus == BluetoothDetector::BluetoothStatus::Disconnected) {
+            if (settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED)) {
+               trayIcon_.ShowPopup(
+                  _T("Bluetooth muting"),
+                  _T("Bluetooth device disconnected: Muting"));
+            }
             muteCtrl_.SetMute(true);
          }
       }