fixed stuff

This commit is contained in:
apa420 2018-08-29 19:25:37 +02:00
parent df7d256c7f
commit c5a88f6af3
7 changed files with 39 additions and 28 deletions

View file

@ -2,11 +2,14 @@
#include "Application.hpp"
#include "common/NetworkRequest.hpp"
#include "common/Outcome.hpp"
#include "controllers/notifications/NotificationModel.hpp"
#include "debug/Log.hpp"
#include "providers/twitch/TwitchApi.hpp"
#include "providers/twitch/TwitchServer.hpp"
#include "singletons/Toasts.hpp"
#include "singletons/WindowManager.hpp"
#include "widgets/Window.hpp"
#include <wintoastlib.h>
@ -93,9 +96,9 @@ void NotificationController::playSound()
static QUrl currentPlayerUrl;
QUrl highlightSoundUrl;
if (getApp()->settings->notificationCustomSound) {
if (getSettings()->notificationCustomSound) {
highlightSoundUrl = QUrl::fromLocalFile(
getApp()->settings->notificationPathSound.getValue());
getSettings()->notificationPathSound.getValue());
} else {
highlightSoundUrl = QUrl("qrc:/sounds/ping2.wav");
}
@ -134,12 +137,12 @@ void NotificationController::getFakeTwitchChannelLiveStatus(
{
TwitchApi::findUserId(channelName, [channelName, this](QString roomID) {
if (roomID.isEmpty()) {
Log("[TwitchChannel:{}] Refreshing live status (Missing ID)",
log("[TwitchChannel:{}] Refreshing live status (Missing ID)",
channelName);
removeFakeChannel(channelName);
return;
}
Log("[TwitchChannel:{}] Refreshing live status", channelName);
log("[TwitchChannel:{}] Refreshing live status", channelName);
QString url("https://api.twitch.tv/kraken/streams/" + roomID);
auto request = NetworkRequest::twitchRequest(url);
@ -148,12 +151,12 @@ void NotificationController::getFakeTwitchChannelLiveStatus(
request.onSuccess([this, channelName](auto result) -> Outcome {
rapidjson::Document document = result.parseRapidJson();
if (!document.IsObject()) {
Log("[TwitchChannel:refreshLiveStatus] root is not an object");
log("[TwitchChannel:refreshLiveStatus]root is not an object");
return Failure;
}
if (!document.HasMember("stream")) {
Log("[TwitchChannel:refreshLiveStatus] Missing stream in root");
log("[TwitchChannel:refreshLiveStatus] Missing stream in root");
return Failure;
}
@ -161,7 +164,7 @@ void NotificationController::getFakeTwitchChannelLiveStatus(
if (!stream.IsObject()) {
// Stream is offline (stream is most likely null)
removeFakeChannel(channelName);
// removeFakeChannel(channelName);
return Failure;
}
// Stream is live
@ -174,14 +177,15 @@ void NotificationController::getFakeTwitchChannelLiveStatus(
getApp()->toasts->sendChannelNotification(channelName,
Platform::Twitch);
}
if (getApp()->settings->notificationPlaySound) {
if (getSettings()->notificationPlaySound) {
getApp()->notifications->playSound();
}
if (getApp()->settings->notificationFlashTaskbar) {
if (getSettings()->notificationFlashTaskbar) {
QApplication::alert(
getApp()->windows->getMainWindow().window(), 2500);
}
}
return Success;
});
request.execute();

View file

@ -1,6 +1,7 @@
#pragma once
#include "common/SignalVector.hpp"
#include "common/Singleton.hpp"
#include "singletons/Settings.hpp"
#include <QTimer>

View file

@ -6,6 +6,7 @@
#include "providers/twitch/TwitchCommon.hpp"
#include <QString>
#include <QThread>
namespace chatterino {

View file

@ -18,6 +18,7 @@
#include "singletons/Toasts.hpp"
#include "singletons/WindowManager.hpp"
#include "util/PostToThread.hpp"
#include "widgets/Window.hpp"
#include <IrcConnection>
#include <QJsonArray>
@ -400,10 +401,10 @@ void TwitchChannel::setLive(bool newLiveStatus)
getApp()->toasts->sendChannelNotification(this->getName(),
Platform::Twitch);
}
if (getApp()->settings->notificationPlaySound) {
if (getSettings()->notificationPlaySound) {
getApp()->notifications->playSound();
}
if (getApp()->settings->notificationFlashTaskbar) {
if (getSettings()->notificationFlashTaskbar) {
QApplication::alert(
getApp()->windows->getMainWindow().window(), 2500);
}

View file

@ -19,6 +19,8 @@
namespace chatterino {
enum class HighlightState;
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
class EmoteMap;

View file

@ -27,7 +27,7 @@ namespace chatterino {
bool Toasts::isEnabled()
{
return WinToastLib::WinToast::isCompatible() &&
getApp()->settings->notificationToast;
getSettings()->notificationToast;
}
void Toasts::sendChannelNotification(const QString &channelName, Platform p)
@ -115,13 +115,13 @@ void Toasts::sendWindowsNotification(const QString &channelName, Platform p)
WinToastLib::WinToastTemplate::SecondLine);
QString Path;
if (p == Platform::Twitch) {
Path = getApp()->paths->cacheDirectory() + "/" +
Path = Path = getPaths()->cacheDirectory() + "/" +
"profileAvatars/twitch/" + channelName + ".png";
}
std::string temp_Utf8 = Path.toUtf8().constData();
std::wstring imagePath = std::wstring(temp_Utf8.begin(), temp_Utf8.end());
templ.setImagePath(imagePath);
if (getApp()->settings->notificationPlaySound) {
if (getSettings()->notificationPlaySound) {
templ.setAudioOption(
WinToastLib::WinToastTemplate::AudioOption::Silent);
}
@ -154,28 +154,30 @@ void Toasts::fetchChannelAvatar(const QString channelName,
request.onSuccess([successCallback](auto result) mutable -> Outcome {
auto root = result.parseJson();
if (!root.value("users").isArray()) {
Log("API Error while getting user id, users is not an array");
// log("API Error while getting user id, users is not an array");
successCallback("");
return Failure;
}
auto users = root.value("users").toArray();
if (users.size() != 1) {
Log("API Error while getting user id, users array size is not 1");
// log("API Error while getting user id, users array size is not
// 1");
successCallback("");
return Failure;
}
if (!users[0].isObject()) {
Log("API Error while getting user id, first user is not an object");
// log("API Error while getting user id, first user is not an
// object");
successCallback("");
return Failure;
}
auto firstUser = users[0].toObject();
auto avatar = firstUser.value("logo");
if (!avatar.isString()) {
Log("API Error: while getting user avatar, first user object "
"`avatar` key "
"is not a "
"string");
// log("API Error: while getting user avatar, first user object "
// "`avatar` key "
// "is not a "
// "string");
successCallback("");
return Failure;
}

View file

@ -33,21 +33,21 @@ NotificationPage::NotificationPage()
settings.emplace<QLabel>("Enable for selected channels");
settings.append(this->createCheckBox(
"Flash taskbar",
getApp()->settings->notificationFlashTaskbar));
getSettings()->notificationFlashTaskbar));
settings.append(this->createCheckBox(
"Playsound (doesn't mute the Windows 8.x sound of toasts)",
getApp()->settings->notificationPlaySound));
getSettings()->notificationPlaySound));
#ifdef Q_OS_WIN
settings.append(this->createCheckBox(
"Enable toasts (currently only for windows 8.x or 10)",
getApp()->settings->notificationToast));
getSettings()->notificationToast));
#endif
auto customSound =
layout.emplace<QHBoxLayout>().withoutMargin();
{
customSound.append(this->createCheckBox(
"Custom sound",
getApp()->settings->notificationCustomSound));
getSettings()->notificationCustomSound));
auto selectFile = customSound.emplace<QPushButton>(
"Select custom sound file");
QObject::connect(
@ -56,7 +56,7 @@ NotificationPage::NotificationPage()
auto fileName = QFileDialog::getOpenFileName(
this, tr("Open Sound"), "",
tr("Audio Files (*.mp3 *.wav)"));
getApp()->settings->notificationPathSound =
getSettings()->notificationPathSound =
fileName;
});
}