[VCM]Add options to hide after timeout and startup action (#28658)

* VideoConference add new option ToolbarHide After timeout

* VideoConference add new behavior option startup action
This commit is contained in:
Quyen Le Van
2023-10-06 14:48:36 +07:00
committed by GitHub
parent 03ad83836d
commit 99882508bc
9 changed files with 148 additions and 12 deletions

View File

@@ -50,12 +50,12 @@ bool VideoConferenceModule::isHotkeyPressed(DWORD code, PowerToysSettings::Hotke
void VideoConferenceModule::reverseMicrophoneMute()
{
bool muted = false;
// All controlled mic should same state with _microphoneTrackedInUI
// Avoid manually change in Control Panel make controlled mic has different state
bool muted = !getMicrophoneMuteState();
for (auto& controlledMic : instance->_controlledMicrophones)
{
const bool was_muted = controlledMic->muted();
controlledMic->toggle_muted();
muted = muted || !was_muted;
controlledMic->set_muted(muted);
}
if (muted)
{
@@ -283,6 +283,10 @@ void VideoConferenceModule::onModuleSettingsChanged()
{
toolbar.setToolbarHide(val.value());
}
if (const auto val = values.get_string_value(L"startup_action"))
{
settings.startupAction = val.value();
}
const auto selectedMic = values.get_string_value(L"selected_mic");
if (selectedMic && selectedMic != settings.selectedMicrophone)
@@ -308,7 +312,7 @@ void VideoConferenceModule::onMicrophoneConfigurationChanged()
return;
}
const bool mutedStateForNewMics = _microphoneTrackedInUI ? _microphoneTrackedInUI->muted() : _mic_muted_state_during_disconnect;
const bool mutedStateForNewMics = getMicrophoneMuteState();
std::unordered_set<std::wstring_view> currentlyTrackedMicsIds;
for (const auto& controlledMic : _controlledMicrophones)
{
@@ -338,6 +342,7 @@ void VideoConferenceModule::onMicrophoneConfigurationChanged()
toolbar.setMicrophoneMute(muted);
});
}
setMuteChangedCallback();
}
VideoConferenceModule::VideoConferenceModule()
@@ -401,6 +406,25 @@ void VideoConferenceModule::set_config(const wchar_t* config)
}
}
void VideoConferenceModule::setMuteChangedCallback()
{
// Keep all controlledMic mute state same _microphoneTrackedInUI
// Should not change manually in Control Panel
for (const auto& controlledMic : _controlledMicrophones)
{
if (controlledMic->id() != _microphoneTrackedInUI->id())
{
controlledMic->set_mute_changed_callback([&](const bool muted) {
auto muteState = getMicrophoneMuteState();
if (muted != muteState)
{
controlledMic->set_muted(muteState);
}
});
}
}
}
void VideoConferenceModule::init_settings()
{
try
@@ -447,6 +471,10 @@ void VideoConferenceModule::init_settings()
{
toolbar.setToolbarHide(val.value());
}
if (const auto val = powerToysSettings.get_string_value(L"startup_action"))
{
settings.startupAction = val.value();
}
if (const auto val = powerToysSettings.get_string_value(L"selected_mic"); val && *val != settings.selectedMicrophone)
{
settings.selectedMicrophone = *val;
@@ -509,6 +537,22 @@ void VideoConferenceModule::updateControlledMicrophones(const std::wstring_view
});
toolbar.setMicrophoneMute(_microphoneTrackedInUI->muted());
}
if (settings.startupAction == L"Unmute")
{
for (auto& controlledMic : _controlledMicrophones)
{
controlledMic->set_muted(false);
}
}
else if (settings.startupAction == L"Mute")
{
for (auto& controlledMic : _controlledMicrophones)
{
controlledMic->set_muted(true);
}
}
setMuteChangedCallback();
}
MicrophoneDevice* VideoConferenceModule::controlledDefaultMic()
@@ -669,6 +713,14 @@ void VideoConferenceModule::sendSourceCameraNameUpdate()
auto updatesChannel = reinterpret_cast<CameraSettingsUpdateChannel*>(memory._data);
updatesChannel->sourceCameraName.emplace();
std::copy(begin(settings.selectedCamera), end(settings.selectedCamera), begin(*updatesChannel->sourceCameraName));
if (settings.startupAction == L"Unmute")
{
updatesChannel->useOverlayImage = false;
}
else if (settings.startupAction == L"Mute")
{
updatesChannel->useOverlayImage = true;
}
});
}

View File

@@ -30,6 +30,8 @@ struct VideoConferenceSettings
std::wstring imageOverlayPath;
std::wstring selectedMicrophone;
std::wstring startupAction;
bool pushToReverseEnabled = false;
};
@@ -71,6 +73,7 @@ public:
private:
void setMuteChangedCallback();
void init_settings();
void updateControlledMicrophones(const std::wstring_view new_mic);
MicrophoneDevice* controlledDefaultMic();

View File

@@ -53,11 +53,6 @@ bool MicrophoneDevice::muted() const noexcept
return muted;
}
void MicrophoneDevice::toggle_muted() noexcept
{
set_muted(!muted());
}
std::wstring_view MicrophoneDevice::id() const noexcept
{
return _id ? _id.get() : FALLBACK_ID;
@@ -70,6 +65,10 @@ std::wstring_view MicrophoneDevice::name() const noexcept
void MicrophoneDevice::set_mute_changed_callback(mute_changed_cb_t callback) noexcept
{
if (_notifier)
{
_endpoint->UnregisterControlChangeNotify(_notifier.get());
}
_mute_changed_callback = std::move(callback);
_notifier = winrt::make<VolumeNotifier>(this);

View File

@@ -54,7 +54,6 @@ public:
bool active() const noexcept;
void set_muted(const bool muted) noexcept;
bool muted() const noexcept;
void toggle_muted() noexcept;
std::wstring_view id() const noexcept;
std::wstring_view name() const noexcept;