notification overhaul

This commit is contained in:
2025-08-30 00:12:29 +02:00
parent 9ae2bb5654
commit 6dccac6124
25 changed files with 1313 additions and 3947 deletions

View File

@@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:flutter/foundation.dart';
import 'package:supplements/logging.dart';
import '../providers/settings_provider.dart';
import '../providers/simple_sync_provider.dart';
@@ -69,7 +70,7 @@ class AutoSyncService {
// Check if auto-sync is enabled
if (!_settingsProvider.autoSyncEnabled) {
if (kDebugMode) {
print('AutoSyncService: Auto-sync is disabled, skipping trigger');
printLog('AutoSyncService: Auto-sync is disabled, skipping trigger');
}
return;
}
@@ -77,7 +78,7 @@ class AutoSyncService {
// Check if auto-sync was disabled due to persistent errors
if (_autoDisabledDueToErrors) {
if (kDebugMode) {
print('AutoSyncService: Auto-sync disabled due to persistent errors, skipping trigger');
printLog('AutoSyncService: Auto-sync disabled due to persistent errors, skipping trigger');
}
return;
}
@@ -90,7 +91,7 @@ class AutoSyncService {
timestamp: DateTime.now(),
));
if (kDebugMode) {
print('AutoSyncService: Sync not configured, skipping auto-sync');
printLog('AutoSyncService: Sync not configured, skipping auto-sync');
}
return;
}
@@ -99,7 +100,7 @@ class AutoSyncService {
if (_syncInProgress || _syncProvider.isSyncing) {
_hasPendingSync = true;
if (kDebugMode) {
print('AutoSyncService: Sync in progress, marking pending sync');
printLog('AutoSyncService: Sync in progress, marking pending sync');
}
return;
}
@@ -111,7 +112,7 @@ class AutoSyncService {
final backoffDelay = _calculateBackoffDelay();
if (backoffDelay > 0) {
if (kDebugMode) {
print('AutoSyncService: Applying backoff delay of ${backoffDelay}s due to recent failures');
printLog('AutoSyncService: Applying backoff delay of ${backoffDelay}s due to recent failures');
}
_debounceTimer = Timer(Duration(seconds: backoffDelay), () {
_executePendingSync();
@@ -126,7 +127,7 @@ class AutoSyncService {
});
if (kDebugMode) {
print('AutoSyncService: Auto-sync scheduled in ${debounceSeconds}s');
printLog('AutoSyncService: Auto-sync scheduled in ${debounceSeconds}s');
}
}
@@ -135,14 +136,14 @@ class AutoSyncService {
// Double-check conditions before executing
if (!_settingsProvider.autoSyncEnabled) {
if (kDebugMode) {
print('AutoSyncService: Auto-sync disabled during execution, aborting');
printLog('AutoSyncService: Auto-sync disabled during execution, aborting');
}
return;
}
if (_autoDisabledDueToErrors) {
if (kDebugMode) {
print('AutoSyncService: Auto-sync disabled due to errors during execution, aborting');
printLog('AutoSyncService: Auto-sync disabled due to errors during execution, aborting');
}
return;
}
@@ -154,14 +155,14 @@ class AutoSyncService {
timestamp: DateTime.now(),
));
if (kDebugMode) {
print('AutoSyncService: Sync not configured during execution, aborting');
printLog('AutoSyncService: Sync not configured during execution, aborting');
}
return;
}
if (_syncInProgress || _syncProvider.isSyncing) {
if (kDebugMode) {
print('AutoSyncService: Sync already in progress during execution, aborting');
printLog('AutoSyncService: Sync already in progress during execution, aborting');
}
return;
}
@@ -171,7 +172,7 @@ class AutoSyncService {
try {
if (kDebugMode) {
print('AutoSyncService: Executing auto-sync (attempt ${_consecutiveFailures + 1})');
printLog('AutoSyncService: Executing auto-sync (attempt ${_consecutiveFailures + 1})');
}
// Check network connectivity before attempting sync
@@ -191,12 +192,12 @@ class AutoSyncService {
_autoDisabledDueToErrors = false;
if (kDebugMode) {
print('AutoSyncService: Auto-sync completed successfully');
printLog('AutoSyncService: Auto-sync completed successfully');
}
} catch (e) {
if (kDebugMode) {
print('AutoSyncService: Auto-sync failed: $e');
printLog('AutoSyncService: Auto-sync failed: $e');
}
// Handle specific error types
@@ -208,7 +209,7 @@ class AutoSyncService {
// If there was a pending sync request while we were syncing, trigger it
if (_hasPendingSync && !_autoDisabledDueToErrors) {
if (kDebugMode) {
print('AutoSyncService: Processing queued sync request');
printLog('AutoSyncService: Processing queued sync request');
}
_hasPendingSync = false;
// Use a small delay to avoid immediate re-triggering
@@ -231,14 +232,14 @@ class AutoSyncService {
if (_consecutiveFailures >= _autoDisableThreshold) {
_autoDisabledDueToErrors = true;
if (kDebugMode) {
print('AutoSyncService: Auto-sync disabled due to ${_consecutiveFailures} consecutive failures');
printLog('AutoSyncService: Auto-sync disabled due to ${_consecutiveFailures} consecutive failures');
}
// For configuration errors, disable immediately
if (autoSyncError.type == AutoSyncErrorType.configuration ||
autoSyncError.type == AutoSyncErrorType.authentication) {
if (kDebugMode) {
print('AutoSyncService: Auto-sync disabled due to configuration/authentication error');
printLog('AutoSyncService: Auto-sync disabled due to configuration/authentication error');
}
}
}
@@ -328,7 +329,7 @@ class AutoSyncService {
}
if (kDebugMode) {
print('AutoSyncService: Recorded error: $error');
printLog('AutoSyncService: Recorded error: $error');
}
}
@@ -375,13 +376,13 @@ class AutoSyncService {
_retryTimer?.cancel();
_retryTimer = Timer(Duration(seconds: retryDelay), () {
if (kDebugMode) {
print('AutoSyncService: Retrying auto-sync after backoff delay');
printLog('AutoSyncService: Retrying auto-sync after backoff delay');
}
triggerAutoSync();
});
if (kDebugMode) {
print('AutoSyncService: Scheduled retry in ${retryDelay}s');
printLog('AutoSyncService: Scheduled retry in ${retryDelay}s');
}
}
@@ -392,7 +393,7 @@ class AutoSyncService {
return result.isNotEmpty && result[0].rawAddress.isNotEmpty;
} catch (e) {
if (kDebugMode) {
print('AutoSyncService: Network check failed: $e');
printLog('AutoSyncService: Network check failed: $e');
}
return false;
}
@@ -406,7 +407,7 @@ class AutoSyncService {
_hasPendingSync = false;
if (kDebugMode) {
print('AutoSyncService: Cancelled pending sync and retry timer');
printLog('AutoSyncService: Cancelled pending sync and retry timer');
}
}
@@ -426,7 +427,7 @@ class AutoSyncService {
_retryTimer = null;
if (kDebugMode) {
print('AutoSyncService: Error state reset, auto-sync re-enabled');
printLog('AutoSyncService: Error state reset, auto-sync re-enabled');
}
}
@@ -440,7 +441,7 @@ class AutoSyncService {
_recentErrors.clear();
if (kDebugMode) {
print('AutoSyncService: Disposed');
printLog('AutoSyncService: Disposed');
}
}