PowerToys/src/modules/fancyzones/FancyZones/main.cpp
Seraphima Zykova c93eb92cd0
[FancyZones] Move FancyZones out of the runner process (#11818)
* rename dll -> FancyZonesModuleInterface (#11488)

* [FancyZones] Rename "fancyzones/tests" -> "fancyzones/FancyZonesTests" (#11492)

* [FancyZones] Rename "fancyzones/lib" -> "fancyzones/FancyZonesLib" (#11489)

* [FancyZones] New FancyZones project. (#11544)

* [FancyZones] Allow single instance of "PowerToys.FancyZones.exe" (#11558)

* [FancyZones] Updated bug reports (#11571)

* [FancyZones] Updated installer (#11572)

* [FancyZones] Update string resources (#11596)

* [FancyZones] Terminate FancyZones with runner (#11696)

* [FancyZones] Drop support for the module interface API to save settings (#11661)

* Settings telemetry for FancyZones (#11766)

* commented out test

* enable dpi awareness for the process
2021-06-23 13:48:54 +01:00

74 lines
2.1 KiB
C++

#include "pch.h"
#include <common/utils/ProcessWaiter.h>
#include <common/utils/window.h>
#include <common/utils/UnhandledExceptionHandler_x64.h>
#include <FancyZonesLib/trace.h>
#include <FancyZonesLib/Generated Files/resource.h>
#include <common/utils/logger_helper.h>
#include <common/hooks/LowlevelKeyboardEvent.h>
#include <common/utils/resources.h>
#include <FancyZonesLib/FancyZones.h>
#include <FancyZonesLib/FancyZonesData.h>
#include <FancyZonesLib/FancyZonesWinHookEventIDs.h>
#include <FancyZonesApp.h>
// Non-localizable
const std::wstring moduleName = L"FancyZones";
const std::wstring internalPath = L"";
const std::wstring instanceMutexName = L"Local\\PowerToys_FancyZones_InstanceMutex";
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ PWSTR lpCmdLine, _In_ int nCmdShow)
{
winrt::init_apartment();
InitUnhandledExceptionHandler_x64();
LoggerHelpers::init_logger(moduleName, internalPath, LogSettings::fancyZonesLoggerName);
auto mutex = CreateMutex(nullptr, true, instanceMutexName.c_str());
if (mutex == nullptr)
{
Logger::error(L"Failed to create mutex. {}", get_last_error_or_default(GetLastError()));
}
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
Logger::warn(L"FancyZones instance is already running");
return 0;
}
std::wstring pid = std::wstring(lpCmdLine);
if (!pid.empty())
{
auto mainThreadId = GetCurrentThreadId();
ProcessWaiter::OnProcessTerminate(pid, [mainThreadId](int err) {
if (err != ERROR_SUCCESS)
{
Logger::error(L"Failed to wait for parent process exit. {}", get_last_error_or_default(err));
}
else
{
Logger::trace(L"PowerToys runner exited.");
}
Logger::trace(L"Exiting FancyZones");
PostThreadMessage(mainThreadId, WM_QUIT, 0, 0);
});
}
Trace::RegisterProvider();
FancyZonesApp app(GET_RESOURCE_STRING(IDS_FANCYZONES), NonLocalizable::FancyZonesStr);
app.Run();
run_message_loop();
Trace::UnregisterProvider();
return 0;
}