This commit is contained in:
Mykhailo Pylyp
2021-03-26 19:17:26 +02:00
committed by GitHub
parent 5baf11dada
commit 9a3896f48a
3 changed files with 11 additions and 0 deletions

View File

@@ -345,6 +345,12 @@ public:
void terminateProcess()
{
Logger::trace(L"Terminating PowerToys Run process. Handle {}.", m_hProcess);
if (WaitForSingleObject(m_hProcess, 0) == WAIT_OBJECT_0)
{
Logger::warn("PowerToys Run has exited unexpectedly, so there is no need to terminate it.");
return;
}
DWORD processID = GetProcessId(m_hProcess);
if (TerminateProcess(m_hProcess, 1) == 0)
{

View File

@@ -2,6 +2,7 @@
#include "centralized_kb_hook.h"
#include <common/debug_control.h>
#include <common/utils/winapi_error.h>
#include <common/logger/logger.h>
namespace CentralizedKeyboardHook
{
@@ -79,12 +80,14 @@ namespace CentralizedKeyboardHook
void SetHotkeyAction(const std::wstring& moduleName, const Hotkey& hotkey, std::function<bool()>&& action) noexcept
{
Logger::trace(L"Register hotkey action for {}", moduleName);
std::unique_lock lock{ mutex };
hotkeyDescriptors.insert({ .hotkey = hotkey, .moduleName = moduleName, .action = std::move(action) });
}
void ClearModuleHotkeys(const std::wstring& moduleName) noexcept
{
Logger::trace(L"UnRegister hotkey action for {}", moduleName);
std::unique_lock lock{ mutex };
auto it = hotkeyDescriptors.begin();
while (it != hotkeyDescriptors.end())

View File

@@ -1,6 +1,7 @@
#include "pch.h"
#include "powertoy_module.h"
#include "centralized_kb_hook.h"
#include <common/logger/logger.h>
std::map<std::wstring, PowertoyModule>& modules()
{
@@ -60,6 +61,7 @@ void PowertoyModule::update_hotkeys()
for (size_t i = 0; i < hotkeyCount; i++)
{
CentralizedKeyboardHook::SetHotkeyAction(pt_module->get_key(), hotkeys[i], [modulePtr, i] {
Logger::trace(L"{} hotkey is invoked from Centralized keyboard hook", modulePtr->get_key());
return modulePtr->on_hotkey(i);
});
}