fix: memory leak hunting and reconnecting on data error

This commit is contained in:
2026-05-18 19:37:30 +02:00
parent dea114aed0
commit 0152ed9dd2
5 changed files with 148 additions and 60 deletions

View File

@@ -62,6 +62,9 @@ import { listRunningProcessNames } from '../process-list';
import { detectActiveGame } from '../game-detection';
const DEFAULT_MIME_TYPE = 'application/octet-stream';
const MAX_ACTIVE_DESKTOP_NOTIFICATIONS = 20;
const activeDesktopNotifications = new Set<Notification>();
const desktopNotificationCleanups = new Map<Notification, () => void>();
const FILE_CLIPBOARD_FORMATS = [
'x-special/gnome-copied-files',
'text/uri-list',
@@ -399,9 +402,16 @@ export function setupSystemHandlers(): void {
icon: getWindowIconPath(),
silent: true
});
notification.on('click', () => {
const cleanup = () => {
notification.removeListener('click', handleClick);
notification.removeListener('close', cleanup);
notification.removeListener('failed', cleanup);
activeDesktopNotifications.delete(notification);
desktopNotificationCleanups.delete(notification);
};
const handleClick = () => {
if (!mainWindow) {
cleanup();
return;
}
@@ -414,7 +424,26 @@ export function setupSystemHandlers(): void {
}
mainWindow.focus();
});
cleanup();
notification.close();
};
notification.on('click', handleClick);
notification.once('close', cleanup);
notification.once('failed', cleanup);
activeDesktopNotifications.add(notification);
desktopNotificationCleanups.set(notification, cleanup);
while (activeDesktopNotifications.size > MAX_ACTIVE_DESKTOP_NOTIFICATIONS) {
const oldestNotification = activeDesktopNotifications.values().next().value;
if (!oldestNotification) {
break;
}
desktopNotificationCleanups.get(oldestNotification)?.();
oldestNotification.close();
}
notification.show();
} catch {