From e317569057efd23e15fb5546fa00b063c1136abc Mon Sep 17 00:00:00 2001 From: Igor Sikachyna Date: Mon, 12 Jul 2021 16:04:31 +0300 Subject: [PATCH] SYNERGY-1060 - Toast notifications on windows (#7052) * SYNERGY-1060 - Add toast notification library for Windows * SYNERGY-1060 - Use unique_ptr * SYNERGY-1060 - Update changelog * SYNERGY-1061 Toast notifications on windows Co-authored-by: SerhiiGadzhilov <71632867+SerhiiGadzhilov@users.noreply.github.com> Co-authored-by: Serhii Hadzhilov --- .gitmodules | 3 ++ ChangeLog | 1 + ext/WinToast | 1 + src/lib/synergy/CMakeLists.txt | 4 ++- src/lib/synergy/win32/AppUtilWindows.cpp | 39 ++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 160000 ext/WinToast diff --git a/.gitmodules b/.gitmodules index a4a68a061..ba1a5ef6e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "ext/googletest"] path = ext/googletest url = https://github.com/google/googletest.git +[submodule "ext/WinToast"] + path = ext/WinToast + url = https://github.com/mohabouje/WinToast diff --git a/ChangeLog b/ChangeLog index 67e1aed12..5387415a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ Bug fixes: - #7036 Fix tray icon not changing theme on Big Sur - #7046 Fix MacOS 10.13 build - #7049 Scroll doesn't work in case of macOS is server +- #7052 Add secure input notification on Windows - #7047 Fix prevent sleep option on Mac and Windows Enhancements: diff --git a/ext/WinToast b/ext/WinToast new file mode 160000 index 000000000..8abb85b44 --- /dev/null +++ b/ext/WinToast @@ -0,0 +1 @@ +Subproject commit 8abb85b44cb2100dba45c3f3f8fe981fcf300b71 diff --git a/src/lib/synergy/CMakeLists.txt b/src/lib/synergy/CMakeLists.txt index 910086966..3819b591b 100644 --- a/src/lib/synergy/CMakeLists.txt +++ b/src/lib/synergy/CMakeLists.txt @@ -21,6 +21,8 @@ file(GLOB sources "*.cpp") if (WIN32) file(GLOB arch_headers "win32/*.h") file(GLOB arch_sources "win32/*.cpp") + include_directories("../../../ext/WinToast/src") + list(APPEND arch_sources "../../../ext/WinToast/src/wintoastlib.cpp") elseif (UNIX) file(GLOB arch_headers "unix/*.h") file(GLOB arch_sources "unix/*.cpp") @@ -37,4 +39,4 @@ add_library(synlib STATIC ${sources}) if (UNIX) target_link_libraries(synlib arch client ipc net base platform mt server) -endif() +endif() \ No newline at end of file diff --git a/src/lib/synergy/win32/AppUtilWindows.cpp b/src/lib/synergy/win32/AppUtilWindows.cpp index d1c64a467..6480526f7 100644 --- a/src/lib/synergy/win32/AppUtilWindows.cpp +++ b/src/lib/synergy/win32/AppUtilWindows.cpp @@ -31,6 +31,7 @@ #include "base/Event.h" #include "base/EventQueue.h" #include "common/Version.h" +#include "wintoastlib.h" #include #include @@ -181,8 +182,46 @@ AppUtilWindows::startNode() app().startNode(); } +class WinToastHandler : public WinToastLib::IWinToastHandler { +public: + WinToastHandler() {} + // Public interfaces + void toastActivated() const override {} + void toastActivated(int actionIndex) const override {} + void toastDismissed(WinToastDismissalReason state) const override {} + void toastFailed() const override {} +}; + void AppUtilWindows::showNotification(const String & title, const String & text) const { LOG((CLOG_DEBUG "Showing notification. Title: \"%s\". Text: \"%s\"", title.c_str(), text.c_str())); + if (!WinToastLib::WinToast::isCompatible()) { + LOG((CLOG_INFO "This system does not support toast notifications")); + return; + } + if (!WinToastLib::WinToast::instance()->isInitialized()) + { + WinToastLib::WinToast::instance()->setAppName(L"Synergy"); + const auto aumi = WinToastLib::WinToast::configureAUMI(L"Symless", L"Synergy", L"Synergy App", L"1.14.1+"); + WinToastLib::WinToast::instance()->setAppUserModelId(aumi); + + if (!WinToastLib::WinToast::instance()->initialize()) + { + LOG((CLOG_DEBUG "Failed to initialize toast notifications")); + return; + } + } + + WinToastLib::WinToast::WinToastError error; + auto handler = std::make_unique(); + WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate(WinToastLib::WinToastTemplate::Text02); + templ.setTextField(std::wstring(title.begin(), title.end()), WinToastLib::WinToastTemplate::FirstLine); + templ.setTextField(std::wstring(text.begin(), text.end()), WinToastLib::WinToastTemplate::SecondLine); + + const bool launched = WinToastLib::WinToast::instance()->showToast(templ, handler.get(), &error); + if (!launched) { + LOG((CLOG_DEBUG "Failed to show toast notification. Error code: %d", error)); + return; + } }