mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
update, should now be working Toasts for splitheader channels
This commit is contained in:
parent
77411f7012
commit
2de99ca9f5
|
@ -36,6 +36,12 @@ void NotificationController::updateChannelNotification(
|
||||||
|
|
||||||
bool NotificationController::isChannelNotified(const QString &channelName)
|
bool NotificationController::isChannelNotified(const QString &channelName)
|
||||||
{
|
{
|
||||||
|
for (std::vector<int>::size_type i = 0;
|
||||||
|
i != notificationVector.getVector().size(); i++) {
|
||||||
|
qDebug() << notificationVector.getVector()[i]
|
||||||
|
<< " vector to the left channel to the right " << channelName
|
||||||
|
<< " vectorsize:" << notificationVector.getVector().size();
|
||||||
|
}
|
||||||
for (std::vector<int>::size_type i = 0;
|
for (std::vector<int>::size_type i = 0;
|
||||||
i != notificationVector.getVector().size(); i++) {
|
i != notificationVector.getVector().size(); i++) {
|
||||||
if (notificationVector.getVector()[i] == channelName) {
|
if (notificationVector.getVector()[i] == channelName) {
|
||||||
|
@ -44,7 +50,7 @@ bool NotificationController::isChannelNotified(const QString &channelName)
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
class CustomHandler : public WinToastLib::IWinToastHandler
|
class CustomHandler : public WinToastLib::IWinToastHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -85,7 +91,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
void NotificationController::addChannelNotification(const QString &channelName)
|
void NotificationController::addChannelNotification(const QString &channelName)
|
||||||
{
|
{
|
||||||
notificationVector.appendItem(channelName);
|
notificationVector.appendItem(channelName);
|
||||||
|
@ -93,7 +99,7 @@ void NotificationController::addChannelNotification(const QString &channelName)
|
||||||
if (WinToastLib::WinToast::isCompatible()) {
|
if (WinToastLib::WinToast::isCompatible()) {
|
||||||
QDir dir;
|
QDir dir;
|
||||||
qDebug() << "NaM" << dir.absolutePath();
|
qDebug() << "NaM" << dir.absolutePath();
|
||||||
;
|
/*
|
||||||
|
|
||||||
WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate(
|
WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate(
|
||||||
WinToastLib::WinToastTemplate::ImageAndText02);
|
WinToastLib::WinToastTemplate::ImageAndText02);
|
||||||
|
@ -111,6 +117,7 @@ void NotificationController::addChannelNotification(const QString &channelName)
|
||||||
WinToastLib::WinToast::instance()->initialize();
|
WinToastLib::WinToast::instance()->initialize();
|
||||||
WinToastLib::WinToast::instance()->showToast(templ,
|
WinToastLib::WinToast::instance()->showToast(templ,
|
||||||
new CustomHandler());
|
new CustomHandler());
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,13 @@
|
||||||
#include "providers/twitch/TwitchChannel.hpp"
|
#include "providers/twitch/TwitchChannel.hpp"
|
||||||
#include "providers/twitch/TwitchServer.hpp"
|
#include "providers/twitch/TwitchServer.hpp"
|
||||||
|
|
||||||
|
#include <wintoastlib.h>
|
||||||
|
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
Toasts::Toasts()
|
Toasts::Toasts()
|
||||||
|
@ -13,15 +20,21 @@ Toasts::Toasts()
|
||||||
|
|
||||||
void Toasts::initialize(Settings &settings, Paths &paths)
|
void Toasts::initialize(Settings &settings, Paths &paths)
|
||||||
{
|
{
|
||||||
getApp()->twitch2->forEachChannel([](ChannelPtr chn) {
|
getApp()->twitch2->forEachChannel([this](ChannelPtr chn) {
|
||||||
auto twchn = dynamic_cast<TwitchChannel *>(chn.get());
|
auto twchn = dynamic_cast<TwitchChannel *>(chn.get());
|
||||||
twchn->liveStatusChanged.connect([twchn]() {
|
twchn->liveStatusChanged.connect([twchn, this]() {
|
||||||
const auto streamStatus = twchn->accessStreamStatus();
|
const auto streamStatus = twchn->accessStreamStatus();
|
||||||
if (streamStatus->live) {
|
if (streamStatus->live) {
|
||||||
// to Live
|
// is live
|
||||||
getApp()->toasts->updateLiveChannels(twchn->getName());
|
if (getApp()->notifications->isChannelNotified(
|
||||||
|
twchn->getName()) &&
|
||||||
|
!wasChannelLive(twchn->getName())) {
|
||||||
|
sendChannelNotification(twchn->getName());
|
||||||
|
}
|
||||||
|
updateLiveChannels(twchn->getName());
|
||||||
} else {
|
} else {
|
||||||
// to Offline
|
// is Offline
|
||||||
|
removeFromLiveChannels(twchn->getName());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -29,14 +42,21 @@ void Toasts::initialize(Settings &settings, Paths &paths)
|
||||||
|
|
||||||
void Toasts::updateLiveChannels(const QString &channelName)
|
void Toasts::updateLiveChannels(const QString &channelName)
|
||||||
{
|
{
|
||||||
if (wasChannelLive(channelName)) {
|
if (!wasChannelLive(channelName)) {
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
liveChannels.push_back(channelName);
|
liveChannels.push_back(channelName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Toasts::removeFromLiveChannels(const QString &channelName)
|
||||||
|
{
|
||||||
|
if (wasChannelLive(channelName)) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
liveChannels.erase(
|
||||||
|
std::find(liveChannels.begin(), liveChannels.end(), channelName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Toasts::wasChannelLive(const QString &channelName)
|
bool Toasts::wasChannelLive(const QString &channelName)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
@ -47,10 +67,92 @@ bool Toasts::wasChannelLive(const QString &channelName)
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toasts::sendChannelNotification(const QString &channelName)
|
void Toasts::sendChannelNotification(const QString &channelName)
|
||||||
{
|
{
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
if (WinToastLib::WinToast::isCompatible()) {
|
||||||
|
sendWindowsNotification(channelName);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// OSX
|
||||||
|
|
||||||
|
// LINUX
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toasts::
|
#ifdef Q_OS_WIN
|
||||||
|
|
||||||
|
class CustomHandler : public WinToastLib::IWinToastHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void toastActivated() const
|
||||||
|
{
|
||||||
|
std::wcout << L"The user clicked in this toast" << std::endl;
|
||||||
|
QString link = "http://www.google.com";
|
||||||
|
QDesktopServices::openUrl(QUrl(link));
|
||||||
|
}
|
||||||
|
|
||||||
|
void toastActivated(int actionIndex) const
|
||||||
|
{
|
||||||
|
// std::wcout << L"The user clicked on button #" << actionIndex
|
||||||
|
// << L" in this toast" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void toastFailed() const
|
||||||
|
{
|
||||||
|
// std::wcout << L"Error showing current toast" << std::endl;
|
||||||
|
}
|
||||||
|
void toastDismissed(WinToastDismissalReason state) const
|
||||||
|
{
|
||||||
|
switch (state) {
|
||||||
|
case UserCanceled:
|
||||||
|
// std::wcout << L"The user dismissed this toast" << std::endl;
|
||||||
|
break;
|
||||||
|
case ApplicationHidden:
|
||||||
|
/*
|
||||||
|
std::wcout << L"The application hid the toast using "
|
||||||
|
L"ToastNotifier.hide()"
|
||||||
|
<< std::endl;
|
||||||
|
*/
|
||||||
|
break;
|
||||||
|
case TimedOut:
|
||||||
|
// std::wcout << L"The toast has timed out" << std::endl;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// std::wcout << L"Toast not activated" << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void Toasts::sendWindowsNotification(const QString &channelName)
|
||||||
|
{
|
||||||
|
WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate(
|
||||||
|
WinToastLib::WinToastTemplate::ImageAndText02);
|
||||||
|
QString str = channelName + " has just gone live!";
|
||||||
|
std::string utf8_text = str.toUtf8().constData();
|
||||||
|
std::wstring widestr = std::wstring(utf8_text.begin(), utf8_text.end());
|
||||||
|
|
||||||
|
templ.setTextField(widestr, WinToastLib::WinToastTemplate::FirstLine);
|
||||||
|
templ.setTextField(L"Click here to open in browser",
|
||||||
|
WinToastLib::WinToastTemplate::SecondLine);
|
||||||
|
WinToastLib::WinToast::instance()->setAppName(L"Chatterino2");
|
||||||
|
int mbstowcs(wchar_t * aumi_version, const char *CHATTERINO_VERSION,
|
||||||
|
size_t size);
|
||||||
|
std::string(CHATTERINO_VERSION);
|
||||||
|
std::wstring aumi_version =
|
||||||
|
std::wstring(CHATTERINO_VERSION.begin(), CHATTERINO_VERSION.end());
|
||||||
|
// int mbstowcs(wchar_t *out, const char *in, size_t size);
|
||||||
|
/*
|
||||||
|
std::wstring aumi_version =
|
||||||
|
std::wstring(std::string(CHATTERINO_VERSION).begin(),
|
||||||
|
std::string(CHATTERINO_VERSION).end());*/
|
||||||
|
WinToastLib::WinToast::instance()->setAppUserModelId(
|
||||||
|
WinToastLib::WinToast::configureAUMI(L"", L"Chatterino 2", L"",
|
||||||
|
aumi_version));
|
||||||
|
WinToastLib::WinToast::instance()->initialize();
|
||||||
|
WinToastLib::WinToast::instance()->showToast(templ, new CustomHandler());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -12,12 +12,16 @@ class Toasts final : public Singleton
|
||||||
public:
|
public:
|
||||||
Toasts();
|
Toasts();
|
||||||
virtual void initialize(Settings &settings, Paths &paths) override final;
|
virtual void initialize(Settings &settings, Paths &paths) override final;
|
||||||
|
|
||||||
|
private:
|
||||||
void updateLiveChannels(const QString &channelName);
|
void updateLiveChannels(const QString &channelName);
|
||||||
void removeFromLiveChannels(const QString &channelName);
|
void removeFromLiveChannels(const QString &channelName);
|
||||||
|
|
||||||
private:
|
|
||||||
bool wasChannelLive(const QString &channelName);
|
bool wasChannelLive(const QString &channelName);
|
||||||
|
|
||||||
|
void shouldChannelBeNotified(const QString &channelName);
|
||||||
void sendChannelNotification(const QString &channelName);
|
void sendChannelNotification(const QString &channelName);
|
||||||
|
void sendWindowsNotification(const QString &channelName);
|
||||||
std::vector<QString> liveChannels;
|
std::vector<QString> liveChannels;
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue