[Runner]remove hotkeyEx when disabling a module (#15944)

This commit is contained in:
Jaime Bernardo 2022-02-02 12:17:37 +00:00 committed by GitHub
parent 79c13aec6e
commit 567cc50fb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -149,7 +149,8 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
{
continue;
}
const bool module_inst_enabled = modules().at(name)->is_enabled();
PowertoyModule& powertoy = modules().at(name);
const bool module_inst_enabled = powertoy->is_enabled();
const bool target_enabled = value.GetBoolean();
if (module_inst_enabled == target_enabled)
{
@ -157,12 +158,14 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
}
if (target_enabled)
{
modules().at(name)->enable();
powertoy->enable();
}
else
{
modules().at(name)->disable();
powertoy->disable();
}
// Sync the hotkey state with the module state, so it can be removed for disabled modules.
powertoy.UpdateHotkeyEx();
}
}
@ -221,6 +224,7 @@ void start_enabled_powertoys()
if (!powertoys_to_disable.contains(name))
{
powertoy->enable();
powertoy.UpdateHotkeyEx();
}
}
}

View File

@ -74,11 +74,12 @@ void PowertoyModule::UpdateHotkeyEx()
{
CentralizedHotkeys::UnregisterHotkeysForModule(pt_module->get_key());
auto container = pt_module->GetHotkeyEx();
if (container.has_value())
if (container.has_value() && pt_module->is_enabled())
{
auto hotkey = container.value();
auto modulePtr = pt_module.get();
auto action = [modulePtr](WORD modifiersMask, WORD vkCode) {
Logger::trace(L"{} hotkey Ex is invoked from Centralized keyboard hook", modulePtr->get_key());
modulePtr->OnHotkeyEx();
};