Add global notification control icon in top bar

The "Mentions & keywords only" option doesn't work yet in multi-account
cases: when notifications arrive for a room that multiple accounts are
part of, the first notification to arrive is let through, and the
duplicate later ones are ignored. The first notification to arrive may
not be from the account that gets highlighted, thus it is ignored under
the "Mentions & keywords" setting.
This commit is contained in:
miruka 2020-09-17 18:16:54 -04:00
parent bfc3a60cad
commit e8d8f7fe0b
7 changed files with 72 additions and 3 deletions

View File

@ -2,6 +2,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import ".."
import "../Base" import "../Base"
Rectangle { Rectangle {
@ -69,12 +70,60 @@ Rectangle {
HButton { HButton {
backgroundColor: "transparent" backgroundColor: "transparent"
icon.name: "reload-config-files"
toolTip.text: qsTr("Reload config files")
onClicked: mainUI.reloadSettings() icon.name:
window.notificationLevel === Window.NotificationLevel.All ?
"notifications-all" :
window.notificationLevel === Window.NotificationLevel.None ?
"notifications-none" :
"notifications-mentions-keywords"
icon.color:
window.notificationLevel === Window.NotificationLevel.All ?
theme.icons.colorize :
window.notificationLevel === Window.NotificationLevel.None ?
theme.colors.negativeBackground :
theme.colors.middleBackground
toolTip.text: qsTr("Control global notifications")
onClicked: notificationsMenu.open()
Layout.fillHeight: true Layout.fillHeight: true
HMenu {
id: notificationsMenu
y: parent.height
HMenuItem {
icon.name: "notifications-all"
text: qsTr("Normal notifications")
onTriggered:
window.notificationLevel =
Window.NotificationLevel.All
}
HMenuItem {
icon.name: "notifications-mentions-keywords"
icon.color: theme.colors.middleBackground
text: qsTr("Mentions & keywords")
onTriggered:
window.notificationLevel =
Window.NotificationLevel.MentionsKeywords
}
HMenuItem {
icon.name: "notifications-none"
icon.color: theme.colors.negativeBackground
text: qsTr("Nothing")
onTriggered:
window.notificationLevel =
Window.NotificationLevel.None
}
}
} }
HButton { HButton {

View File

@ -12,7 +12,11 @@ QtObject {
} }
function onNotificationRequested(title, body, image, highImportance) { function onNotificationRequested(title, body, image, highImportance) {
const level = window.notificationLevel
if (Qt.application.state === Qt.ApplicationActive) return if (Qt.application.state === Qt.ApplicationActive) return
if (level === Window.NotificationLevel.None) return
if (level === Window.MentionsKeywords && ! highImportance) return
py.callCoro("desktop_notify", [title, body, image]) py.callCoro("desktop_notify", [title, body, image])

View File

@ -8,6 +8,8 @@ import "PythonBridge"
ApplicationWindow { ApplicationWindow {
id: window id: window
enum NotificationLevel { None, MentionsKeywords, All }
// FIXME: Qt 5.13.1 bug, this randomly stops updating after the cursor // FIXME: Qt 5.13.1 bug, this randomly stops updating after the cursor
// leaves the window until it's clicked again. // leaves the window until it's clicked again.
@ -17,6 +19,8 @@ ApplicationWindow {
window.visibility === window.Minimized || window.visibility === window.Minimized ||
window.visibility === window.Hidden window.visibility === window.Hidden
property int notificationLevel: Window.NotificationLevel.All
property var mainUI: null property var mainUI: null
property var settings: ({}) property var settings: ({})
property var uiState: ({}) property var uiState: ({})

View File

@ -0,0 +1,3 @@
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="m15 21c0 1.598-1.392 3-2.971 3s-3.029-1.402-3.029-3zm.137-17.055c-.644-.374-1.042-1.07-1.041-1.82v-.003c.001-1.172-.938-2.122-2.096-2.122s-2.097.95-2.097 2.122v.003c.001.751-.396 1.446-1.041 1.82-4.668 2.709-1.985 11.715-6.862 13.306v1.749h20v-1.749c-4.877-1.591-2.193-10.598-6.863-13.306zm-3.137-2.945c.552 0 1 .449 1 1 0 .552-.448 1-1 1s-1-.448-1-1c0-.551.448-1 1-1zm-6.451 16c1.189-1.667 1.605-3.891 1.964-5.815.447-2.39.869-4.648 2.354-5.509 1.38-.801 2.956-.76 4.267 0 1.485.861 1.907 3.119 2.354 5.509.359 1.924.775 4.148 1.964 5.815z"/>
</svg>

After

Width:  |  Height:  |  Size: 648 B

View File

@ -0,0 +1,3 @@
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="m15 21c0 1.598-1.392 3-2.971 3s-3.029-1.402-3.029-3zm.137-17.055c-.644-.374-1.042-1.07-1.041-1.82v-.003c.001-1.172-.938-2.122-2.096-2.122s-2.097.95-2.097 2.122v.003c.001.751-.396 1.446-1.041 1.82-4.668 2.709-1.985 11.715-6.862 13.306v1.749h20v-1.749c-4.877-1.591-2.193-10.598-6.863-13.306zm-3.137-2.945c.552 0 1 .449 1 1 0 .552-.448 1-1 1s-1-.448-1-1c0-.551.448-1 1-1zm-6.451 16c1.189-1.667 1.605-3.891 1.964-5.815.447-2.39.869-4.648 2.354-5.509 1.38-.801 2.956-.76 4.267 0 1.485.861 1.907 3.119 2.354 5.509.359 1.924.775 4.148 1.964 5.815z"/>
</svg>

After

Width:  |  Height:  |  Size: 648 B

View File

@ -0,0 +1,3 @@
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="m15 21c0 1.598-1.392 3-2.971 3s-3.029-1.402-3.029-3zm.137-17.055c-.644-.374-1.042-1.07-1.041-1.82v-.003c.001-1.172-.938-2.122-2.096-2.122s-2.097.95-2.097 2.122v.003c.001.751-.396 1.446-1.041 1.82-4.668 2.709-1.985 11.715-6.862 13.306v1.749h20v-1.749c-4.877-1.591-2.193-10.598-6.863-13.306zm-3.137-2.945c.552 0 1 .449 1 1 0 .552-.448 1-1 1s-1-.448-1-1c0-.551.448-1 1-1zm-6.451 16c1.189-1.667 1.605-3.891 1.964-5.815.447-2.39.869-4.648 2.354-5.509 1.38-.801 2.956-.76 4.267 0 1.485.861 1.907 3.119 2.354 5.509.359 1.924.775 4.148 1.964 5.815zm15.229-7.679c.18.721.05 1.446-.304 2.035l.97.584c.504-.838.688-1.869.433-2.892-.255-1.024-.9-1.848-1.739-2.351l-.582.97c.589.355 1.043.934 1.222 1.654zm.396-4.346-.597.995c1.023.616 1.812 1.623 2.125 2.874.311 1.251.085 2.51-.53 3.534l.994.598c.536-.892.835-1.926.835-3-.001-1.98-1.01-3.909-2.827-5.001zm-16.73 2.692-.582-.97c-.839.504-1.484 1.327-1.739 2.351-.255 1.023-.071 2.053.433 2.892l.97-.584c-.354-.588-.484-1.314-.304-2.035.179-.72.633-1.299 1.222-1.654zm-4.444 2.308c0 1.074.299 2.108.835 3l.994-.598c-.615-1.024-.841-2.283-.53-3.534.312-1.251 1.101-2.258 2.124-2.873l-.597-.995c-1.817 1.092-2.826 3.021-2.826 5z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,3 @@
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="m22 17.251v1.749h-13.008l2.205-2h7.254c-1.015-1.422-1.465-3.248-1.798-4.949l1.735-1.574c.561 2.98 1.016 5.928 3.612 6.774zm-9.971 6.749c1.578 0 2.971-1.402 2.971-3h-6c0 1.598 1.449 3 3.029 3zm10.971-19.75-20.654 18.734-1.346-1.479 2.762-2.505h-1.762v-1.749c4.877-1.591 2.194-10.597 6.863-13.306.645-.374 1.041-1.069 1.04-1.82v-.003c0-1.172.939-2.122 2.097-2.122s2.097.95 2.097 2.122v.003c-.001.75.396 1.447 1.04 1.82 1.076.624 1.759 1.585 2.236 2.711l4.285-3.886 1.342 1.48zm-12-2.25c0 .552.448 1 1 1s1-.448 1-1c0-.551-.448-1-1-1s-1 .449-1 1zm-5.032 15 9.812-8.898c-.353-1.083-.842-1.961-1.646-2.427-1.312-.76-2.888-.801-4.267 0-1.485.862-1.907 3.119-2.353 5.51-.36 1.924-.776 4.148-1.965 5.815z"/>
</svg>

After

Width:  |  Height:  |  Size: 803 B