onSignalRNotificationReceived method

Future<void> onSignalRNotificationReceived(
  1. Map<String, dynamic> jsonPayload
)

Hook for the main app's SignalRService to invoke when backend file generation finishes. Automatically refreshes list and displays a premium UI snackbar/notification.

Implementation

Future<void> onSignalRNotificationReceived(Map<String, dynamic> jsonPayload) async {
  try {
    final notification = DownloadsNotificationModel.fromJson(jsonPayload);
    debugPrint('[DownloadController] SignalR notification received for: ${notification.message}');

    // 1. Immediately force-refresh downloads to get the updated status & fileUrl
    await loadDownloadsIfNeeded(force: true);

    // 2. Display a premium user notification
    final String fileName = notification.fileName ?? 'Your report';
    final String message = notification.message ?? 'The file "$fileName" is ready for download!';
    AppUtils.showSnackBar(message);
  } catch (e) {
    debugPrint('[DownloadController] Error processing SignalR notification: $e');
  }
}