From 63c3a2b37422d39da9a220749479df604956328a Mon Sep 17 00:00:00 2001 From: Frank Merkel <138444693+frankmer@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:11:43 +0100 Subject: [PATCH] fixes polling with zero tokens --- lib/utils/push_provider.dart | 36 ++++++++++--------- lib/utils/riverpod_providers.dart | 2 +- .../main_view_tokens_list.dart | 2 +- .../widgets/push_tokens_view_list.dart | 2 +- pubspec.yaml | 2 +- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/utils/push_provider.dart b/lib/utils/push_provider.dart index c582d0509..cdac45a13 100644 --- a/lib/utils/push_provider.dart +++ b/lib/utils/push_provider.dart @@ -222,8 +222,8 @@ class PushProvider { // Start polling if enabled and not already polling if (pollingEnabled && _pollTimer == null) { Logger.info('Polling is enabled.', name: 'push_provider.dart#_startPollingIfEnabled'); - _pollTimer = Timer.periodic(const Duration(seconds: 3), (_) => pollForChallenges()); - pollForChallenges(); + _pollTimer = Timer.periodic(const Duration(seconds: 3), (_) => pollForChallenges(isManually: false)); + pollForChallenges(isManually: false); return; } // Stop polling if it's disabled and currently polling @@ -237,24 +237,28 @@ class PushProvider { return; } - Future pollForChallenges() async { - final connectivityResult = await (Connectivity().checkConnectivity()); - if (connectivityResult == ConnectivityResult.none) { - Logger.info('Tried to poll without any internet connection available.', name: 'push_provider.dart#pollForChallenges'); - globalRef?.read(statusMessageProvider.notifier).state = ( - AppLocalizations.of(globalNavigatorKey.currentContext!)!.pollingFailed, - AppLocalizations.of(globalNavigatorKey.currentContext!)!.noNetworkConnection, - ); - return; - } - + Future pollForChallenges({required bool isManually}) async { // Get all push tokens List pushTokens = globalRef?.read(tokenProvider).tokens.whereType().where((t) => t.isRolledOut && t.url != null).toList() ?? []; // Disable polling if no push tokens exist - if (pushTokens.isEmpty && globalRef?.read(settingsProvider).enablePolling == true) { - Logger.info('No push token is available for polling, polling is disabled.', name: 'push_provider.dart#pollForChallenges'); - globalRef?.read(settingsProvider.notifier).setPolling(false); + if (pushTokens.isEmpty) { + if (globalRef?.read(settingsProvider).enablePolling == true) { + Logger.info('No push token is available for polling, polling is disabled.', name: 'push_provider.dart#pollForChallenges'); + globalRef?.read(settingsProvider.notifier).setPolling(false); + } + return; + } + + final connectivityResult = await (Connectivity().checkConnectivity()); + if (connectivityResult == ConnectivityResult.none) { + if (isManually) { + Logger.info('Tried to poll without any internet connection available.', name: 'push_provider.dart#pollForChallenges'); + globalRef?.read(statusMessageProvider.notifier).state = ( + AppLocalizations.of(globalNavigatorKey.currentContext!)!.pollingFailed, + AppLocalizations.of(globalNavigatorKey.currentContext!)!.noNetworkConnection, + ); + } return; } diff --git a/lib/utils/riverpod_providers.dart b/lib/utils/riverpod_providers.dart index 49a258a6b..3e82139ad 100644 --- a/lib/utils/riverpod_providers.dart +++ b/lib/utils/riverpod_providers.dart @@ -92,7 +92,7 @@ final pushRequestProvider = StateNotifierProvider { message: AppLocalizations.of(context)!.pollingChallenges, duration: const Duration(seconds: 1), ); - await PushProvider().pollForChallenges(); + await PushProvider().pollForChallenges(isManually: true); }, child: SlidableAutoCloseBehavior( child: DragItemScroller( diff --git a/lib/views/push_token_view/widgets/push_tokens_view_list.dart b/lib/views/push_token_view/widgets/push_tokens_view_list.dart index 1c5b7288d..5e5380822 100644 --- a/lib/views/push_token_view/widgets/push_tokens_view_list.dart +++ b/lib/views/push_token_view/widgets/push_tokens_view_list.dart @@ -45,7 +45,7 @@ class _PushTokensViwListState extends ConsumerState { message: AppLocalizations.of(context)!.pollingChallenges, duration: const Duration(seconds: 1), ); - await PushProvider().pollForChallenges(); + await PushProvider().pollForChallenges(isManually: true); }, child: SlidableAutoCloseBehavior( child: DragItemScroller( diff --git a/pubspec.yaml b/pubspec.yaml index fbaeda193..3b38d3b9e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ publish_to: none # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 4.2.1+402103 # TODO Set the right version number +version: 4.2.1+402104 # TODO Set the right version number # version: major.minor.build + 2x major|2x minor|3x build # version: version number + build number (optional) # android: build-name + versionCode