diff --git a/CHANGELOG.md b/CHANGELOG.md index e95268a8..4e5f4e0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Bugfix: Fixed suspicious user treatment update messages not being searchable. (#5865) - Bugfix: Ensure miniaudio backend exits even if it doesn't exit cleanly. (#5896) - Dev: Add initial experimental EventSub support. (#5837, #5895, #5897, #5904, #5910, #5903, #5915, #5916, #5930, #5935, #5932) +- Dev: Remove unneeded platform specifier for toasts. (#5914) - Dev: Highlight checks now use non-capturing groups for the boundaries. (#5784) - Dev: Removed unused PubSub whisper code. (#5898) - Dev: Updated Conan dependencies. (#5776) diff --git a/src/controllers/commands/builtin/chatterino/Debugging.cpp b/src/controllers/commands/builtin/chatterino/Debugging.cpp index 6262cda4..9339bb3d 100644 --- a/src/controllers/commands/builtin/chatterino/Debugging.cpp +++ b/src/controllers/commands/builtin/chatterino/Debugging.cpp @@ -187,7 +187,7 @@ QString debugTest(const CommandContext &ctx) auto title = ctx.twitchChannel->accessStreamStatus()->title; getApp()->getToasts()->sendChannelNotification( - ctx.twitchChannel->getName(), title, Platform::Twitch); + ctx.twitchChannel->getName(), title); ctx.channel->addSystemMessage( QString("debug-test sent desktop notification")); } diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index 7de9595a..eccf7cc8 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -122,8 +122,8 @@ void NotificationController::notifyTwitchChannelLive( { if (Toasts::isEnabled()) { - getApp()->getToasts()->sendChannelNotification( - payload.channelName, payload.title, Platform::Twitch); + getApp()->getToasts()->sendChannelNotification(payload.channelName, + payload.title); } if (getSettings()->notificationPlaySound) { diff --git a/src/singletons/Toasts.cpp b/src/singletons/Toasts.cpp index eef0d60a..2c51e2a8 100644 --- a/src/singletons/Toasts.cpp +++ b/src/singletons/Toasts.cpp @@ -126,11 +126,11 @@ QString Toasts::findStringFromReaction( // NOLINTNEXTLINE(readability-convert-member-functions-to-static) void Toasts::sendChannelNotification(const QString &channelName, - const QString &channelTitle, Platform p) + const QString &channelTitle) { #ifdef Q_OS_WIN - auto sendChannelNotification = [this, channelName, channelTitle, p] { - this->sendWindowsNotification(channelName, channelTitle, p); + auto sendChannelNotification = [this, channelName, channelTitle] { + this->sendWindowsNotification(channelName, channelTitle); }; #elif defined(CHATTERINO_WITH_LIBNOTIFY) auto sendChannelNotification = [this, channelName, channelTitle] { @@ -143,28 +143,25 @@ void Toasts::sendChannelNotification(const QString &channelName, }; #endif // Fetch user profile avatar - if (p == Platform::Twitch) + if (hasAvatarForChannel(channelName)) { - if (hasAvatarForChannel(channelName)) - { - sendChannelNotification(); - } - else - { - getHelix()->getUserByName( - channelName, - [channelName, sendChannelNotification](const auto &user) { - // gets deleted when finished - auto *downloader = - new AvatarDownloader(user.profileImageUrl, channelName); - QObject::connect(downloader, - &AvatarDownloader::downloadComplete, - sendChannelNotification); - }, - [] { - // on failure - }); - } + sendChannelNotification(); + } + else + { + getHelix()->getUserByName( + channelName, + [channelName, sendChannelNotification](const auto &user) { + // gets deleted when finished + auto *downloader = + new AvatarDownloader(user.profileImageUrl, channelName); + QObject::connect(downloader, + &AvatarDownloader::downloadComplete, + sendChannelNotification); + }, + [] { + // on failure + }); } } @@ -174,12 +171,10 @@ class CustomHandler : public WinToastLib::IWinToastHandler { private: QString channelName_; - Platform platform_; public: - CustomHandler(QString channelName, Platform p) + CustomHandler(QString channelName) : channelName_(std::move(channelName)) - , platform_(p) { } void toastActivated() const override @@ -190,18 +185,12 @@ public: switch (toastReaction) { case ToastReaction::OpenInBrowser: - if (platform_ == Platform::Twitch) - { - QDesktopServices::openUrl( - QUrl(u"https://www.twitch.tv/" % channelName_)); - } + QDesktopServices::openUrl( + QUrl(u"https://www.twitch.tv/" % channelName_)); break; case ToastReaction::OpenInPlayer: - if (platform_ == Platform::Twitch) - { - QDesktopServices::openUrl( - QUrl(TWITCH_PLAYER_URL.arg(channelName_))); - } + QDesktopServices::openUrl( + QUrl(TWITCH_PLAYER_URL.arg(channelName_))); break; case ToastReaction::OpenInStreamlink: { openStreamlinkForChannel(channelName_); @@ -255,7 +244,7 @@ void Toasts::ensureInitialized() } void Toasts::sendWindowsNotification(const QString &channelName, - const QString &channelTitle, Platform p) + const QString &channelTitle) { this->ensureInitialized(); @@ -276,10 +265,7 @@ void Toasts::sendWindowsNotification(const QString &channelName, } QString avatarPath; - if (p == Platform::Twitch) - { - avatarPath = avatarFilePath(channelName); - } + avatarPath = avatarFilePath(channelName); templ.setImagePath(avatarPath.toStdWString()); if (getSettings()->notificationPlaySound) { @@ -287,7 +273,7 @@ void Toasts::sendWindowsNotification(const QString &channelName, } WinToast::WinToastError error = WinToast::NoError; - WinToast::instance()->showToast(templ, new CustomHandler(channelName, p), + WinToast::instance()->showToast(templ, new CustomHandler(channelName), &error); if (error != WinToast::NoError) { diff --git a/src/singletons/Toasts.hpp b/src/singletons/Toasts.hpp index a945f11b..25d9ee59 100644 --- a/src/singletons/Toasts.hpp +++ b/src/singletons/Toasts.hpp @@ -3,12 +3,8 @@ #include #include -#include - namespace chatterino { -enum class Platform : uint8_t; - enum class ToastReaction { OpenInBrowser = 0, OpenInPlayer = 1, @@ -22,7 +18,7 @@ public: ~Toasts(); void sendChannelNotification(const QString &channelName, - const QString &channelTitle, Platform p); + const QString &channelTitle); static QString findStringFromReaction(const ToastReaction &reaction); static QString findStringFromReaction( const pajlada::Settings::Setting &reaction); @@ -33,7 +29,7 @@ private: #ifdef Q_OS_WIN void ensureInitialized(); void sendWindowsNotification(const QString &channelName, - const QString &channelTitle, Platform p); + const QString &channelTitle); bool initialized_ = false; #elif defined(CHATTERINO_WITH_LIBNOTIFY)