| 91 | } |
| 92 | |
| 93 | _Use_decl_annotations_ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, wchar_t *, int) |
| 94 | { |
| 95 | #ifdef _DEBUG |
| 96 | SetThreadDescription(GetCurrentThread(), APP_NAME L" Main Thread"); |
| 97 | #endif |
| 98 | |
| 99 | auto storageFolder = UWP::GetAppStorageFolder(); |
| 100 | Log::Initialize(storageFolder); |
| 101 | HardenProcess(); |
| 102 | |
| 103 | wil::unique_mutex instanceMutex; |
| 104 | bool instanceAlreadyExists = false; |
| 105 | try |
| 106 | { |
| 107 | instanceMutex.create(MUTEX_GUID.c_str(), 0, MAXIMUM_ALLOWED, nullptr, &instanceAlreadyExists); |
| 108 | } |
| 109 | ResultExceptionCatch(spdlog::level::critical, L"Failed to create or open single-instance mutex."); |
| 110 | |
| 111 | if (instanceAlreadyExists) |
| 112 | { |
| 113 | bool suppressNotification = false; |
| 114 | if (storageFolder) |
| 115 | { |
| 116 | const auto eventArgs = wam::AppInstance::GetActivatedEventArgs(); |
| 117 | if (eventArgs) |
| 118 | { |
| 119 | // if an instance got started even earlier, for example by EarlyStart, suppress the notification. |
| 120 | suppressNotification = eventArgs.Kind() == wam::Activation::ActivationKind::StartupTask; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // If there already is another instance running, tell it. |
| 125 | if (!suppressNotification) |
| 126 | { |
| 127 | MainAppWindow::PostNewInstanceNotification(); |
| 128 | } |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | try |
| 134 | { |
| 135 | winrt::init_apartment(winrt::apartment_type::single_threaded); |
| 136 | } |
| 137 | HresultErrorCatch(spdlog::level::critical, L"Initialization of Windows Runtime failed."); |
| 138 | |
| 139 | // Run the main program loop. When this method exits, TranslucentTB itself is about to exit. |
| 140 | const auto ret = Application(hInstance, std::move(storageFolder)).Run(); |
| 141 | |
| 142 | // why are we brutally terminating you might ask? |
| 143 | // Windows.UI.Xaml.dll likes to read null pointers if you exit the app too quickly after |
| 144 | // closing a XAML window. While this is not a big deal for the user since we |
| 145 | // are about to exit and saved everything, it pollutes telemetry and system crash data. |
| 146 | // It's not easily doable to catch SEH exceptions in post-Main DLL unload, so instead just |
| 147 | // brutally terminating will work. |
| 148 | // Caused specifically by ColorPicker, go figure: https://github.com/microsoft/microsoft-ui-xaml/issues/3541 |
| 149 | TerminateProcess(GetCurrentProcess(), ret); |
| 150 |
nothing calls this directly
no test coverage detected