Implement dekstop notifications on Windows (#290)

remotes/origin/HEAD
Konstantinos Sideris 6 years ago
parent 765ff5dcb5
commit 95ce2ef920
  1. 1
      .gitignore
  2. 12
      CMakeLists.txt
  3. 45
      src/notifications/ManagerWin.cpp

1
.gitignore vendored

@ -1,6 +1,7 @@
build build
tags tags
.clang_complete .clang_complete
*wintoastlib*
# C++ objects and libs # C++ objects and libs

@ -323,7 +323,17 @@ if (APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Foundation") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Foundation")
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerMac.mm) set(SRC_FILES ${SRC_FILES} src/notifications/ManagerMac.mm)
elseif (WIN32) elseif (WIN32)
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerWin.cpp) file(DOWNLOAD
"https://raw.githubusercontent.com/mohabouje/WinToast/41ed1c58d5dce0ee9c01dbdeac05be45358d4f57/src/wintoastlib.cpp"
${PROJECT_SOURCE_DIR}/src/wintoastlib.cpp
EXPECTED_HASH SHA256=1A1A7CE41C1052B12946798F4A6C67CE1FAD209C967F5ED4D720B173527E2073)
file(DOWNLOAD
"https://raw.githubusercontent.com/mohabouje/WinToast/41ed1c58d5dce0ee9c01dbdeac05be45358d4f57/src/wintoastlib.h"
${PROJECT_SOURCE_DIR}/include/wintoastlib.h
EXPECTED_HASH SHA256=b4481023c5782733795838be22bf1a75f45d87458cd4d9a5a75f664a146eea11)
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerWin.cpp src/wintoastlib.cpp)
else () else ()
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerLinux.cpp) set(SRC_FILES ${SRC_FILES} src/notifications/ManagerLinux.cpp)
endif () endif ()

@ -1,7 +1,48 @@
#include "notifications/Manager.h" #include "notifications/Manager.h"
#include "wintoastlib.h"
using namespace WinToastLib;
class CustomHandler : public IWinToastHandler
{
public:
void toastActivated() const {}
void toastActivated(int) const {}
void toastFailed() const { std::wcout << L"Error showing current toast" << std::endl; }
void toastDismissed(WinToastDismissalReason) const {}
};
namespace {
bool isInitialized = false;
void
init()
{
isInitialized = true;
WinToast::instance()->setAppName(L"Nheko");
WinToast::instance()->setAppUserModelId(WinToast::configureAUMI(L"nheko", L"nheko"));
if (!WinToast::instance()->initialize())
std::wcout << "Your system in not compatible with toast notifications\n";
}
}
void void
NotificationsManager::postNotification(const QString &, const QString &, const QString &) NotificationsManager::postNotification(const QString &room, const QString &user, const QString &msg)
{ {
// TODO: To be implemented if (!isInitialized)
init();
auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
if (room != user)
templ.setTextField(QString("%1 - %2").arg(user).arg(room).toStdWString(),
WinToastTemplate::FirstLine);
else
templ.setTextField(QString("%1").arg(user).toStdWString(),
WinToastTemplate::FirstLine);
templ.setTextField(QString("%1").arg(msg).toStdWString(), WinToastTemplate::SecondLine);
// TODO: implement room or user avatar
// templ.setImagePath(L"C:/example.png");
WinToast::instance()->showToast(templ, new CustomHandler());
} }

Loading…
Cancel
Save