diff --git a/lib/services/update_service.dart b/lib/services/update_service.dart index 2a63d818b..13a1cee1e 100644 --- a/lib/services/update_service.dart +++ b/lib/services/update_service.dart @@ -73,30 +73,39 @@ class UpdateService { return _latestVersion; } - Future showUpdateNotification() async { - if (!isIndependent()) { - return; - } + Future shouldShowUpdateNoification() async { final shouldUpdate = await this.shouldUpdate(); + final lastNotificationShownTime = _prefs.getInt(kUpdateAvailableShownTimeKey) ?? 0; final now = DateTime.now().microsecondsSinceEpoch; - final hasBeen3DaysSinceLastNotification = - (now - lastNotificationShownTime) > (3 * microSecondsInDay); - if (shouldUpdate && - hasBeen3DaysSinceLastNotification && - _latestVersion!.shouldNotify) { + final hasBeenThresholdDaysSinceLastNotification = + (now - lastNotificationShownTime) > + ((_latestVersion!.shouldNotify ? 1 : 3) * microSecondsInDay); + + return shouldUpdate && hasBeenThresholdDaysSinceLastNotification; + } + + Future showUpdateNotification() async { + if (await shouldShowUpdateNoification()) { // ignore: unawaited_futures NotificationService.instance.showNotification( "Update available", "Click to install our best version yet", ); - await _prefs.setInt(kUpdateAvailableShownTimeKey, now); + await resetUpdateAvailableShownTime(); } else { _logger.info("Debouncing notification"); } } + Future resetUpdateAvailableShownTime() { + return _prefs.setInt( + kUpdateAvailableShownTimeKey, + DateTime.now().microsecondsSinceEpoch, + ); + } + Future _getLatestVersionInfo() async { final response = await NetworkClient.instance .getDio() diff --git a/lib/ui/settings/app_update_dialog.dart b/lib/ui/settings/app_update_dialog.dart index 00bf1c948..124b87927 100644 --- a/lib/ui/settings/app_update_dialog.dart +++ b/lib/ui/settings/app_update_dialog.dart @@ -1,12 +1,13 @@ import 'package:flutter/material.dart'; import 'package:logging/logging.dart'; -// import 'package:open_file/open_file.dart'; import 'package:photos/core/configuration.dart'; import 'package:photos/core/network/network.dart'; import 'package:photos/ente_theme_data.dart'; import "package:photos/generated/l10n.dart"; import 'package:photos/services/update_service.dart'; import 'package:photos/theme/ente_theme.dart'; +import "package:photos/ui/components/buttons/button_widget.dart"; +import "package:photos/ui/components/models/button_type.dart"; import 'package:url_launcher/url_launcher_string.dart'; class AppUpdateDialog extends StatefulWidget { @@ -63,32 +64,28 @@ class _AppUpdateDialogState extends State { children: changelog, ), const Padding(padding: EdgeInsets.all(8)), - SizedBox( - width: double.infinity, - height: 56, - child: OutlinedButton( - style: Theme.of(context).outlinedButtonTheme.style!.copyWith( - textStyle: MaterialStateProperty.resolveWith( - (Set states) { - return enteTextTheme.bodyBold; - }, - ), - ), - onPressed: () async { - Navigator.pop(context); - // ignore: unawaited_futures - showDialog( - context: context, - builder: (BuildContext context) { - return ApkDownloaderDialog(widget.latestVersionInfo); - }, - barrierDismissible: false, - ); - }, - child: Text( - S.of(context).update, - ), - ), + ButtonWidget( + buttonType: ButtonType.primary, + labelText: S.of(context).update, + onTap: () async { + Navigator.pop(context); + // ignore: unawaited_futures + showDialog( + context: context, + builder: (BuildContext context) { + return ApkDownloaderDialog(widget.latestVersionInfo); + }, + barrierDismissible: false, + ); + }, + ), + const SizedBox(height: 6), + ButtonWidget( + buttonType: ButtonType.secondary, + labelText: S.of(context).cancel, + onTap: () async { + Navigator.of(context).pop(); + }, ), const Padding(padding: EdgeInsets.all(8)), Center( diff --git a/lib/ui/tabs/home_widget.dart b/lib/ui/tabs/home_widget.dart index ca66011da..6ce7d46d1 100644 --- a/lib/ui/tabs/home_widget.dart +++ b/lib/ui/tabs/home_widget.dart @@ -194,9 +194,9 @@ class _HomeWidgetState extends State { }, ); _initDeepLinks(); - UpdateService.instance.shouldUpdate().then((shouldUpdate) { - if (shouldUpdate) { - Future.delayed(Duration.zero, () { + UpdateService.instance.shouldShowUpdateNoification().then((value) { + Future.delayed(Duration.zero, () { + if (value) { showDialog( context: context, builder: (BuildContext context) { @@ -206,9 +206,11 @@ class _HomeWidgetState extends State { }, barrierColor: Colors.black.withOpacity(0.85), ); - }); - } + UpdateService.instance.resetUpdateAvailableShownTime(); + } + }); }); + // For sharing images coming from outside the app _initMediaShareSubscription(); WidgetsBinding.instance.addPostFrameCallback(