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 <serhii-external@symless.com>
This commit is contained in:
Igor Sikachyna 2021-07-12 16:04:31 +03:00 committed by GitHub
parent 6b1761316a
commit e317569057
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 1 deletions

3
.gitmodules vendored
View file

@ -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

View file

@ -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:

1
ext/WinToast Submodule

@ -0,0 +1 @@
Subproject commit 8abb85b44cb2100dba45c3f3f8fe981fcf300b71

View file

@ -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()

View file

@ -31,6 +31,7 @@
#include "base/Event.h"
#include "base/EventQueue.h"
#include "common/Version.h"
#include "wintoastlib.h"
#include <sstream>
#include <iostream>
@ -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<WinToastHandler>();
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;
}
}