55 lines
1.5 KiB
QML
55 lines
1.5 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 — recomputed whenever NotifService._now ticks (single global 5s timer)
|
|
readonly property string timeStr: {
|
|
const diff = M.NotifService._now - time;
|
|
const m = Math.floor(diff / 60000);
|
|
if (m < 1)
|
|
return "now";
|
|
const h = Math.floor(m / 60);
|
|
if (h < 1)
|
|
return m + "m";
|
|
const d = Math.floor(h / 24);
|
|
return d > 0 ? d + "d" : h + "h";
|
|
}
|
|
|
|
function beginDismiss() {
|
|
if (state === "visible")
|
|
state = "dismissing";
|
|
}
|
|
|
|
function finishDismiss() {
|
|
state = "dismissed";
|
|
_expireTimer.running = false;
|
|
notification?.dismiss();
|
|
}
|
|
}
|