Skip to content

Commit

Permalink
Something working I guess?
Browse files Browse the repository at this point in the history
  • Loading branch information
Tha14 committed May 17, 2024
1 parent b1ea3f8 commit 8016938
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ CMakeCache.txt

*.tox
imgui.ini
/out
CMakePresets.json
CMakeUserPresets.json
7 changes: 7 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

########################################
Expand Down
37 changes: 37 additions & 0 deletions src/message_n10n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,54 @@

#include <solanaceae/message3/components.hpp>


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<Message::Components::MessageText>()) {
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 {
}
11 changes: 9 additions & 2 deletions src/message_n10n.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <solanaceae/message3/registry_message_model.hpp>

class MessageN10n : public RegistryMessageModelEventI {
#include <wintoastlib.h>

class MessageN10n : public RegistryMessageModelEventI, public WinToastLib::IWinToastHandler {
RegistryMessageModel& _rmm;

public:
Expand All @@ -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;
};

0 comments on commit 8016938

Please sign in to comment.