Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
Implement dekstop notifications on Windows (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
mujx committed Jun 30, 2018
1 parent 765ff5d commit 95ce2ef
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
build
tags
.clang_complete
*wintoastlib*

# C++ objects and libs

Expand Down
12 changes: 11 additions & 1 deletion CMakeLists.txt
Expand Up @@ -323,7 +323,17 @@ if (APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Foundation")
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerMac.mm)
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 ()
set(SRC_FILES ${SRC_FILES} src/notifications/ManagerLinux.cpp)
endif ()
Expand Down
45 changes: 43 additions & 2 deletions src/notifications/ManagerWin.cpp
@@ -1,7 +1,48 @@
#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
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());
}

0 comments on commit 95ce2ef

Please sign in to comment.