downloads notif fix

This commit is contained in:
tapframe 2025-11-25 02:10:29 +05:30
parent 2494d45e8f
commit 8d918cdf5e
2 changed files with 81 additions and 61 deletions

View file

@ -56,6 +56,8 @@ class NotificationService {
private appStateSubscription: any = null; private appStateSubscription: any = null;
private lastSyncTime: number = 0; private lastSyncTime: number = 0;
private readonly MIN_SYNC_INTERVAL = 5 * 60 * 1000; // 5 minutes minimum between syncs private readonly MIN_SYNC_INTERVAL = 5 * 60 * 1000; // 5 minutes minimum between syncs
// Download notification tracking - stores progress value (50) when notified
private lastDownloadNotificationTime: Map<string, number> = new Map();
private constructor() { private constructor() {
// Initialize notifications // Initialize notifications
@ -157,8 +159,8 @@ class NotificationService {
// Check if notification already exists for this episode // Check if notification already exists for this episode
const existingNotification = this.scheduledNotifications.find( const existingNotification = this.scheduledNotifications.find(
notification => notification.seriesId === item.seriesId && notification => notification.seriesId === item.seriesId &&
notification.season === item.season && notification.season === item.season &&
notification.episode === item.episode notification.episode === item.episode
); );
if (existingNotification) { if (existingNotification) {
return null; // Don't schedule duplicate notifications return null; // Don't schedule duplicate notifications
@ -327,6 +329,21 @@ class NotificationService {
try { try {
if (!this.settings.enabled) return; if (!this.settings.enabled) return;
if (AppState.currentState === 'active') return; if (AppState.currentState === 'active') return;
// Only notify at 50% progress
if (progress < 50) {
return; // Skip notifications before 50%
}
// Check if we've already notified at 50% for this download
const lastNotifiedProgress = this.lastDownloadNotificationTime.get(title) || 0;
if (lastNotifiedProgress >= 50) {
return; // Already notified at 50%, don't notify again
}
// Mark that we've notified at 50%
this.lastDownloadNotificationTime.set(title, 50);
const downloadedMb = Math.floor((downloadedBytes || 0) / (1024 * 1024)); const downloadedMb = Math.floor((downloadedBytes || 0) / (1024 * 1024));
const totalMb = totalBytes ? Math.floor(totalBytes / (1024 * 1024)) : undefined; const totalMb = totalBytes ? Math.floor(totalBytes / (1024 * 1024)) : undefined;
const body = `${progress}%` + (totalMb !== undefined ? `${downloadedMb}MB / ${totalMb}MB` : ''); const body = `${progress}%` + (totalMb !== undefined ? `${downloadedMb}MB / ${totalMb}MB` : '');
@ -348,6 +365,7 @@ class NotificationService {
try { try {
if (!this.settings.enabled) return; if (!this.settings.enabled) return;
if (AppState.currentState === 'active') return; if (AppState.currentState === 'active') return;
await Notifications.scheduleNotificationAsync({ await Notifications.scheduleNotificationAsync({
content: { content: {
title: 'Download complete', title: 'Download complete',
@ -356,6 +374,9 @@ class NotificationService {
}, },
trigger: null, trigger: null,
}); });
// Clean up tracking entry after completion to prevent memory leaks
this.lastDownloadNotificationTime.delete(title);
} catch (error) { } catch (error) {
logger.error('[NotificationService] notifyDownloadComplete error:', error); logger.error('[NotificationService] notifyDownloadComplete error:', error);
} }
@ -716,7 +737,7 @@ class NotificationService {
this.scheduledNotifications = validNotifications; this.scheduledNotifications = validNotifications;
await this.saveScheduledNotifications(); await this.saveScheduledNotifications();
// Reduced logging verbosity // Reduced logging verbosity
// logger.log(`[NotificationService] Cleaned up ${this.scheduledNotifications.length - validNotifications.length} old notifications`); // logger.log(`[NotificationService] Cleaned up ${this.scheduledNotifications.length - validNotifications.length} old notifications`);
} }
} catch (error) { } catch (error) {
logger.error('[NotificationService] Error cleaning up notifications:', error); logger.error('[NotificationService] Error cleaning up notifications:', error);

@ -1 +0,0 @@
Subproject commit b22f2a386d86fbb31a5f60af62153e9ce77390a5