nova-shell/modules/NotifItem.qml

67 lines
1.7 KiB
QML

import QtQuick
import Quickshell.Services.Notifications
import "." as M
QtObject {
id: root
property bool popup: false
property string state: "visible" // "visible" | "dismissing" | "dismissed"
property var notification: null
property var id
property string summary
property string body
property string appName
property string appIcon
property string image
property var hints
property int urgency: NotificationUrgency.Normal
property var actions: []
property real time: Date.now()
// Expire timer — owned by this item, not dynamically created
readonly property Timer _expireTimer: Timer {
running: false
onTriggered: {
if (root.state === "visible")
root.popup = false;
}
}
// Relative time string
property string timeStr: "now"
readonly property Timer _timeStrTimer: Timer {
running: root.state !== "dismissed"
repeat: true
interval: 5000
onTriggered: root._updateTimeStr()
}
function _updateTimeStr() {
const diff = Date.now() - time;
const m = Math.floor(diff / 60000);
if (m < 1) {
timeStr = "now";
return;
}
const h = Math.floor(m / 60);
if (h < 1) {
timeStr = m + "m";
return;
}
const d = Math.floor(h / 24);
timeStr = d > 0 ? d + "d" : h + "h";
}
function beginDismiss() {
if (state === "visible")
state = "dismissing";
}
function finishDismiss() {
state = "dismissed";
_expireTimer.running = false;
notification?.dismiss();
}
}