Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: globally suppress highlight notifications #5629

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- Minor: Moderators can now see which mods start and cancel raids. (#5563)
- Minor: The emote popup now reloads when Twitch emotes are reloaded. (#5580)
- Minor: Added `--login <username>` CLI argument to specify which account to start logged in as. (#5626)
- Minor: Add muting of all application notifications via keybind/window menu. (#5629)
- Bugfix: Fixed tab move animation occasionally failing to start after closing a tab. (#5426, #5612)
- Bugfix: If a network request errors with 200 OK, Qt's error code is now reported instead of the HTTP status. (#5378)
- Bugfix: Fixed restricted users usernames not being clickable. (#5405)
Expand Down
13 changes: 13 additions & 0 deletions src/controllers/hotkeys/ActionNames.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,19 @@ inline const std::map<HotkeyCategory, ActionDefinitionMap> actionNames{
.argumentsPromptHover = "Should the tabs be enabled, disabled, "
"toggled, or live-only.",
}},
{"toggleGlobalNotificationSuppression",
ActionDefinition{
.displayName = "Toggle muting of all notifications",
.argumentDescription = "[on, off, or toggle. default: toggle]",
.minCountArguments = 0,
.maxCountArguments = 1,
.possibleArguments{{"Toggle", {}},
{"Mute notifications", {"on"}},
{"Unmute notifications", {"off"}}},
.argumentsPrompt = "New value:",
.argumentsPromptHover = "Should all highlight notifications be "
"enabled, disabled, or toggled.",
}},
}},
};

Expand Down
6 changes: 6 additions & 0 deletions src/messages/MessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ void actuallyTriggerHighlights(const QString &channelName, bool playSound,
return;
}

if (getSettings()->globallySuppressNotifications)
{
// Notifications are globally suppressed, ignore it.
return;
}

const bool hasFocus = (QApplication::focusWidget() != nullptr);
const bool resolveFocus =
!hasFocus || getSettings()->highlightAlwaysPlaySound;
Expand Down
3 changes: 3 additions & 0 deletions src/singletons/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ class Settings
BoolSetting suppressInitialLiveNotification = {
"/notifications/suppressInitialLive", false};

BoolSetting globallySuppressNotifications = {
"/notifications/globalSuppression", false};

BoolSetting notificationToast = {"/notifications/enableToast", false};
IntSetting openFromToast = {"/notifications/openFromToast",
static_cast<int>(ToastReaction::OpenInBrowser)};
Expand Down
21 changes: 20 additions & 1 deletion src/widgets/Notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ Notebook::Notebook(QWidget *parent)
<< "Notebook must be created within a BaseWindow";
}

this->toggleNotificationSuppression_ =
new QAction("Mute all notifications", this);
this->toggleNotificationSuppression_->setCheckable(true);
this->toggleNotificationSuppression_->setChecked(
getSettings()->globallySuppressNotifications);
this->toggleNotificationSuppression_->setShortcut(
getApp()->getHotkeys()->getDisplaySequence(
HotkeyCategory::Window, "toggleGlobalNotificationSuppression"));

QObject::connect(this->toggleNotificationSuppression_, &QAction::triggered,
[] {
getSettings()->globallySuppressNotifications =
!getSettings()->globallySuppressNotifications;
});
getSettings()->globallySuppressNotifications.connect(
[this](const bool &value) {
this->toggleNotificationSuppression_->setChecked(value);
});

// Manually resize the add button so the initial paint uses the correct
// width when computing the maximum width occupied per column in vertical
// tab rendering.
Expand Down Expand Up @@ -1241,8 +1260,8 @@ void Notebook::setLockNotebookLayout(bool value)
void Notebook::addNotebookActionsToMenu(QMenu *menu)
{
menu->addAction(this->lockNotebookLayoutAction_);

menu->addAction(this->toggleTopMostAction_);
menu->addAction(this->toggleNotificationSuppression_);
}

NotebookButton *Notebook::getAddButton()
Expand Down
1 change: 1 addition & 0 deletions src/widgets/Notebook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class Notebook : public BaseWidget

QAction *lockNotebookLayoutAction_;
QAction *toggleTopMostAction_;
QAction *toggleNotificationSuppression_;

// This filter, if set, is used to figure out the visibility of
// the tabs in this notebook.
Expand Down
33 changes: 32 additions & 1 deletion src/widgets/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,38 @@ void Window::addShortcuts()

return "";
}},
};
{"toggleGlobalNotificationSuppression",
[](const std::vector<QString> &arguments) -> QString {
QString arg = arguments.empty() ? "toggle" : arguments.front();

bool desiredValue = false;
if (arg == "toggle")
{
desiredValue = !getSettings()->globallySuppressNotifications;
}
else if (arg == "on")
{
desiredValue = true;
}
else if (arg == "off")
{
desiredValue = false;
}
else
{
qCWarning(chatterinoHotkeys)
<< "Invalid argument for "
"toggleGlobalNotificationSuppression hotkey: "
<< arg;
return QString("Invalid argument for "
"toggleGlobalNotificationSuppression hotkey: "
"%1. Use \"on\", \"off\", or \"toggle\".")
.arg(arg);
}

getSettings()->globallySuppressNotifications = desiredValue;
return "";
}}};

this->addDebugStuff(actions);

Expand Down
Loading