[Toast] Only enable when the component model is initialized

This commit is contained in:
momo5502 2017-03-30 20:55:39 +02:00
parent 0580e59d11
commit ce457b20c6
3 changed files with 17 additions and 7 deletions

View File

@ -18,12 +18,18 @@ namespace Components
return Loader::Postgame; return Loader::Postgame;
} }
bool Loader::IsComInitialized()
{
return Loader::ComInitialized;
}
void Loader::Initialize() void Loader::Initialize()
{ {
Loader::Pregame = true; Loader::Pregame = true;
Loader::Postgame = false; Loader::Postgame = false;
Loader::MemAllocator.clear(); Loader::MemAllocator.clear();
Loader::ComInitialized = false;
if (!Loader::PerformingUnitTests()) Loader::ComInitialized = (CoInitialize(nullptr) == S_OK); if (!Loader::PerformingUnitTests()) Loader::ComInitialized = (CoInitialize(nullptr) == S_OK);
Loader::Register(new Flags()); Loader::Register(new Flags());

View File

@ -32,6 +32,7 @@ namespace Components
static bool IsPregame(); static bool IsPregame();
static bool IsPostgame(); static bool IsPostgame();
static bool IsComInitialized();
static Utils::Memory::Allocator* GetAlloctor(); static Utils::Memory::Allocator* GetAlloctor();

View File

@ -16,7 +16,7 @@ namespace Components
bool Toast::ShowNative(const WinToastLib::WinToastTemplate& toast) bool Toast::ShowNative(const WinToastLib::WinToastTemplate& toast)
{ {
if (!Toast::ToastHandler) return false; if (!Loader::IsComInitialized() || !Toast::ToastHandler) return false;
return WinToastLib::WinToast::instance()->showToast(toast, Toast::ToastHandler); return WinToastLib::WinToast::instance()->showToast(toast, Toast::ToastHandler);
} }
@ -146,13 +146,16 @@ namespace Components
Toast::Toast() Toast::Toast()
{ {
if (Dedicated::IsEnabled() || Monitor::IsEnabled() || Loader::PerformingUnitTests()) return; if (Dedicated::IsEnabled() || Monitor::IsEnabled()) return;
Toast::ToastHandler = new WinToastLib::WinToastHandler; if (Loader::IsComInitialized())
{
Toast::ToastHandler = new WinToastLib::WinToastHandler;
WinToastLib::WinToast::instance()->setAppName(L"IW4x"); WinToastLib::WinToast::instance()->setAppName(L"IW4x");
WinToastLib::WinToast::instance()->setAppUserModelId(WinToastLib::WinToast::configureAUMI(L"IW4x", L"IW4x", L"IW4x", L"0")); WinToastLib::WinToast::instance()->setAppUserModelId(WinToastLib::WinToast::configureAUMI(L"IW4x", L"IW4x", L"IW4x", L"0"));
WinToastLib::WinToast::instance()->initialize(); WinToastLib::WinToast::instance()->initialize();
}
QuickPatch::OnReady([]() QuickPatch::OnReady([]()
{ {
@ -172,7 +175,7 @@ namespace Components
void Toast::preDestroy() void Toast::preDestroy()
{ {
if (Dedicated::IsEnabled() || Monitor::IsEnabled() || Loader::PerformingUnitTests()) return; if (Dedicated::IsEnabled() || Monitor::IsEnabled() || !Loader::IsComInitialized()) return;
// Destroying that on the main thread deadlocks. // Destroying that on the main thread deadlocks.
// I did not write the library, so whatever. // I did not write the library, so whatever.