mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
[PTRun]Avoid starting two instances from runner (#14868)
* [PTRun]Avoid starting two instances from runner * Set m_enabled later
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include <common/utils/winapi_error.h>
|
#include <common/utils/winapi_error.h>
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -60,6 +61,8 @@ private:
|
|||||||
// Load initial settings from the persisted values.
|
// Load initial settings from the persisted values.
|
||||||
void init_settings();
|
void init_settings();
|
||||||
|
|
||||||
|
bool processStarting = false;
|
||||||
|
std::mutex processStartingMutex;
|
||||||
bool processStarted = false;
|
bool processStarted = false;
|
||||||
|
|
||||||
//contains the name of the powerToys
|
//contains the name of the powerToys
|
||||||
@@ -204,8 +207,25 @@ public:
|
|||||||
// Enable the powertoy
|
// Enable the powertoy
|
||||||
virtual void enable()
|
virtual void enable()
|
||||||
{
|
{
|
||||||
Logger::info("Microsoft_Launcher::enable()");
|
Logger::info("Microsoft_Launcher::enable() begin");
|
||||||
m_enabled = true;
|
|
||||||
|
// This synchronization code is here since we've seen logs of this function being entered twice in the same process/thread pair.
|
||||||
|
// The theory here is that the call to ShellExecuteExW might be enabling some context switching that allows the low level keyboard hook to be run.
|
||||||
|
// Ref: https://github.com/microsoft/PowerToys/issues/12908#issuecomment-986995633
|
||||||
|
// We want only one instance to be started at the same time.
|
||||||
|
processStartingMutex.lock();
|
||||||
|
if (processStarting)
|
||||||
|
{
|
||||||
|
processStartingMutex.unlock();
|
||||||
|
Logger::warn(L"Two PowerToys Run processes were trying to get started at the same time.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
processStarting = true;
|
||||||
|
processStartingMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
ResetEvent(m_hCentralizedKeyboardHookEvent);
|
ResetEvent(m_hCentralizedKeyboardHookEvent);
|
||||||
ResetEvent(send_telemetry_event);
|
ResetEvent(send_telemetry_event);
|
||||||
|
|
||||||
@@ -264,6 +284,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
processStarting = false;
|
||||||
|
m_enabled = true;
|
||||||
|
Logger::info("Microsoft_Launcher::enable() end");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable the powertoy
|
// Disable the powertoy
|
||||||
|
|||||||
Reference in New Issue
Block a user