mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-21 16:51:57 +00:00
downloads notif fix
This commit is contained in:
parent
2494d45e8f
commit
8d918cdf5e
2 changed files with 81 additions and 61 deletions
|
|
@ -56,6 +56,8 @@ class NotificationService {
|
|||
private appStateSubscription: any = null;
|
||||
private lastSyncTime: number = 0;
|
||||
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() {
|
||||
// Initialize notifications
|
||||
|
|
@ -327,6 +329,21 @@ class NotificationService {
|
|||
try {
|
||||
if (!this.settings.enabled) 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 totalMb = totalBytes ? Math.floor(totalBytes / (1024 * 1024)) : undefined;
|
||||
const body = `${progress}%` + (totalMb !== undefined ? ` • ${downloadedMb}MB / ${totalMb}MB` : '');
|
||||
|
|
@ -348,6 +365,7 @@ class NotificationService {
|
|||
try {
|
||||
if (!this.settings.enabled) return;
|
||||
if (AppState.currentState === 'active') return;
|
||||
|
||||
await Notifications.scheduleNotificationAsync({
|
||||
content: {
|
||||
title: 'Download complete',
|
||||
|
|
@ -356,6 +374,9 @@ class NotificationService {
|
|||
},
|
||||
trigger: null,
|
||||
});
|
||||
|
||||
// Clean up tracking entry after completion to prevent memory leaks
|
||||
this.lastDownloadNotificationTime.delete(title);
|
||||
} catch (error) {
|
||||
logger.error('[NotificationService] notifyDownloadComplete error:', error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
Subproject commit b22f2a386d86fbb31a5f60af62153e9ce77390a5
|
||||
Loading…
Reference in a new issue