[Toast] Support for native toast notifications

This commit is contained in:
momo5502
2017-02-18 17:25:54 +01:00
parent 2f3e665c89
commit 1b7aea6780
8 changed files with 92 additions and 5 deletions

View File

@ -18,6 +18,8 @@ namespace Components
Loader::Postgame = false;
Loader::MemAllocator.clear();
CoInitialize(nullptr);
Loader::Register(new Flags());
Loader::Register(new Singleton());
Loader::Register(new Exception()); // install our exception handler as early as posssible to get better debug dumps from startup crashes
@ -107,6 +109,8 @@ namespace Components
Loader::Components.clear();
Loader::MemAllocator.clear();
CoUninitialize();
}
void Loader::PreDestroy()

View File

@ -5,6 +5,8 @@ namespace Components
std::queue<Toast::UIToast> Toast::Queue;
std::mutex Toast::Mutex;
WinToastLib::WinToastHandler* Toast::ToastHandler = nullptr;
void Toast::Show(std::string image, std::string title, std::string description, int length)
{
Toast::Mutex.lock();
@ -12,6 +14,12 @@ namespace Components
Toast::Mutex.unlock();
}
bool Toast::ShowNative(const WinToastLib::WinToastTemplate& toast)
{
if (!Toast::ToastHandler) return false;
return WinToastLib::WinToast::instance()->showToast(toast, Toast::ToastHandler);
}
void Toast::Draw(UIToast* toast)
{
if (!toast) return;
@ -125,6 +133,12 @@ namespace Components
Toast::Toast()
{
Toast::ToastHandler = new WinToastLib::WinToastHandler;
WinToastLib::WinToast::instance()->setAppName(L"IW4x");
WinToastLib::WinToast::instance()->setAppUserModelId(WinToastLib::WinToast::configureAUMI(L"IW4x", L"IW4x", L"IW4x", L"0"));
WinToastLib::WinToast::instance()->initialize();
QuickPatch::OnReady([]()
{
Renderer::OnFrame(Toast::Handler);
@ -140,4 +154,16 @@ namespace Components
{
Toast::Queue = std::queue<Toast::UIToast>();
}
void Toast::preDestroy()
{
// Destroying that on the main thread deadlocks, for whatever reason.
// I did not write the library, so whatever.
std::thread([]()
{
delete WinToastLib::WinToast::instance();
delete Toast::ToastHandler;
Toast::ToastHandler = nullptr;
}).join();
}
}

View File

@ -7,12 +7,16 @@ namespace Components
public:
Toast();
~Toast();
void preDestroy() override;
typedef WinToastLib::WinToastTemplate Template;
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
const char* getName() override { return "Toast"; };
#endif
static void Show(std::string image, std::string title, std::string description, int length);
static bool ShowNative(const WinToastLib::WinToastTemplate& toast);
private:
class UIToast
@ -30,5 +34,7 @@ namespace Components
static std::queue<UIToast> Queue;
static std::mutex Mutex;
static WinToastLib::WinToastHandler* ToastHandler;
};
}

View File

@ -47,6 +47,7 @@ template <size_t S> class Sizer { };
// Ignore the warnings, it's no our code!
#pragma warning(push)
#pragma warning(disable: 4005)
#pragma warning(disable: 4091)
#pragma warning(disable: 4100)
#pragma warning(disable: 4389)
#pragma warning(disable: 4702)
@ -67,6 +68,7 @@ template <size_t S> class Sizer { };
#ifndef DISABLE_BITMESSAGE
#include <BitMRC.h>
#endif
#include <wintoastlib.h>
#ifdef max
#undef max