High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
fix: poll counts from DB rather than using callbacks from library (#22117)
shenlong29fd981587c8
diff --git a/mobile/lib/pages/backup/drift_backup.page.dart b/mobile/lib/pages/backup/drift_backup.page.dartindex bf9ad43f9c..dc452d49d3 100644--- a/mobile/lib/pages/backup/drift_backup.page.dart+++ b/mobile/lib/pages/backup/drift_backup.page.dart@@ -1,3 +1,5 @@+import 'dart:async';+import 'package:auto_route/auto_route.dart';import 'package:easy_localization/easy_localization.dart';import 'package:flutter/material.dart';@@ -9,11 +11,13 @@ import 'package:immich_mobile/extensions/build_context_extensions.dart';import 'package:immich_mobile/extensions/theme_extensions.dart';import 'package:immich_mobile/extensions/translate_extensions.dart';import 'package:immich_mobile/presentation/widgets/backup/backup_toggle_button.widget.dart';+import 'package:immich_mobile/providers/app_settings.provider.dart';import 'package:immich_mobile/providers/background_sync.provider.dart';import 'package:immich_mobile/providers/backup/backup_album.provider.dart';import 'package:immich_mobile/providers/backup/drift_backup.provider.dart';import 'package:immich_mobile/providers/user.provider.dart';import 'package:immich_mobile/routing/router.dart';+import 'package:immich_mobile/services/app_settings.service.dart';import 'package:immich_mobile/widgets/backup/backup_info_card.dart';@RoutePage()@@ -25,6 +29,8 @@ class DriftBackupPage extends ConsumerStatefulWidget {}class _DriftBackupPageState extends ConsumerState<DriftBackupPage> {+ Timer? _countPoller;+@overridevoid initState() {super.initState();@@ -33,9 +39,42 @@ class _DriftBackupPageState extends ConsumerState<DriftBackupPage> {return;}+ if (ref.read(appSettingsServiceProvider).getSetting(AppSettingsEnum.enableBackup)) {+ _startCountPolling();+ }+ref.read(driftBackupProvider.notifier).getBackupStatus(currentUser.id);}+ void _startCountPolling() {+ _countPoller?.cancel();+ _countPoller = Timer.periodic(const Duration(seconds: 5), (timer) async {+ if (!mounted) {+ timer.cancel();+ return;+ }++ final currentUser = ref.read(currentUserProvider);+ if (currentUser == null) {+ timer.cancel();+ return;+ }++ await ref.read(driftBackupProvider.notifier).getBackupStatus(currentUser.id);+ });+ }++ void _stopCountPolling() {+ _countPoller?.cancel();+ _countPoller = null;+ }++ @override+ void dispose() {+ _stopCountPolling();+ super.dispose();+ }+@overrideWidget build(BuildContext context) {final selectedAlbum = ref@@ -55,10 +94,12 @@ class _DriftBackupPageState extends ConsumerState<DriftBackupPage> {await backgroundManager.syncRemote();await backupNotifier.getBackupStatus(currentUser.id);await backupNotifier.startBackup(currentUser.id);+ _startCountPolling();}Future<void> stopBackup() async {await backupNotifier.cancel();+ _stopCountPolling();}return Scaffold(diff --git a/mobile/lib/providers/backup/drift_backup.provider.dart b/mobile/lib/providers/backup/drift_backup.provider.dartindex 40ec7b1077..1de7f75135 100644--- a/mobile/lib/providers/backup/drift_backup.provider.dart+++ b/mobile/lib/providers/backup/drift_backup.provider.dart@@ -12,8 +12,8 @@ import 'package:immich_mobile/infrastructure/repositories/backup.repository.dartimport 'package:immich_mobile/providers/infrastructure/asset.provider.dart';import 'package:immich_mobile/providers/user.provider.dart';import 'package:immich_mobile/services/upload.service.dart';-import 'package:logging/logging.dart';import 'package:immich_mobile/utils/debug_print.dart';+import 'package:logging/logging.dart';class EnqueueStatus {final int enqueueCount;@@ -234,10 +234,6 @@ class DriftBackupNotifier extends StateNotifier<DriftBackupState> {switch (update.status) {case TaskStatus.complete:- if (update.task.group == kBackupGroup) {- state = state.copyWith(backupCount: state.backupCount + 1, remainderCount: state.remainderCount - 1);- }-// Remove the completed task from the upload itemsif (state.uploadItems.containsKey(taskId)) {Future.delayed(const Duration(milliseconds: 1000), () {