Skip to content

Commit

Permalink
Fix some incorrect handling of Expected<bool>
Browse files Browse the repository at this point in the history
Updated AudioDeviceLib to ban implicit conversion of Expected<bool> to bool.
  • Loading branch information
fredemmott committed Dec 31, 2023
1 parent be1a72d commit 7995a8d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions AudioDeviceLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ include(FetchContent)
FetchContent_Declare(
AudioDeviceLib
GIT_REPOSITORY https://github.com/fredemmott/AudioDeviceLib
GIT_TAG 7ec63ac88204e93abaec9b17e63ddcd9f4b00abb
GIT_TAG fb7b31b42d331480dce766c83230c905fbb1e540
DOWNLOAD_EXTRACT_TIMESTAMP ON
)

FetchContent_GetProperties(AudioDeviceLib)

if(NOT audiodevicelib_POPULATED)
FetchContent_Populate(AudioDeviceLib)
add_subdirectory("${audiodevicelib_SOURCE_DIR}" "${audiodevicelib_BINARY_DIR}" EXCLUDE_FROM_ALL)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(VERSION_BUILD "${DEFAULT_VERSION_BUILD}" CACHE STRING "patch component of ve

project(
com.fredemmott.micmutetoggle.sdPlugin
VERSION 3.2.0.${VERSION_BUILD}
VERSION 3.3.0.${VERSION_BUILD}
LANGUAGES CXX
)
message(STATUS "Configuring v${CMAKE_PROJECT_VERSION}")
Expand Down
12 changes: 9 additions & 3 deletions Sources/BaseMuteAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,22 @@ void BaseMuteAction::OnPlugEvent(
}

switch (event) {
case AudioDevicePlugEvent::ADDED:
case AudioDevicePlugEvent::ADDED: {
ESDLog("Matching device added");
this->RealDeviceDidChange();
// Windows will now preserve/enforce the state if changed while the
// device is unplugged, but MacOS won't, so we need to update the
// displayed state to match reality
this->MuteStateDidChange(IsAudioDeviceMuted(deviceID));
const auto result = IsAudioDeviceMuted(deviceID);
if (result.has_value()) {
this->MuteStateDidChange(result.value());
}
ShowOK();
return;
}
case AudioDevicePlugEvent::REMOVED:
ESDLog("Matching device removed");
this->RealDeviceDidChange();
ShowAlert();
return;
}
Expand Down Expand Up @@ -203,7 +209,7 @@ void BaseMuteAction::OnMuteStateChanged(
const std::string& device,
bool isMuted) {
auto state = IsAudioDeviceMuted(device);
if (!state) {
if (!state.has_value()) {
ESDDebug(
"Error on real device change: {}", static_cast<int>(state.error()));
ShowAlert();
Expand Down
6 changes: 3 additions & 3 deletions Sources/MuteAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void MuteAction::MuteStateDidChange(bool isMuted) {

void MuteAction::WillAppear() {
auto muteState = IsAudioDeviceMuted(GetRealDeviceID());
if (!muteState) {
if (!muteState.has_value()) {
ShowAlert();
return;
}
Expand All @@ -28,7 +28,7 @@ void MuteAction::WillAppear() {
void MuteAction::DoAction() {
auto deviceID = GetRealDeviceID();
auto muteState = IsAudioDeviceMuted(deviceID);
if (!muteState) {
if (!muteState.has_value()) {
ShowAlert();
return;
}
Expand All @@ -49,5 +49,5 @@ void MuteAction::DoAction() {

void MuteAction::PlayFeedbackSound() {
FredEmmott::Audio::PlayWavFile(
ESDUtilities::GetPluginDirectoryPath() / "mute.wav");
ESDUtilities::GetPluginDirectoryPath() / ESD::filesystem::path { "mute.wav" });
}
6 changes: 3 additions & 3 deletions Sources/ToggleMuteAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void ToggleMuteAction::MuteStateDidChange(bool isMuted) {

void ToggleMuteAction::WillAppear() {
auto muteState = IsAudioDeviceMuted(GetRealDeviceID());
if (!muteState) {
if (!muteState.has_value()) {
ShowAlert();
return;
}
Expand All @@ -35,7 +35,7 @@ void ToggleMuteAction::DoAction() {
const auto device(GetRealDeviceID());

const auto muteState = IsAudioDeviceMuted(device);
if (!muteState) {
if (!muteState.has_value()) {
ShowAlert();
return;
}
Expand Down Expand Up @@ -64,7 +64,7 @@ void ToggleMuteAction::DoAction() {
void ToggleMuteAction::KeyUp() {
if (mPushAndHoldToTalk) {
const auto muteState = IsAudioDeviceMuted(GetRealDeviceID());
if (!muteState) {
if (!muteState.has_value()) {
ShowAlert();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/UnmuteAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void UnmuteAction::MuteStateDidChange(bool isMuted) {

void UnmuteAction::WillAppear() {
const auto muteState = IsAudioDeviceMuted(GetRealDeviceID());
if (!muteState) {
if (!muteState.has_value()) {
ShowAlert();
return;
}
Expand All @@ -31,7 +31,7 @@ void UnmuteAction::WillAppear() {
void UnmuteAction::DoAction() {
const auto device(GetRealDeviceID());
const auto muteState = IsAudioDeviceMuted(device);
if (!muteState) {
if (!muteState.has_value()) {
ShowAlert();
return;
}
Expand Down

0 comments on commit 7995a8d

Please sign in to comment.