notifications working
This commit is contained in:
93
Bar/Time.qml
93
Bar/Time.qml
@@ -1,7 +1,9 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import Quickshell
|
||||
import Quickshell.Hyprland
|
||||
import Quickshell.Services.Notifications
|
||||
|
||||
import "../Color.js" as Colors
|
||||
import "../Components/"
|
||||
@@ -10,32 +12,121 @@ import "../Services/"
|
||||
Container {
|
||||
id: root
|
||||
|
||||
property Notification latestNotif
|
||||
property double latestNotifId: latestNotif.id || 0
|
||||
required property HyprlandMonitor monitor
|
||||
property bool notified: false
|
||||
property bool overriden: false
|
||||
|
||||
boxColor: Colors.mauve
|
||||
defaultItem: time
|
||||
exclusiveMonitor: root.monitor
|
||||
|
||||
states: [
|
||||
State {
|
||||
name: "closed"
|
||||
when: root.hovered == false && root.overriden == false
|
||||
|
||||
PropertyChanges {
|
||||
root.boxHeight: 28
|
||||
root.boxRadius: 9
|
||||
root.boxWidth: 100
|
||||
}
|
||||
|
||||
StateChangeScript {
|
||||
script: {
|
||||
if (root.stack.currentItem.component != "time") {
|
||||
root.stack.replace(time);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
State {
|
||||
name: "hovered"
|
||||
when: root.hovered == true
|
||||
when: root.hovered == true && root.overriden == false
|
||||
|
||||
PropertyChanges {
|
||||
root.boxHeight: 32
|
||||
root.boxRadius: 12
|
||||
root.boxWidth: 107
|
||||
}
|
||||
|
||||
StateChangeScript {
|
||||
script: {
|
||||
root.stack.replace(time);
|
||||
}
|
||||
}
|
||||
},
|
||||
State {
|
||||
name: "notified"
|
||||
when: root.notified == true
|
||||
|
||||
PropertyChanges {
|
||||
root.boxHeight: 32
|
||||
root.boxRadius: 12
|
||||
root.boxWidth: 200
|
||||
}
|
||||
|
||||
StateChangeScript {
|
||||
script: {
|
||||
root.stack.replace(notification);
|
||||
console.log("notification");
|
||||
notificationTimer.restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Connections {
|
||||
function onNewNotification() {
|
||||
notification => {
|
||||
if (notification != root.latestNotif) {
|
||||
root.latestNotif = notification;
|
||||
root.overriden = true;
|
||||
root.notified = true;
|
||||
} else {
|
||||
console.log("notif already called");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
target: NotificationManager
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: notificationTimer
|
||||
|
||||
interval: 2000
|
||||
repeat: false
|
||||
running: false
|
||||
|
||||
onTriggered: {
|
||||
root.notified = false;
|
||||
root.overriden = false;
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: time
|
||||
|
||||
StyledText {
|
||||
property string component: "time"
|
||||
|
||||
horizontalAlignment: Qt.AlignCenter
|
||||
text: Time.time
|
||||
verticalAlignment: Qt.AlignVCenter
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: notification
|
||||
|
||||
StyledText {
|
||||
property string component: "notification"
|
||||
|
||||
horizontalAlignment: Qt.AlignCenter
|
||||
text: root.latestNotif.summary
|
||||
verticalAlignment: Qt.AlignVCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ Singleton {
|
||||
|
||||
property alias notif: server
|
||||
|
||||
signal newNotification(notificiation: Notification)
|
||||
|
||||
function getLatestNotification() {
|
||||
let notificationList = server.trackedNotifications.values;
|
||||
let len = notificationList.length;
|
||||
@@ -27,6 +29,7 @@ Singleton {
|
||||
|
||||
onNotification: notification => {
|
||||
notification.tracked = true;
|
||||
root.newNotification(notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user