feat: add "Open in custom player" to toast options (#5880)

This commit is contained in:
nerix
2025-03-05 16:29:28 +01:00
committed by GitHub
parent 54793f1496
commit 72369b1611
9 changed files with 67 additions and 11 deletions
+1
View File
@@ -11,6 +11,7 @@
- Minor: When (re-)connecting, visible channels are now joined first. (#5850) - Minor: When (re-)connecting, visible channels are now joined first. (#5850)
- Minor: Added the ability to filter on messages by the author's user ID (example: `author.user_id == "22484632"`). (#5862) - Minor: Added the ability to filter on messages by the author's user ID (example: `author.user_id == "22484632"`). (#5862)
- Minor: Improved error messaging of the `/clip` command. (#5879) - Minor: Improved error messaging of the `/clip` command. (#5879)
- Minor: Clicking on a live notification can now open the channel in a custom player. (#5880)
- Minor: Added searchable hotkeys to global search and make keybinds searchable in the Hotkeys settings. (#5884) - Minor: Added searchable hotkeys to global search and make keybinds searchable in the Hotkeys settings. (#5884)
- Minor: Added Linux support for Live Notifications toasts. (#5881, #5971, #5976) - Minor: Added Linux support for Live Notifications toasts. (#5881, #5971, #5976)
- Minor: Messages can now be deleted from the context menu in a channel. (#5956) - Minor: Messages can now be deleted from the context menu in a channel. (#5956)
+2
View File
@@ -501,6 +501,8 @@ set(SOURCE_FILES
util/ChannelHelpers.hpp util/ChannelHelpers.hpp
util/Clipboard.cpp util/Clipboard.cpp
util/Clipboard.hpp util/Clipboard.hpp
util/CustomPlayer.cpp
util/CustomPlayer.hpp
util/DebugCount.cpp util/DebugCount.cpp
util/DebugCount.hpp util/DebugCount.hpp
util/DisplayBadge.cpp util/DisplayBadge.cpp
+19
View File
@@ -11,6 +11,7 @@
#include "singletons/Paths.hpp" #include "singletons/Paths.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "singletons/StreamerMode.hpp" #include "singletons/StreamerMode.hpp"
#include "util/CustomPlayer.hpp"
#include "util/StreamLink.hpp" #include "util/StreamLink.hpp"
#include "widgets/helper/CommonTexts.hpp" #include "widgets/helper/CommonTexts.hpp"
@@ -78,6 +79,10 @@ void performReaction(const ToastReaction &reaction, const QString &channelName)
openStreamlinkForChannel(channelName); openStreamlinkForChannel(channelName);
break; break;
} }
case ToastReaction::OpenInCustomPlayer: {
openInCustomPlayer(channelName);
break;
}
case ToastReaction::DontOpen: case ToastReaction::DontOpen:
// nothing should happen // nothing should happen
break; break;
@@ -106,6 +111,10 @@ void onAction(NotifyNotification *notif, const char *actionRaw, void *userData)
{ {
toastReaction = ToastReaction::OpenInStreamlink; toastReaction = ToastReaction::OpenInStreamlink;
} }
else if (action == OPEN_IN_CUSTOM_PLAYER)
{
toastReaction = ToastReaction::OpenInCustomPlayer;
}
performReaction(toastReaction, *channelName); performReaction(toastReaction, *channelName);
@@ -172,6 +181,9 @@ QString Toasts::findStringFromReaction(const ToastReaction &reaction)
case ToastReaction::OpenInStreamlink: case ToastReaction::OpenInStreamlink:
return OPEN_IN_STREAMLINK; return OPEN_IN_STREAMLINK;
case ToastReaction::DontOpen: case ToastReaction::DontOpen:
return DONT_OPEN;
case ToastReaction::OpenInCustomPlayer:
return OPEN_IN_CUSTOM_PLAYER;
default: default:
return DONT_OPEN; return DONT_OPEN;
} }
@@ -372,6 +384,13 @@ void Toasts::sendLibnotify(const QString &channelName,
notif, OPEN_IN_STREAMLINK.toUtf8().constData(), notif, OPEN_IN_STREAMLINK.toUtf8().constData(),
OPEN_IN_STREAMLINK.toUtf8().constData(), (NotifyActionCallback)onAction, OPEN_IN_STREAMLINK.toUtf8().constData(), (NotifyActionCallback)onAction,
channelNameHeap, nullptr); channelNameHeap, nullptr);
if (!getSettings()->customURIScheme.getValue().isEmpty())
{
notify_notification_add_action(
notif, OPEN_IN_CUSTOM_PLAYER.toUtf8().constData(),
OPEN_IN_CUSTOM_PLAYER.toUtf8().constData(),
(NotifyActionCallback)onAction, channelNameHeap, nullptr);
}
auto defaultToastReaction = auto defaultToastReaction =
static_cast<ToastReaction>(getSettings()->openFromToast.getValue()); static_cast<ToastReaction>(getSettings()->openFromToast.getValue());
+2 -1
View File
@@ -9,7 +9,8 @@ enum class ToastReaction {
OpenInBrowser = 0, OpenInBrowser = 0,
OpenInPlayer = 1, OpenInPlayer = 1,
OpenInStreamlink = 2, OpenInStreamlink = 2,
DontOpen = 3 DontOpen = 3,
OpenInCustomPlayer = 4,
}; };
class Toasts final class Toasts final
+28
View File
@@ -0,0 +1,28 @@
#include "util/CustomPlayer.hpp"
#include "common/QLogging.hpp"
#include "singletons/Settings.hpp"
#include <QDesktopServices>
#include <QStringBuilder>
#include <QStringView>
#include <QUrl>
namespace chatterino {
void openInCustomPlayer(QStringView channelName)
{
QString scheme = getSettings()->customURIScheme.getValue();
if (scheme.isEmpty())
{
qCWarning(chatterinoApp)
<< "Can't open" << channelName
<< "in custom player because no URI scheme is set";
return;
}
QDesktopServices::openUrl(
QUrl{scheme % u"https://twitch.tv/" % channelName});
}
} // namespace chatterino
+9
View File
@@ -0,0 +1,9 @@
#pragma once
#include <QStringView>
namespace chatterino {
void openInCustomPlayer(QStringView channel);
} // namespace chatterino
+2
View File
@@ -10,6 +10,8 @@ inline const QString OPEN_PLAYER_IN_BROWSER =
inline const QString OPEN_MOD_VIEW_IN_BROWSER = inline const QString OPEN_MOD_VIEW_IN_BROWSER =
QStringLiteral("Open mod view in browser"); QStringLiteral("Open mod view in browser");
inline const QString OPEN_IN_STREAMLINK = QStringLiteral("Open in streamlink"); inline const QString OPEN_IN_STREAMLINK = QStringLiteral("Open in streamlink");
inline const QString OPEN_IN_CUSTOM_PLAYER =
QStringLiteral("Open in custom player");
inline const QString DONT_OPEN = QStringLiteral("Don't open"); inline const QString DONT_OPEN = QStringLiteral("Don't open");
inline const QString OPEN_WHISPERS_IN_BROWSER = inline const QString OPEN_WHISPERS_IN_BROWSER =
QStringLiteral("Open whispers in browser"); QStringLiteral("Open whispers in browser");
@@ -127,7 +127,8 @@ QComboBox *NotificationPage::createToastReactionComboBox()
{ {
QComboBox *toastReactionOptions = new QComboBox(); QComboBox *toastReactionOptions = new QComboBox();
for (int i = 0; i <= static_cast<int>(ToastReaction::DontOpen); i++) for (int i = 0; i <= static_cast<int>(ToastReaction::OpenInCustomPlayer);
i++)
{ {
toastReactionOptions->insertItem( toastReactionOptions->insertItem(
i, Toasts::findStringFromReaction(static_cast<ToastReaction>(i))); i, Toasts::findStringFromReaction(static_cast<ToastReaction>(i)));
+2 -9
View File
@@ -21,6 +21,7 @@
#include "singletons/Theme.hpp" #include "singletons/Theme.hpp"
#include "singletons/WindowManager.hpp" #include "singletons/WindowManager.hpp"
#include "util/Clipboard.hpp" #include "util/Clipboard.hpp"
#include "util/CustomPlayer.hpp"
#include "util/Helpers.hpp" #include "util/Helpers.hpp"
#include "util/StreamLink.hpp" #include "util/StreamLink.hpp"
#include "widgets/dialogs/QualityPopup.hpp" #include "widgets/dialogs/QualityPopup.hpp"
@@ -1252,19 +1253,11 @@ void Split::openInStreamlink()
void Split::openWithCustomScheme() void Split::openWithCustomScheme()
{ {
QString scheme = getSettings()->customURIScheme.getValue();
if (scheme.isEmpty())
{
return;
}
auto *const channel = this->getChannel().get(); auto *const channel = this->getChannel().get();
if (auto *const twitchChannel = dynamic_cast<TwitchChannel *>(channel)) if (auto *const twitchChannel = dynamic_cast<TwitchChannel *>(channel))
{ {
QDesktopServices::openUrl(QString("%1https://twitch.tv/%2") openInCustomPlayer(twitchChannel->getName());
.arg(scheme)
.arg(twitchChannel->getName()));
} }
} }