1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-07 05:55:37 -05:00

General code cleanups

This commit is contained in:
bbedward
2025-08-02 16:18:12 -04:00
parent 2cf7497324
commit 599118c63e
68 changed files with 102 additions and 1241 deletions

View File

@@ -11,9 +11,7 @@ QtObject {
property int baseNotificationHeight: 120
property int maxTargetNotifications: 3
property var popupWindows: [] // strong refs to windows (live until exitFinished)
// Track destroying windows to prevent duplicate cleanup
property var destroyingWindows: new Set()
// Factory
property Component popupComponent
popupComponent: Component {
@@ -34,7 +32,6 @@ QtObject {
target: NotificationService
}
// Smart sweeper that only runs when needed
property Timer sweeper
sweeper: Timer {
@@ -48,24 +45,21 @@ QtObject {
toRemove.push(p);
continue;
}
// Check for various zombie conditions
const isZombie = p.status === Component.Null || (!p.visible && !p.exiting) || (!p.notificationData && !p._isDestroying) || (!p.hasValidData && !p._isDestroying);
if (isZombie) {
console.warn("Sweeper found zombie window, cleaning up");
toRemove.push(p);
// Try to force cleanup
if (p.forceExit) {
p.forceExit();
} else if (p.destroy) {
try {
p.destroy();
} catch (e) {
console.warn("Error destroying zombie:", e);
}
}
}
}
// Remove all zombies from array
if (toRemove.length > 0) {
for (let zombie of toRemove) {
const i = popupWindows.indexOf(zombie);
@@ -74,7 +68,6 @@ QtObject {
}
popupWindows = popupWindows.slice();
// Recompact after cleanup
const survivors = _active().sort((a, b) => {
return a.screenY - b.screenY;
});
@@ -82,7 +75,6 @@ QtObject {
survivors[k].screenY = topMargin + k * baseNotificationHeight;
}
}
// Stop the timer if no windows remain
if (popupWindows.length === 0)
sweeper.stop();
@@ -91,7 +83,6 @@ QtObject {
function _hasWindowFor(w) {
return popupWindows.some((p) => {
// More robust check for valid windows
return p && p.notificationData === w && !p._isDestroying && p.status !== Component.Null;
});
}
@@ -101,13 +92,11 @@ QtObject {
}
function _sync(newWrappers) {
// Add new notifications
for (let w of newWrappers) {
if (w && !_hasWindowFor(w))
insertNewestAtTop(w);
}
// Remove old notifications
for (let p of popupWindows.slice()) {
if (!_isValidWindow(p))
continue;
@@ -119,13 +108,11 @@ QtObject {
}
}
// Insert newest at top
function insertNewestAtTop(wrapper) {
if (!wrapper) {
console.warn("insertNewestAtTop: wrapper is null");
return ;
}
// Shift live, non-exiting windows down *now*
for (let p of popupWindows) {
if (!_isValidWindow(p))
continue;
@@ -135,7 +122,6 @@ QtObject {
p.screenY = p.screenY + baseNotificationHeight;
}
// Create the new top window at fixed Y
const notificationId = wrapper && wrapper.notification ? wrapper.notification.id : "";
const win = popupComponent.createObject(null, {
"notificationData": wrapper,
@@ -144,24 +130,21 @@ QtObject {
"screen": manager.modelData
});
if (!win) {
console.warn("Popup create failed");
return ;
}
// Validate the window was created properly
if (!win.hasValidData) {
console.warn("Popup created with invalid data, destroying");
win.destroy();
return ;
}
popupWindows.push(win);
// Start sweeper if it's not running
if (!sweeper.running)
sweeper.start();
_maybeStartOverflow();
}
// Overflow: keep one extra (slot #4), then ask bottom to exit gracefully
function _active() {
return popupWindows.filter((p) => {
return _isValidWindow(p) && p.notificationData && p.notificationData.popup && !p.exiting;
@@ -186,55 +169,46 @@ QtObject {
const b = _bottom();
if (b && !b.exiting) {
// Tell the popup to animate out (don't destroy here)
b.notificationData.removedByLimit = true;
b.notificationData.popup = false;
}
}
// After entrance, you may kick overflow (optional)
function _onPopupEntered(p) {
if (_isValidWindow(p))
_maybeStartOverflow();
}
// Primary cleanup path (after the popup finishes its exit)
function _onPopupExitFinished(p) {
if (!p)
return ;
// Prevent duplicate cleanup
const windowId = p.toString();
if (destroyingWindows.has(windowId))
return ;
destroyingWindows.add(windowId);
// Remove from popupWindows
const i = popupWindows.indexOf(p);
if (i !== -1) {
popupWindows.splice(i, 1);
popupWindows = popupWindows.slice();
}
// Release the wrapper
if (NotificationService.releaseWrapper && p.notificationData)
NotificationService.releaseWrapper(p.notificationData);
// Schedule destruction
Qt.callLater(() => {
if (p && p.destroy) {
try {
p.destroy();
} catch (e) {
console.warn("Error destroying popup:", e);
}
}
// Clean up tracking after a delay
Qt.callLater(() => {
destroyingWindows.delete(windowId);
});
});
// Compact survivors (only live, non-exiting)
const survivors = _active().sort((a, b) => {
return a.screenY - b.screenY;
});
@@ -244,7 +218,6 @@ QtObject {
_maybeStartOverflow();
}
// Emergency cleanup function
function cleanupAllWindows() {
sweeper.stop();
for (let p of popupWindows.slice()) {
@@ -255,7 +228,7 @@ QtObject {
else if (p.destroy)
p.destroy();
} catch (e) {
console.warn("Error during emergency cleanup:", e);
}
}
}
@@ -263,7 +236,6 @@ QtObject {
destroyingWindows.clear();
}
// Watch for changes to popup windows array
onPopupWindowsChanged: {
if (popupWindows.length > 0 && !sweeper.running)
sweeper.start();