[Toast] Support for native toast notifications
This commit is contained in:
parent
2f3e665c89
commit
1b7aea6780
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -35,3 +35,6 @@
|
||||
path = deps/protobuf
|
||||
url = https://github.com/google/protobuf.git
|
||||
branch = 3.2.x
|
||||
[submodule "deps/WinToast"]
|
||||
path = deps/WinToast
|
||||
url = https://github.com/mohabouje/WinToast.git
|
||||
|
1
deps/WinToast
vendored
Submodule
1
deps/WinToast
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit a9771a2b43d93e18227fae5ecee92d6b9eb6f2bb
|
45
premake/WinToast.lua
Normal file
45
premake/WinToast.lua
Normal file
@ -0,0 +1,45 @@
|
||||
WinToast = {
|
||||
settings = nil,
|
||||
}
|
||||
|
||||
function WinToast.setup(settings)
|
||||
if not settings.source then error("Missing source.") end
|
||||
|
||||
WinToast.settings = settings
|
||||
end
|
||||
|
||||
function WinToast.import()
|
||||
if not WinToast.settings then error("Run WinToast.setup first") end
|
||||
|
||||
links { "WinToast" }
|
||||
WinToast.includes()
|
||||
end
|
||||
|
||||
function WinToast.includes()
|
||||
if not WinToast.settings then error("Run WinToast.setup first") end
|
||||
|
||||
includedirs { path.join(WinToast.settings.source, "src"), }
|
||||
end
|
||||
|
||||
function WinToast.project()
|
||||
if not WinToast.settings then error("Run WinToast.setup first") end
|
||||
|
||||
project "WinToast"
|
||||
language "C++"
|
||||
|
||||
includedirs
|
||||
{
|
||||
WinToast.settings.source,
|
||||
}
|
||||
|
||||
files
|
||||
{
|
||||
path.join(WinToast.settings.source, "src/*.cpp"),
|
||||
path.join(WinToast.settings.source, "src/*.h"),
|
||||
}
|
||||
|
||||
-- not our code, ignore POSIX usage warnings for now
|
||||
warnings "Off"
|
||||
|
||||
kind "StaticLib"
|
||||
end
|
10
premake5.lua
10
premake5.lua
@ -199,7 +199,7 @@ require "premake/pdcurses"
|
||||
require "premake/protobuf"
|
||||
require "premake/sqlite3"
|
||||
require "premake/zlib"
|
||||
require "premake/boost"
|
||||
require "premake/WinToast"
|
||||
|
||||
base128.setup
|
||||
{
|
||||
@ -256,9 +256,9 @@ zlib.setup
|
||||
},
|
||||
source = path.join(depsBasePath, "zlib"),
|
||||
}
|
||||
boost.setup
|
||||
WinToast.setup
|
||||
{
|
||||
source = path.join(depsBasePath, "boost"),
|
||||
source = path.join(depsBasePath, "WinToast"),
|
||||
}
|
||||
|
||||
workspace "iw4x"
|
||||
@ -366,7 +366,7 @@ workspace "iw4x"
|
||||
pdcurses.import()
|
||||
protobuf.import()
|
||||
zlib.import()
|
||||
boost.import()
|
||||
WinToast.import()
|
||||
|
||||
-- fix vpaths for protobuf sources
|
||||
vpaths
|
||||
@ -485,7 +485,7 @@ workspace "iw4x"
|
||||
pdcurses.project()
|
||||
protobuf.project()
|
||||
zlib.project()
|
||||
boost.project()
|
||||
WinToast.project()
|
||||
|
||||
rule "ProtobufCompiler"
|
||||
display "Protobuf compiler"
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user