fix: memory leak hunting and reconnecting on data error
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user