diff --git a/lib/app/view/app.dart b/lib/app/view/app.dart index 97609f957..be5b9f8bf 100644 --- a/lib/app/view/app.dart +++ b/lib/app/view/app.dart @@ -10,7 +10,9 @@ import 'package:ente_auth/events/signed_in_event.dart'; import 'package:ente_auth/events/signed_out_event.dart'; import "package:ente_auth/l10n/l10n.dart"; import "package:ente_auth/onboarding/view/onboarding_page.dart"; +import 'package:ente_auth/services/update_service.dart'; import 'package:ente_auth/ui/home_page.dart'; +import 'package:ente_auth/ui/settings/app_update_dialog.dart'; import 'package:flutter/foundation.dart'; import "package:flutter/material.dart"; import "package:flutter_localizations/flutter_localizations.dart"; @@ -38,6 +40,21 @@ class _AppState extends State { setState(() {}); } }); + UpdateService.instance.shouldUpdate().then((shouldUpdate) { + if (shouldUpdate) { + Future.delayed(Duration.zero, () { + showDialog( + context: context, + builder: (BuildContext context) { + return AppUpdateDialog( + UpdateService.instance.getLatestVersionInfo(), + ); + }, + barrierColor: Colors.black.withOpacity(0.85), + ); + }); + } + }); super.initState(); } diff --git a/lib/main.dart b/lib/main.dart index f55c97e72..808526e8b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,6 +7,7 @@ import 'package:ente_auth/core/network.dart'; import 'package:ente_auth/ente_theme_data.dart'; import 'package:ente_auth/services/authenticator_service.dart'; import 'package:ente_auth/services/billing_service.dart'; +import 'package:ente_auth/services/notification_service.dart'; import 'package:ente_auth/services/update_service.dart'; import 'package:ente_auth/services/user_remote_flag_service.dart'; import 'package:ente_auth/services/user_service.dart'; @@ -30,6 +31,7 @@ Future _runInForeground() async { return await _runWithLogs(() async { _logger.info("Starting app in foreground"); await _init(false, via: 'mainMethod'); + UpdateService.instance.showUpdateNotification(); runApp( AppLock( builder: (args) => const App(), @@ -64,7 +66,8 @@ Future _init(bool bool, {String via}) async { await Network.instance.init(); await UserService.instance.init(); await UserRemoteFlagService.instance.init(); - await UpdateService.instance.init(); await AuthenticatorService.instance.init(); await BillingService.instance.init(); + await NotificationService.instance.init(); + await UpdateService.instance.init(); } diff --git a/lib/services/update_service.dart b/lib/services/update_service.dart index 484efa871..94f8ae3d7 100644 --- a/lib/services/update_service.dart +++ b/lib/services/update_service.dart @@ -2,7 +2,9 @@ import 'dart:io'; +import 'package:ente_auth/core/constants.dart'; import 'package:ente_auth/core/network.dart'; +import 'package:ente_auth/services/notification_service.dart'; import 'package:flutter/foundation.dart'; import 'package:logging/logging.dart'; import 'package:package_info_plus/package_info_plus.dart'; @@ -55,33 +57,33 @@ class UpdateService { return _latestVersion; } - // Future showUpdateNotification() async { - // if (!isIndependent()) { - // return; - // } - // 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) { - // NotificationService.instance.showNotification( - // "update available", - // "click to install our best version yet", - // ); - // await _prefs.setInt(kUpdateAvailableShownTimeKey, now); - // } else { - // _logger.info("Debouncing notification"); - // } - // } + Future showUpdateNotification() async { + if (!isIndependent()) { + return; + } + 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) { + NotificationService.instance.showNotification( + "Update available", + "Click to install our best version yet", + ); + await _prefs.setInt(kUpdateAvailableShownTimeKey, now); + } else { + _logger.info("Debouncing notification"); + } + } Future _getLatestVersionInfo() async { final response = await Network.instance .getDio() - .get("https://ente.io/release-info/independent.json"); + .get("https://ente.io/release-info/auth-independent.json"); return LatestVersionInfo.fromMap(response.data["latestVersion"]); } @@ -89,18 +91,7 @@ class UpdateService { if (Platform.isIOS) { return false; } - if (!kDebugMode && - _packageInfo.packageName != "io.ente.auth.independent") { - return false; - } - return true; - } - - bool isIndependentFlavor() { - if (Platform.isIOS) { - return false; - } - return _packageInfo.packageName.startsWith("io.ente.auth.independent"); + return kDebugMode || _packageInfo.packageName.endsWith("independent"); } } diff --git a/lib/ui/settings/app_update_dialog.dart b/lib/ui/settings/app_update_dialog.dart index 9c3d69622..25c3c7ba0 100644 --- a/lib/ui/settings/app_update_dialog.dart +++ b/lib/ui/settings/app_update_dialog.dart @@ -1,12 +1,12 @@ // @dart=2.9 -// import 'package:open_file/open_file.dart'; import 'package:ente_auth/core/configuration.dart'; import 'package:ente_auth/core/network.dart'; import 'package:ente_auth/ente_theme_data.dart'; import 'package:ente_auth/services/update_service.dart'; import 'package:flutter/material.dart'; import 'package:logging/logging.dart'; +import 'package:open_file/open_file.dart'; class AppUpdateDialog extends StatefulWidget { final LatestVersionInfo latestVersionInfo; @@ -25,7 +25,12 @@ class _AppUpdateDialogState extends State { changelog.add( Padding( padding: const EdgeInsets.fromLTRB(8, 4, 0, 4), - child: Text("- " + log, style: Theme.of(context).textTheme.caption), + child: Text( + "- " + log, + style: Theme.of(context).textTheme.caption.copyWith( + fontSize: 14, + ), + ), ), ); } @@ -152,7 +157,7 @@ class _ApkDownloaderDialogState extends State { }, ); Navigator.of(context, rootNavigator: true).pop('dialog'); - // OpenFile.open(_saveUrl); + OpenFile.open(_saveUrl); } catch (e) { Logger("ApkDownloader").severe(e); final AlertDialog alert = AlertDialog(