From d3305a10ddcf11ed9559d9a3421b6c06b826aca2 Mon Sep 17 00:00:00 2001 From: lx-s Date: Mon, 1 Aug 2022 16:46:45 +0200 Subject: [PATCH] Added notifications for bt muting --- WinMute/Settings_BluetoothDlg.cpp | 23 ++++++++--------------- WinMute/WinMute.cpp | 27 +++++++++++++++++++++------ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/WinMute/Settings_BluetoothDlg.cpp b/WinMute/Settings_BluetoothDlg.cpp index 7f2723d..b2da085 100644 --- a/WinMute/Settings_BluetoothDlg.cpp +++ b/WinMute/Settings_BluetoothDlg.cpp @@ -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(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); diff --git a/WinMute/WinMute.cpp b/WinMute/WinMute.cpp index 9e75d7f..ec8f7a6 100644 --- a/WinMute/WinMute.cpp +++ b/WinMute/WinMute.cpp @@ -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); } } -- 2.43.0