1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-06 21:45:38 -05:00

fix: notification warnings & updates

This commit is contained in:
purian23
2025-07-26 01:27:40 -04:00
parent 39e3107db6
commit 308d84bfa1
4 changed files with 169 additions and 137 deletions

View File

@@ -13,7 +13,7 @@ Rectangle {
property bool expanded: NotificationService.expandedGroups[notificationGroup?.key] || false property bool expanded: NotificationService.expandedGroups[notificationGroup?.key] || false
property bool descriptionExpanded: false property bool descriptionExpanded: false
width: parent.width width: parent ? parent.width : 400
height: { height: {
if (expanded) { if (expanded) {
return expandedContent.height + 28; return expandedContent.height + 28;

View File

@@ -12,24 +12,6 @@ PanelWindow {
required property var notificationData required property var notificationData
required property string notificationId required property string notificationId
readonly property bool isPopup: notificationData.popup
readonly property int expireTimeout: notificationData.notification.expireTimeout
property int screenY: 0
onScreenYChanged: margins.top = Theme.barHeight + 16 + screenY
Behavior on screenY {
enabled: !exiting
NumberAnimation {
duration: 220
easing.type: Easing.OutCubic
}
}
property int rowHeight: 132
property bool exiting: false
signal entered()
signal exitFinished()
visible: true visible: true
WlrLayershell.layer: WlrLayershell.Overlay WlrLayershell.layer: WlrLayershell.Overlay
@@ -49,45 +31,32 @@ PanelWindow {
right: 12 right: 12
} }
// Manager drives vertical stacking with this proxy:
property int screenY: 0
onScreenYChanged: margins.top = Theme.barHeight + 16 + screenY
// Disable vertical tween while exiting so there is never diagonal motion
Behavior on screenY {
id: screenYAnim
enabled: !exiting
NumberAnimation { duration: 220; easing.type: Easing.OutCubic }
}
// State
property bool exiting: false
signal entered()
signal exitFinished()
// ---------------- CONTENT: animate this (not the Window) ----------------
Item { Item {
id: content id: content
anchors.fill: parent anchors.fill: parent
transform: Translate { // We animate a Translate so anchors never override horizontal motion
id: tx transform: Translate { id: tx; x: 400 } // start off-screen right
x: 400
Behavior on x {
NumberAnimation {
id: xAnim
duration: 240
easing.type: Easing.OutCubic
onRunningChanged: {
if (!running && win && !win.exiting && Math.abs(tx.x) < 0.5) win.entered();
if (!running && win && win.exiting && Math.abs(tx.x - 96) < 0.5) maybeFinishExit();
}
}
}
}
opacity: win.exiting ? 0 : 1 // Optional: layer while animating for smoothness
Behavior on opacity { layer.enabled: (enterX.running || exitAnim.running)
NumberAnimation {
id: fadeAnim
duration: 200
easing.type: Easing.OutCubic
onRunningChanged: if (!running && win && win.exiting && content && content.opacity === 0) maybeFinishExit()
}
}
scale: win.exiting ? 0.98 : 1.0
Behavior on scale {
NumberAnimation {
duration: 160
easing.type: Easing.OutCubic
}
}
layer.enabled: (Math.abs(tx.x) > 0.5) || win.exiting
layer.smooth: true layer.smooth: true
Rectangle { Rectangle {
@@ -97,8 +66,8 @@ PanelWindow {
anchors.margins: 4 anchors.margins: 4
radius: Theme.cornerRadiusLarge radius: Theme.cornerRadiusLarge
color: Theme.popupBackground() color: Theme.popupBackground()
border.color: notificationData.urgency === 2 ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.3) : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.08) border.color: notificationData && notificationData.urgency === 2 ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.3) : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.08)
border.width: notificationData.urgency === 2 ? 2 : 1 border.width: notificationData && notificationData.urgency === 2 ? 2 : 1
clip: true clip: true
Rectangle { Rectangle {
@@ -136,7 +105,7 @@ PanelWindow {
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
radius: parent.radius radius: parent.radius
visible: notificationData.urgency === 2 visible: notificationData && notificationData.urgency === 2
opacity: 1 opacity: 1
gradient: Gradient { gradient: Gradient {
@@ -171,8 +140,8 @@ PanelWindow {
Rectangle { Rectangle {
id: iconContainer id: iconContainer
readonly property bool hasNotificationImage: notificationData.image && notificationData.image !== "" readonly property bool hasNotificationImage: notificationData && notificationData.image && notificationData.image !== ""
readonly property bool appIconIsImage: notificationData.appIcon && (notificationData.appIcon.startsWith("file://") || notificationData.appIcon.startsWith("http://") || notificationData.appIcon.startsWith("https://")) readonly property bool appIconIsImage: notificationData && notificationData.appIcon && (notificationData.appIcon.startsWith("file://") || notificationData.appIcon.startsWith("http://") || notificationData.appIcon.startsWith("https://"))
property alias iconImage: iconImage property alias iconImage: iconImage
width: 55 width: 55
@@ -190,8 +159,10 @@ PanelWindow {
anchors.margins: 2 anchors.margins: 2
asynchronous: true asynchronous: true
source: { source: {
if (!notificationData) return "";
if (parent.hasNotificationImage) if (parent.hasNotificationImage)
return notificationData.cleanImage; return notificationData.cleanImage || "";
if (notificationData.appIcon) { if (notificationData.appIcon) {
const appIcon = notificationData.appIcon; const appIcon = notificationData.appIcon;
@@ -207,9 +178,9 @@ PanelWindow {
Text { Text {
anchors.centerIn: parent anchors.centerIn: parent
visible: !parent.hasNotificationImage && (!notificationData.appIcon || notificationData.appIcon === "") visible: !parent.hasNotificationImage && (!notificationData || !notificationData.appIcon || notificationData.appIcon === "")
text: { text: {
const appName = notificationData.appName || "?"; const appName = notificationData && notificationData.appName ? notificationData.appName : "?";
return appName.charAt(0).toUpperCase(); return appName.charAt(0).toUpperCase();
} }
font.pixelSize: 20 font.pixelSize: 20
@@ -237,10 +208,13 @@ PanelWindow {
Text { Text {
width: parent.width width: parent.width
text: { text: {
if (notificationData.timeStr.length > 0) if (!notificationData) return "";
return notificationData.appName + " • " + notificationData.timeStr; const appName = notificationData.appName || "";
const timeStr = notificationData.timeStr || "";
if (timeStr.length > 0)
return appName + " • " + timeStr;
else else
return notificationData.appName; return appName;
} }
color: Theme.surfaceVariantText color: Theme.surfaceVariantText
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
@@ -250,7 +224,7 @@ PanelWindow {
} }
Text { Text {
text: notificationData.summary text: notificationData ? (notificationData.summary || "") : ""
color: Theme.surfaceText color: Theme.surfaceText
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
font.weight: Font.Medium font.weight: Font.Medium
@@ -262,11 +236,13 @@ PanelWindow {
Text { Text {
property bool hasUrls: { property bool hasUrls: {
if (!notificationData || !notificationData.body) return false;
const urlRegex = /(https?:\/\/[^\s]+)/g; const urlRegex = /(https?:\/\/[^\s]+)/g;
return urlRegex.test(notificationData.body); return urlRegex.test(notificationData.body);
} }
text: { text: {
if (!notificationData || !notificationData.body) return "";
let bodyText = notificationData.body; let bodyText = notificationData.body;
if (bodyText.length > 105) if (bodyText.length > 105)
bodyText = bodyText.substring(0, 102) + "..."; bodyText = bodyText.substring(0, 102) + "...";
@@ -298,7 +274,8 @@ PanelWindow {
buttonSize: 20 buttonSize: 20
z: 15 z: 15
onClicked: { onClicked: {
notificationData.popup = false; if (notificationData)
notificationData.popup = false;
} }
} }
} }
@@ -311,64 +288,85 @@ PanelWindow {
propagateComposedEvents: true propagateComposedEvents: true
z: 0 z: 0
onEntered: { onEntered: {
notificationData.timer.stop(); if (notificationData && notificationData.timer)
notificationData.timer.stop();
} }
onExited: { onExited: {
if (notificationData.popup) if (notificationData && notificationData.popup && notificationData.timer)
notificationData.timer.restart(); notificationData.timer.restart();
} }
onClicked: { onClicked: {
notificationData.popup = false; if (notificationData)
notificationData.popup = false;
} }
} }
} }
} }
Component.onCompleted: { // ---------------- EXPLICIT ANIMATIONS (no Behavior races) ----------------
enterDelay.start(); // Entrance (guaranteed): 400 -> 0
Qt.callLater(() => { tx.x = 0; }); NumberAnimation {
id: enterX
target: tx; property: "x"; from: 400; to: 0
duration: 240; easing.type: Easing.OutCubic
onStopped: if (!win.exiting && Math.abs(tx.x) < 0.5) win.entered();
} }
Timer { // Exit (guaranteed): (x: 0 -> 96) + (opacity: 1 -> 0)
id: enterDelay ParallelAnimation {
interval: Anims.durMed id: exitAnim
repeat: false PropertyAnimation { target: tx; property: "x"; from: 0; to: 96; duration: 200; easing.type: Easing.OutCubic }
onTriggered: notificationData.timer.start() NumberAnimation { target: content; property: "opacity"; from: 1; to: 0; duration: 200; easing.type: Easing.OutCubic }
NumberAnimation { target: content; property: "scale"; from: 1; to: 0.98; duration: 160; easing.type: Easing.OutCubic }
onStopped: finalizeExit("animStopped")
} }
// Start entrance one tick after create (so it always animates)
Component.onCompleted: Qt.callLater(() => enterX.restart())
// Safe connection to wrapper: disable automatically when wrapper is null
Connections { Connections {
target: notificationData id: wrapperConn
target: win.notificationData || null
ignoreUnknownSignals: true
function onPopupChanged() { function onPopupChanged() {
if (!notificationData.popup && !win.exiting) { if (!win.notificationData) return; // guard
win.exiting = true; if (!win.notificationData.popup && !win.exiting) {
win.screenY = win.screenY; // Freeze vertical and start exit
tx.x = 96; win.exiting = true; // disables screenY Behavior
exitWatchdog.restart(); exitAnim.restart();
forceCleanupTimer.restart(); exitWatchdog.restart(); // safety net
NotificationService.removeFromVisibleNotifications(notificationData); if (NotificationService.removeFromVisibleNotifications)
NotificationService.removeFromVisibleNotifications(win.notificationData);
} }
} }
} }
onNotificationDataChanged: wrapperConn.target = win.notificationData || null
// Timer to start on entrance
Timer { Timer {
id: exitWatchdog id: enterDelay
interval: 500 interval: 160
repeat: false repeat: false
onTriggered: if (win) win.exitFinished() onTriggered: {
} if (notificationData && notificationData.timer)
notificationData.timer.start();
Timer {
id: forceCleanupTimer
interval: 2000
repeat: false
onTriggered: if (win) win.exitFinished()
}
function maybeFinishExit() {
if (win && win.exiting && content && Math.abs(tx.x - 96) < 0.5 && content.opacity === 0) {
exitWatchdog.stop();
forceCleanupTimer.stop();
win.exitFinished();
} }
} }
// Start timer after entrance animation
onEntered: enterDelay.start()
// Idempotent finalizer so we never "half-exit"
property bool _finalized: false
function finalizeExit(reason) {
if (_finalized) return;
_finalized = true;
exitWatchdog.stop();
win.exitFinished(); // manager will destroy the window
}
Timer { id: exitWatchdog; interval: 600; repeat: false; onTriggered: finalizeExit("watchdog") }
// If the popup is torn down unexpectedly, don't leave dangling timers
Component.onDestruction: { exitWatchdog.stop(); }
} }

View File

@@ -5,18 +5,14 @@ import qs.Services
QtObject { QtObject {
id: manager id: manager
property int topMargin: 48
property int maxTargetNotifications: 3
property int baseNotificationHeight: 132 property int baseNotificationHeight: 132
property int topMargin: 0 property int maxTargetNotifications: 3
property var popupWindows: [] property var popupWindows: [] // strong refs to windows (live until exitFinished)
// Factory
property Component popupComponent: Component { property Component popupComponent: Component {
NotificationPopup { NotificationPopup {
property var wrapper
notificationData: wrapper
notificationId: wrapper.notification.id
rowHeight: manager.baseNotificationHeight
onEntered: manager._onPopupEntered(this) onEntered: manager._onPopupEntered(this)
onExitFinished: manager._onPopupExitFinished(this) onExitFinished: manager._onPopupExitFinished(this)
} }
@@ -29,77 +25,115 @@ QtObject {
} }
} }
function _hasWindowFor(w) { return popupWindows.some(p => p && p.notificationData === w); } function _hasWindowFor(w) {
return popupWindows.some(p => p && p.notificationData === w);
}
function _sync(newWrappers) { function _sync(newWrappers) {
for (let w of newWrappers) { for (let w of newWrappers) {
if (!_hasWindowFor(w)) _insertNewestAtTop(w); if (!_hasWindowFor(w)) insertNewestAtTop(w);
} }
for (let p of popupWindows.slice()) { for (let p of popupWindows.slice()) {
if (newWrappers.indexOf(p.notificationData) === -1 && p && !p.exiting) { if (p && p.notificationData && newWrappers.indexOf(p.notificationData) === -1 && !p.exiting) {
p.notificationData.removedByLimit = true; p.notificationData.removedByLimit = true;
p.notificationData.popup = false; p.notificationData.popup = false;
} }
} }
} }
function _insertNewestAtTop(wrapper) { // Insert newest at top
function insertNewestAtTop(wrapper) {
// Shift live, non-exiting windows down *now*
for (let p of popupWindows) { for (let p of popupWindows) {
if (p && p.notificationData && p.notificationData.popup && !p.exiting) { if (!p) continue;
p.screenY = p.screenY + baseNotificationHeight; if (p.exiting) continue;
} // Guard: skip if p is already being destroyed
if (p.status === Component.Null) continue;
p.screenY = p.screenY + baseNotificationHeight;
} }
const win = popupComponent.createObject(null, { wrapper: wrapper, screenY: topMargin }); // Create the new top window at fixed Y
if (!win) { const notificationId = wrapper && wrapper.notification ? wrapper.notification.id : "";
console.warn("Popup create failed"); const win = popupComponent.createObject(null, { notificationData: wrapper, notificationId: notificationId, screenY: topMargin });
return; if (!win) {
console.warn("Popup create failed");
return;
} }
popupWindows.push(win); popupWindows.push(win);
_maybeStartOverflow(); _maybeStartOverflow();
} }
function _active() {
return popupWindows.filter(p => p && p.notificationData && p.notificationData.popup);
}
// Overflow: keep one extra (slot #4), then ask bottom to exit gracefully
function _active() {
return popupWindows.filter(p => p && p.notificationData && p.notificationData.popup);
}
function _bottom() { function _bottom() {
let b = null, max = -1; let b = null, maxY = -1;
for (let p of _active()) { for (let p of _active()) {
if (!p.exiting && p.screenY > max) { if (p.exiting) continue;
max = p.screenY; if (p.screenY > maxY) {
b = p; maxY = p.screenY;
b = p;
} }
} }
return b; return b;
} }
function _maybeStartOverflow() { function _maybeStartOverflow() {
if (_active().length <= maxTargetNotifications + 1) return; if (_active().length <= maxTargetNotifications + 1) return;
const b = _bottom(); const b = _bottom();
if (b && !b.exiting) { if (b && !b.exiting) {
// Tell the popup to animate out (don't destroy here)
b.notificationData.removedByLimit = true; b.notificationData.removedByLimit = true;
b.notificationData.popup = false; b.notificationData.popup = false;
} }
} }
function _onPopupEntered(p) { // After entrance, you may kick overflow (optional)
// Entry completed function _onPopupEntered(p) {
_maybeStartOverflow();
} }
// Primary cleanup path (after the popup finishes its exit)
function _onPopupExitFinished(p) { function _onPopupExitFinished(p) {
const i = popupWindows.indexOf(p); const i = popupWindows.indexOf(p);
if (i !== -1) { if (i !== -1) {
popupWindows.splice(i, 1); popupWindows.splice(i,1);
popupWindows = popupWindows.slice(); popupWindows = popupWindows.slice();
} }
if (NotificationService.releaseWrapper) NotificationService.releaseWrapper(p.notificationData); if (NotificationService.releaseWrapper)
NotificationService.releaseWrapper(p.notificationData);
// Finally destroy the window object
p.destroy(); p.destroy();
const survivors = _active().filter(s => !s.exiting).sort((a,b) => a.screenY - b.screenY); // Compact survivors (only live, non-exiting)
const survivors = _active().filter(s => !s.exiting)
.sort((a,b) => a.screenY - b.screenY);
for (let k = 0; k < survivors.length; ++k) for (let k = 0; k < survivors.length; ++k)
survivors[k].screenY = topMargin + k * baseNotificationHeight; survivors[k].screenY = topMargin + k * baseNotificationHeight;
_maybeStartOverflow(); _maybeStartOverflow();
} }
// Optional sweeper (dev only): catch any stranded windows every 2s
property Timer sweeper: Timer {
interval: 2000
running: true
repeat: true
onTriggered: {
for (let p of popupWindows.slice()) {
if (!p) continue;
if (!p.visible && !p.notificationData) {
const i = popupWindows.indexOf(p);
if (i !== -1) {
popupWindows.splice(i,1);
popupWindows = popupWindows.slice();
}
}
}
}
}
} }

View File

@@ -11,7 +11,7 @@ Column {
SysMonitorService.addRef(); SysMonitorService.addRef();
SysMonitorService.addRef(); SysMonitorService.addRef();
// Trigger immediate updates for both services // Trigger immediate updates for both services
SysMonitorService.updateSystemStats(); SysMonitorService.updateAllStats();
} }
Component.onDestruction: { Component.onDestruction: {