diff --git a/.gitignore b/.gitignore index 56f48bf..d2cb415 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ CMakeCache.txt *.tox imgui.ini +/out +CMakePresets.json +CMakeUserPresets.json \ No newline at end of file diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index a65aa38..7ad3b2c 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -20,3 +20,10 @@ if (NOT TARGET solanaceae_plugin) FetchContent_MakeAvailable(solanaceae_plugin) endif() +if (NOT TARGET WinToast) + FetchContent_Declare(WinToast_ext + GIT_REPOSITORY https://github.com/mohabouje/WinToast.git + GIT_TAG master + ) + FetchContent_MakeAvailable(WinToast_ext) +endif() \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7273bae..5655037 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,7 @@ target_include_directories(solanaceae_message_n10n PUBLIC .) target_compile_features(solanaceae_message_n10n PUBLIC cxx_std_17) target_link_libraries(solanaceae_message_n10n PUBLIC solanaceae_message3 + WinToast ) ######################################## diff --git a/src/message_n10n.cpp b/src/message_n10n.cpp index 49f0971..d98cc9a 100644 --- a/src/message_n10n.cpp +++ b/src/message_n10n.cpp @@ -2,17 +2,54 @@ #include + MessageN10n::MessageN10n(RegistryMessageModel& rmm) : _rmm(rmm) { + // Register WinToast App User Model + WinToastLib::WinToast::instance()->setAppName(L"Tomato"); + const auto aumi = WinToastLib::WinToast::configureAUMI(L"green", L"solanaceae", L"solanaceae_message_n10n", L"20240517"); + WinToastLib::WinToast::instance()->setAppUserModelId(aumi); + + // Initialize WinToast + if (!WinToastLib::WinToast::instance()->initialize()) { + std::wcout << L"Error, could not initialize the lib!" << std::endl; + } else { + _rmm.subscribe(this, RegistryMessageModel_Event::message_construct); + } } MessageN10n::~MessageN10n(void) { } bool MessageN10n::onEvent(const Message::Events::MessageConstruct& e) { + /* if (!e.e.all_of()) { return false; } + */ + + auto templ = WinToastLib::WinToastTemplate(WinToastLib::WinToastTemplate::Text02); + templ.setTextField(L"title", WinToastLib::WinToastTemplate::FirstLine); + templ.setTextField(L"subtitle", WinToastLib::WinToastTemplate::SecondLine); + + WinToastLib::WinToast::WinToastError error; + const auto toast_id = WinToastLib::WinToast::instance()->showToast(templ, this, &error); + if (toast_id < 0) { + std::wcout << L"Error: Could not launch your toast notification! " << error << std::endl; + } return false; } +void MessageN10n::toastActivated(void) const { + // action +} + +void MessageN10n::toastActivated(int actionIndex) const { + // action +} + +void MessageN10n::toastDismissed(WinToastDismissalReason) const { +} + +void MessageN10n::toastFailed(void) const { +} \ No newline at end of file diff --git a/src/message_n10n.hpp b/src/message_n10n.hpp index c1e071a..1ed7c7a 100644 --- a/src/message_n10n.hpp +++ b/src/message_n10n.hpp @@ -2,7 +2,9 @@ #include -class MessageN10n : public RegistryMessageModelEventI { +#include + +class MessageN10n : public RegistryMessageModelEventI, public WinToastLib::IWinToastHandler { RegistryMessageModel& _rmm; public: @@ -11,5 +13,10 @@ class MessageN10n : public RegistryMessageModelEventI { protected: // rmm bool onEvent(const Message::Events::MessageConstruct& e) override; -}; + protected: // wintoast + void toastActivated(void) const override; + void toastActivated(int actionIndex) const override; + void toastDismissed(WinToastDismissalReason state) const override; + void toastFailed(void) const override; +};