Test
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Services.Notifications
|
||||
import Quickshell.Widgets
|
||||
import "../../config"
|
||||
|
||||
Rectangle {
|
||||
@@ -78,13 +77,14 @@ Rectangle {
|
||||
height: 28
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
IconImage {
|
||||
Image {
|
||||
id: notifIcon
|
||||
anchors.fill: parent
|
||||
icon: notification.appIcon
|
||||
source: notification.appIcon ? "file://" + notification.appIcon : ""
|
||||
sourceSize.width: 28
|
||||
sourceSize.height: 28
|
||||
visible: notification.appIcon !== ""
|
||||
asynchronous: true
|
||||
visible: status === Image.Ready
|
||||
}
|
||||
|
||||
Text {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Services.Notifications
|
||||
import Quickshell.Widgets
|
||||
import "../../config"
|
||||
|
||||
MouseArea {
|
||||
@@ -44,13 +43,15 @@ MouseArea {
|
||||
height: Config.iconSize(indicator.height)
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
IconImage {
|
||||
Image {
|
||||
id: notifIcon
|
||||
anchors.fill: parent
|
||||
icon: manager.lastNotification ? manager.lastNotification.appIcon : ""
|
||||
source: (manager.lastNotification && manager.lastNotification.appIcon)
|
||||
? "file://" + manager.lastNotification.appIcon : ""
|
||||
sourceSize.width: Config.iconSize(indicator.height)
|
||||
sourceSize.height: Config.iconSize(indicator.height)
|
||||
visible: manager.lastNotification && manager.lastNotification.appIcon !== ""
|
||||
asynchronous: true
|
||||
visible: status === Image.Ready
|
||||
}
|
||||
|
||||
Text {
|
||||
@@ -159,9 +160,7 @@ MouseArea {
|
||||
radius: Config.small_radius
|
||||
color: Qt.alpha(Colors.surfaceContainerHighest, 0.5)
|
||||
|
||||
required property var model
|
||||
|
||||
property var notif: model.object
|
||||
property var notif: modelData
|
||||
|
||||
Row {
|
||||
anchors {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import QtQuick
|
||||
import QtMultimedia
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Services.Notifications
|
||||
import "../../config"
|
||||
|
||||
@@ -9,6 +9,7 @@ Item {
|
||||
|
||||
NotificationServer {
|
||||
id: notificationServer
|
||||
|
||||
imageSupported: true
|
||||
actionsSupported: true
|
||||
bodyMarkupSupported: false
|
||||
@@ -19,18 +20,20 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
property ObjectModel notifications: ObjectModel {}
|
||||
readonly property ObjectModel notifications: notificationServer.trackedNotifications
|
||||
|
||||
property int notificationCount: 0
|
||||
property var lastNotification: null
|
||||
property bool hasCritical: false
|
||||
|
||||
readonly property string soundDir: Config.configDir + "/assets/sounds"
|
||||
|
||||
property var _trackedIds: ({})
|
||||
property var _dismissTimes: ({})
|
||||
|
||||
function onNotificationReceived(notification) {
|
||||
notifications.append(notification)
|
||||
notificationCount = notifications.count
|
||||
_trackedIds[notification.id] = true
|
||||
notificationCount = Object.keys(_trackedIds).length
|
||||
lastNotification = notification
|
||||
if (notification.urgency === NotificationUrgency.Critical)
|
||||
hasCritical = true
|
||||
@@ -41,26 +44,22 @@ Item {
|
||||
|
||||
function playSound(urgency) {
|
||||
var path
|
||||
var vol
|
||||
switch (urgency) {
|
||||
case NotificationUrgency.Low:
|
||||
path = soundDir + "/notification-low.oga"
|
||||
vol = 0.35
|
||||
break
|
||||
case NotificationUrgency.Critical:
|
||||
path = soundDir + "/notification-critical.oga"
|
||||
vol = 1.0
|
||||
break
|
||||
default:
|
||||
path = soundDir + "/notification-normal.oga"
|
||||
vol = 0.7
|
||||
break
|
||||
}
|
||||
|
||||
if (player.hasAudio) player.stop()
|
||||
player.source = "file://" + path
|
||||
audioOutput.volume = vol
|
||||
player.play()
|
||||
soundProc.command = [
|
||||
"sh", "-c",
|
||||
"pw-play \"" + path + "\" 2>/dev/null || paplay \"" + path + "\" 2>/dev/null || ffplay -nodisp -autoexit \"" + path + "\" 2>/dev/null"
|
||||
]
|
||||
soundProc.running = true
|
||||
}
|
||||
|
||||
function scheduleDismiss(notification) {
|
||||
@@ -77,44 +76,27 @@ Item {
|
||||
}
|
||||
|
||||
function dismissNotification(notification) {
|
||||
delete _trackedIds[notification.id]
|
||||
delete _dismissTimes[notification.id]
|
||||
notificationCount = Object.keys(_trackedIds).length
|
||||
notification.tracked = false
|
||||
refreshMetadata()
|
||||
}
|
||||
|
||||
function refreshMetadata() {
|
||||
hasCritical = false
|
||||
lastNotification = null
|
||||
for (var i = 0; i < notifications.count; i++) {
|
||||
if (notifications.get(i).id === notification.id) {
|
||||
notifications.remove(i)
|
||||
break
|
||||
var n = notifications.get(i)
|
||||
if (_trackedIds[n.id]) {
|
||||
lastNotification = n
|
||||
if (n.urgency === NotificationUrgency.Critical)
|
||||
hasCritical = true
|
||||
}
|
||||
}
|
||||
notificationCount = notifications.count
|
||||
delete _dismissTimes[notification.id]
|
||||
if (notificationCount === 0) {
|
||||
hasCritical = false
|
||||
lastNotification = null
|
||||
} else {
|
||||
lastNotification = notifications.get(0)
|
||||
hasCritical = false
|
||||
for (var j = 0; j < notifications.count; j++) {
|
||||
if (notifications.get(j).urgency === NotificationUrgency.Critical) {
|
||||
hasCritical = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
notification.tracked = false
|
||||
}
|
||||
|
||||
function dismissById(nid) {
|
||||
for (var i = 0; i < notifications.count; i++) {
|
||||
var n = notifications.get(i)
|
||||
if (n.id === nid) {
|
||||
dismissNotification(n)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function dismissAll() {
|
||||
while (notifications.count > 0) {
|
||||
var n = notifications.get(0)
|
||||
dismissNotification(n)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,24 +106,24 @@ Item {
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
var now = Date.now() / 1000
|
||||
var toDismiss = []
|
||||
for (var i = 0; i < notifications.count; i++) {
|
||||
var n = notifications.get(i)
|
||||
var t = _dismissTimes[n.id]
|
||||
if (t !== undefined && now >= t)
|
||||
toDismiss.push(n)
|
||||
for (var id in _dismissTimes) {
|
||||
if (_dismissTimes[id] <= now) {
|
||||
for (var i = 0; i < notifications.count; i++) {
|
||||
var n = notifications.get(i)
|
||||
if (n.id.toString() === id) {
|
||||
dismissNotification(n)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var j = 0; j < toDismiss.length; j++)
|
||||
dismissNotification(toDismiss[j])
|
||||
if (notifications.count === 0)
|
||||
if (Object.keys(_trackedIds).length === 0)
|
||||
running = false
|
||||
}
|
||||
}
|
||||
|
||||
MediaPlayer {
|
||||
id: player
|
||||
audioOutput: AudioOutput {
|
||||
id: audioOutput
|
||||
}
|
||||
Process {
|
||||
id: soundProc
|
||||
running: false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ Variants {
|
||||
|
||||
delegate: NotificationCard {
|
||||
width: contentColumn.width
|
||||
notification: model.object
|
||||
notification: modelData
|
||||
manager: root.manager
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user