From f3ab51c2e96342b199aa8287e66020dd94c53444 Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Sun, 31 Dec 2023 14:06:40 -0600 Subject: [PATCH] Only fuzzy-match devices that are connected refs #78 --- Sources/BaseMuteAction.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Sources/BaseMuteAction.cpp b/Sources/BaseMuteAction.cpp index 22fc8e8..590fa4e 100644 --- a/Sources/BaseMuteAction.cpp +++ b/Sources/BaseMuteAction.cpp @@ -67,15 +67,17 @@ void from_json(const json& json, MuteActionSettings& settings) { }; }; + settings.fuzzyMatching = json.value("fuzzyMatching", false); settings.feedbackSounds = json.value("feedbackSounds", true); + if (json.contains("toggleKind")) { + settings.toggleKind = json.at("toggleKind"); + } + // Legacy setting if (json.value("ptt", false)) { settings.toggleKind = ToggleKind::TogglePressPttPtmHold; } - if (json.contains("toggleKind")) { - settings.toggleKind = json.at("toggleKind"); - } } static std::string FuzzifyInterface(const std::string& name) { @@ -91,42 +93,47 @@ static std::string FuzzifyInterface(const std::string& name) { std::string MuteActionSettings::VolatileDeviceID() const { const auto specificID = DefaultAudioDevices::GetRealDeviceID(device.id); if (GetAudioDeviceState(specificID) == AudioDeviceState::CONNECTED) { + ESDDebug("Exact match found"); return specificID; } if (!fuzzyMatching) { + ESDDebug("Fuzzy disabled, but no match"); return specificID; } if (device.interfaceName.empty()) { - ESDLog( + ESDDebug( "Would try a fuzzy match, but don't have a saved interface name :'("); return specificID; } const auto fuzzyInterface = FuzzifyInterface(device.interfaceName); - ESDLog( + ESDDebug( "Trying a fuzzy match: '{}' -> '{}'", device.interfaceName, fuzzyInterface); for (const auto& [otherId, otherDevice]: GetAudioDeviceList(device.direction)) { + if (otherDevice.state != AudioDeviceState::CONNECTED) { + continue; + } const auto fuzzyOtherInterface = FuzzifyInterface(otherDevice.interfaceName); - ESDLog( + ESDDebug( "Trying '{}' -> '{}'", otherDevice.interfaceName, fuzzyOtherInterface); if ( fuzzyInterface != fuzzyOtherInterface || device.endpointName != otherDevice.endpointName) { continue; } - ESDLog( + ESDDebug( "Fuzzy device match for {}/{}", device.interfaceName, device.endpointName); return otherId; } - ESDLog( + ESDDebug( "Failed fuzzy match for {}/{}", device.interfaceName, device.endpointName); return device.id; }