Skip to content

Commit

Permalink
some sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky committed Jun 21, 2024
1 parent f5e7e7d commit be2885e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 4 additions & 3 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR)

add_library(plugin_message_n10n SHARED
add_library(plugin_message_n10n MODULE
./plugin_message_n10n.cpp
)

Expand All @@ -9,8 +9,9 @@ target_link_libraries(plugin_message_n10n PUBLIC
solanaceae_message_n10n
)

set_target_properties(plugin_message_n10n PROPERTIES
C_VISIBILITY_PRESET hidden
)
# probably not enough
target_compile_definitions(plugin_message_n10n PUBLIC ENTT_API_IMPORT)

set_target_properties(plugin_message_n10n PROPERTIES POSITION_INDEPENDENT_CODE ON)

18 changes: 16 additions & 2 deletions src/message_n10n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class OurHandler : public WinToastLib::IWinToastHandler {
public:
virtual ~OurHandler(void) {
virtual ~OurHandler(void) override {
}

protected: // wintoast
Expand Down Expand Up @@ -58,16 +58,30 @@ bool MessageN10n::onEvent(const Message::Events::MessageConstruct& e) {
return false;
}

const auto& text = e.e.get<Message::Components::MessageText>().text;
if (text.empty()) {
return false;
}

const auto sender_c = e.e.get<Message::Components::ContactFrom>().c;

if (_cr.all_of<Contact::Components::TagSelfStrong>(sender_c)) {
return false;
}
if (!_cr.all_of<
Contact::Components::Name
>(sender_c)) {
return false;
}

std::string title {
_cr.get<Contact::Components::Name>(sender_c).name
};

if (title.empty()) {
return false;
}

auto templ = WinToastLib::WinToastTemplate(WinToastLib::WinToastTemplate::Text02);
templ.setTextField(
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>{}.from_bytes(
Expand All @@ -77,7 +91,7 @@ bool MessageN10n::onEvent(const Message::Events::MessageConstruct& e) {
);
templ.setTextField(
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>{}.from_bytes(
e.e.get<Message::Components::MessageText>().text
text
),
WinToastLib::WinToastTemplate::SecondLine
);
Expand Down

0 comments on commit be2885e

Please sign in to comment.