Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Share app update sheet

Neeraj Guptac0b4697eb02f
diff --git a/mobile/apps/auth/lib/app/view/app.dart b/mobile/apps/auth/lib/app/view/app.dart
index eea9135787..a5ada23cee 100644
--- a/mobile/apps/auth/lib/app/view/app.dart
+++ b/mobile/apps/auth/lib/app/view/app.dart
@@ -9,7 +9,7 @@ import 'package:ente_auth/services/auth_theme_preferences.dart';
import 'package:ente_auth/services/authenticator_service.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:ente_auth/ui/settings/app_update_sheet.dart';
import 'package:ente_events/event_bus.dart';
import 'package:ente_events/models/signed_in_event.dart';
import 'package:ente_events/models/signed_out_event.dart';
@@ -85,18 +85,15 @@ class _AppState extends State<App> with WidgetsBindingObserver {
}
});
locale = widget.locale;
- UpdateService.instance.showUpdateNotification().then((shouldUpdate) {
+ UpdateService.instance.shouldShowUpdatePrompt().then((shouldUpdate) {
if (shouldUpdate) {
Future.delayed(Duration.zero, () {
if (!mounted) return;
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return AppUpdateDialog(
- UpdateService.instance.getLatestVersionInfo(),
- );
- },
- barrierColor: Colors.black.withValues(alpha: 0.85),
+ unawaited(
+ showAppUpdateSheet(
+ context,
+ latestVersionInfo: UpdateService.instance.getLatestVersionInfo()!,
+ ),
);
});
}
diff --git a/mobile/apps/auth/lib/services/update_service.dart b/mobile/apps/auth/lib/services/update_service.dart
index 13ad3ac41d..150aeb091c 100644
--- a/mobile/apps/auth/lib/services/update_service.dart
+++ b/mobile/apps/auth/lib/services/update_service.dart
@@ -15,6 +15,7 @@ class UpdateService {
static final UpdateService instance = UpdateService._privateConstructor();
static const kUpdateAvailableShownTimeKey = "update_available_shown_time_key";
+ static const _updateNotificationsEnabledKey = "update_notifications_enabled";
LatestVersionInfo? _latestVersion;
final _logger = Logger("UpdateService");
@@ -58,33 +59,53 @@ class UpdateService {
return _latestVersion;
}
- Future<bool> showUpdateNotification() async {
- if (!supportsInAppUpdates()) {
+ bool get updateNotificationsEnabled =>
+ _prefs.getBool(_updateNotificationsEnabledKey) ?? true;
+
+ Future<void> setUpdateNotificationsEnabled(bool enabled) async {
+ await _prefs.setBool(_updateNotificationsEnabledKey, enabled);
+ }
+
+ Future<bool> shouldShowUpdatePrompt() async {
+ if (!await shouldUpdate()) {
+ return false;
+ }
+ final isCritical = shouldForceUpdate(_latestVersion);
+ return isCritical || _shouldShowNotification(isCritical: false);
+ }
+
+ Future<void> showUpdateNotification() async {
+ if (!await shouldUpdate()) {
+ return;
+ }
+ final isCritical = shouldForceUpdate(_latestVersion);
+ if (!_shouldShowNotification(isCritical: isCritical)) {
+ _logger.info("Debouncing notification");
+ return;
+ }
+ final now = DateTime.now().microsecondsSinceEpoch;
+ await _prefs.setInt(kUpdateAvailableShownTimeKey, now);
+ if (Platform.isAndroid) {
+ unawaited(
+ NotificationService.instance.showNotification(
+ "Update available",
+ "Click to install our best version yet",
+ ),
+ );
+ }
+ }
+
+ bool _shouldShowNotification({required bool isCritical}) {
+ if (!isCritical && !updateNotificationsEnabled) {
return false;
}
- 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!) {
- await _prefs.setInt(kUpdateAvailableShownTimeKey, now);
- if (Platform.isAndroid) {
- unawaited(
- NotificationService.instance.showNotification(
- "Update available",
- "Click to install our best version yet",
- ),
- );
- }
- return true;
- } else {
- _logger.info("Debouncing notification");
- return false;
- }
+ return hasBeen3DaysSinceLastNotification &&
+ (isCritical || _latestVersion!.shouldNotify!);
}
Future<LatestVersionInfo> _getLatestVersionInfo() async {
diff --git a/mobile/apps/auth/lib/ui/settings/about_settings_page.dart b/mobile/apps/auth/lib/ui/settings/about_settings_page.dart
index 81482d0f97..837f217622 100644
--- a/mobile/apps/auth/lib/ui/settings/about_settings_page.dart
+++ b/mobile/apps/auth/lib/ui/settings/about_settings_page.dart
@@ -1,5 +1,5 @@
import 'package:ente_auth/services/update_service.dart';
-import 'package:ente_auth/ui/settings/app_update_dialog.dart';
+import 'package:ente_auth/ui/settings/app_update_sheet.dart';
import 'package:ente_auth/ui/settings/components/auth_settings_page_scaffold.dart';
import 'package:ente_auth/utils/toast_util.dart';
import 'package:ente_strings/ente_strings.dart';
@@ -36,10 +36,6 @@ class AboutSettingsPage extends StatelessWidget {
showShortToast(context, context.strings.youAreOnTheLatestVersion);
return;
}
- await showDialog<void>(
- context: context,
- builder: (_) => AppUpdateDialog(latestVersion),
- barrierColor: Colors.black.withValues(alpha: 0.85),
- );
+ await showAppUpdateSheet(context, latestVersionInfo: latestVersion);
}
}
diff --git a/mobile/apps/auth/lib/ui/settings/app_update_dialog.dart b/mobile/apps/auth/lib/ui/settings/app_update_dialog.dart
deleted file mode 100644
index a3bb810ce4..0000000000
--- a/mobile/apps/auth/lib/ui/settings/app_update_dialog.dart
+++ /dev/null
@@ -1,101 +0,0 @@
-import 'package:ente_auth/services/update_service.dart';
-import 'package:ente_auth/theme/ente_theme.dart';
-import 'package:ente_pure_utils/ente_pure_utils.dart';
-import 'package:ente_strings/ente_strings.dart';
-import 'package:flutter/material.dart';
-import 'package:url_launcher/url_launcher_string.dart';
-
-class AppUpdateDialog extends StatefulWidget {
- final LatestVersionInfo? latestVersionInfo;
-
- const AppUpdateDialog(this.latestVersionInfo, {super.key});
-
- @override
- State<AppUpdateDialog> createState() => _AppUpdateDialogState();
-}
-
-class _AppUpdateDialogState extends State<AppUpdateDialog> {
- @override
- Widget build(BuildContext context) {
- final enteTextTheme = getEnteTextTheme(context);
- final List<Widget> changelog = [];
- for (final log in widget.latestVersionInfo!.changelog) {
- changelog.add(
- Padding(
- padding: const EdgeInsets.fromLTRB(8, 4, 0, 4),
- child: Text(
- "- $log",
- style: Theme.of(
- context,
- ).textTheme.bodySmall!.copyWith(fontSize: 14),
- ),
- ),
- );
- }
- final content = Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- widget.latestVersionInfo!.name!,
- style: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
- ),
- const Padding(padding: EdgeInsets.all(8)),
- if (changelog.isNotEmpty)
- const Text("Changelog", style: TextStyle(fontSize: 18)),
- if (changelog.isNotEmpty) const Padding(padding: EdgeInsets.all(4)),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: changelog,
- ),
- const Padding(padding: EdgeInsets.all(8)),
- SizedBox(
- width: double.infinity,
- height: 64,
- child: OutlinedButton(
- style: Theme.of(context).outlinedButtonTheme.style!.copyWith(
- textStyle: WidgetStateProperty.resolveWith<TextStyle?>((
- Set<WidgetState> states,
- ) {
- return Theme.of(context).textTheme.titleMedium;
- }),
- ),
- onPressed: () => launchUrlString(
- PlatformDetector.isDesktop()
- ? widget.latestVersionInfo!.release!
- : widget.latestVersionInfo!.url!,
- mode: LaunchMode.externalApplication,
- ),
- child: Text(context.strings.downloadUpdate),
- ),
- ),
- ],
- );
- final shouldForceUpdate = UpdateService.instance.shouldForceUpdate(
- widget.latestVersionInfo,
- );
- return PopScope(
- canPop: !shouldForceUpdate,
- child: AlertDialog(
- title: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Icon(
- Icons.auto_awesome_outlined,
- size: 24,
- color: getEnteColorScheme(context).strokeMuted,
- ),
- const SizedBox(height: 16),
- Text(
- shouldForceUpdate
- ? context.strings.criticalUpdateAvailable
- : context.strings.updateAvailable,
- style: enteTextTheme.h3Bold,
- ),
- ],
- ),
- content: content,
- ),
- );
- }
-}
diff --git a/mobile/apps/auth/lib/ui/settings/app_update_sheet.dart b/mobile/apps/auth/lib/ui/settings/app_update_sheet.dart
new file mode 100644
index 0000000000..50c980950c
--- /dev/null
+++ b/mobile/apps/auth/lib/ui/settings/app_update_sheet.dart
@@ -0,0 +1,25 @@
+import "package:ente_auth/services/update_service.dart";
+import "package:ente_pure_utils/ente_pure_utils.dart";
+import "package:ente_ui/components/app_update_sheet.dart" as shared;
+import "package:flutter/material.dart";
+
+const _changelogUrl = "https://ente.com/help/auth/changelog";
+
+Future<void> showAppUpdateSheet(
+ BuildContext context, {
+ required LatestVersionInfo latestVersionInfo,
+}) {
+ final updateService = UpdateService.instance;
+ return shared.showAppUpdateSheet(
+ context,
+ version: latestVersionInfo.name!,
+ downloadUrl: PlatformDetector.isDesktop()
+ ? latestVersionInfo.release!
+ : latestVersionInfo.url!,
+ changelogUrl: _changelogUrl,
+ isCritical: updateService.shouldForceUpdate(latestVersionInfo),
+ notificationsEnabled: updateService.updateNotificationsEnabled,
+ onNotificationsChanged: updateService.setUpdateNotificationsEnabled,
+ useRootNavigator: true,
+ );
+}
diff --git a/mobile/apps/locker/lib/app.dart b/mobile/apps/locker/lib/app.dart
index 8acb8b1033..9276d7a095 100644
--- a/mobile/apps/locker/lib/app.dart
+++ b/mobile/apps/locker/lib/app.dart
@@ -16,7 +16,7 @@ import 'package:locker/services/contacts_display_service.dart';
import "package:locker/services/update_service.dart";
import 'package:locker/ui/pages/home_page.dart';
import 'package:locker/ui/pages/onboarding_page.dart';
-import "package:locker/ui/settings/widgets/app_update_dialog.dart";
+import "package:locker/ui/settings/app_update_sheet.dart";
import "package:locker/ui/settings/widgets/change_log_sheet.dart";
class App extends StatefulWidget {
@@ -95,7 +95,7 @@ class _AppState extends State<App> with WidgetsBindingObserver {
return false;
}
- await showAppUpdateBottomSheet(context, latestVersionInfo: latestVersion);
+ await showAppUpdateSheet(context, latestVersionInfo: latestVersion);
await UpdateService.instance.markUpdateNotificationShown();
return true;
}
diff --git a/mobile/apps/locker/lib/services/update_service.dart b/mobile/apps/locker/lib/services/update_service.dart
index 8ed5a20afd..642978411f 100644
--- a/mobile/apps/locker/lib/services/update_service.dart
+++ b/mobile/apps/locker/lib/services/update_service.dart
@@ -13,6 +13,8 @@ class UpdateService {
static final UpdateService instance = UpdateService._privateConstructor();
static const String kUpdateAvailableShownTimeKey =
"update_available_shown_time_key";
+ static const String _updateNotificationsEnabledKey =
+ "update_notifications_enabled";
static const String kChangeLogShownVersionKey = "update_change_log_key";
static const int currentChangeLogVersion = 1;
static const String _lockerIndependentPackageName =
@@ -68,6 +70,13 @@ class UpdateService {
return _latestVersion;
}
+ bool get updateNotificationsEnabled =>
+ _prefs!.getBool(_updateNotificationsEnabledKey) ?? true;
+
+ Future<void> setUpdateNotificationsEnabled(bool enabled) async {
+ await _prefs!.setBool(_updateNotificationsEnabledKey, enabled);
+ }
+
Future<bool> shouldShowUpdateNotification() async {
if (!_isInitialized || !isIndependent()) {
return false;
@@ -77,6 +86,12 @@ class UpdateService {
if (!shouldUpdate || _latestVersion == null) {
return false;
}
+ if (shouldForceUpdate(_latestVersion)) {
+ return true;
+ }
+ if (!updateNotificationsEnabled) {
+ return false;
+ }
final lastNotificationShownTime =
_prefs!.getInt(kUpdateAvailableShownTimeKey) ?? 0;
diff --git a/mobile/apps/locker/lib/ui/settings/app_update_sheet.dart b/mobile/apps/locker/lib/ui/settings/app_update_sheet.dart
new file mode 100644
index 0000000000..399e69c533
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/settings/app_update_sheet.dart
@@ -0,0 +1,21 @@
+import "package:ente_ui/components/app_update_sheet.dart" as shared;
+import "package:flutter/material.dart";
+import "package:locker/services/update_service.dart";
+
+const _changelogUrl = "https://ente.com/help/locker/changelog";
+
+Future<void> showAppUpdateSheet(
+ BuildContext context, {
+ required LatestVersionInfo latestVersionInfo,
+}) {
+ final updateService = UpdateService.instance;
+ return shared.showAppUpdateSheet(
+ context,
+ version: latestVersionInfo.name,
+ downloadUrl: latestVersionInfo.url,
+ changelogUrl: _changelogUrl,
+ isCritical: updateService.shouldForceUpdate(latestVersionInfo),
+ notificationsEnabled: updateService.updateNotificationsEnabled,
+ onNotificationsChanged: updateService.setUpdateNotificationsEnabled,
+ );
+}
diff --git a/mobile/apps/locker/lib/ui/settings/pages/about_page.dart b/mobile/apps/locker/lib/ui/settings/pages/about_page.dart
index 1d4664dacb..ef0c8365fd 100644
--- a/mobile/apps/locker/lib/ui/settings/pages/about_page.dart
+++ b/mobile/apps/locker/lib/ui/settings/pages/about_page.dart
@@ -4,7 +4,7 @@ import "package:ente_ui/components/settings/about_settings_section.dart";
import "package:ente_ui/utils/toast_util.dart";
import "package:flutter/material.dart";
import "package:locker/services/update_service.dart";
-import "package:locker/ui/settings/widgets/app_update_dialog.dart";
+import "package:locker/ui/settings/app_update_sheet.dart";
class AboutPage extends StatelessWidget {
const AboutPage({super.key});
@@ -40,6 +40,6 @@ class AboutPage extends StatelessWidget {
showShortToast(context, l10n.youAreOnTheLatestVersion);
return;
}
- await showAppUpdateBottomSheet(context, latestVersionInfo: latestVersion);
+ await showAppUpdateSheet(context, latestVersionInfo: latestVersion);
}
}
diff --git a/mobile/apps/locker/lib/ui/settings/widgets/app_update_dialog.dart b/mobile/apps/locker/lib/ui/settings/widgets/app_update_dialog.dart
deleted file mode 100644
index 611058103f..0000000000
--- a/mobile/apps/locker/lib/ui/settings/widgets/app_update_dialog.dart
+++ /dev/null
@@ -1,51 +0,0 @@
-import "dart:async";
-
-import "package:ente_components/ente_components.dart";
-import "package:ente_strings/ente_strings.dart";
-import "package:flutter/material.dart";
-import "package:locker/services/update_service.dart";
-import "package:locker/utils/bottom_sheet_illustration.dart";
-import "package:url_launcher/url_launcher_string.dart";
-
-Future<void> showAppUpdateBottomSheet(
- BuildContext context, {
- required LatestVersionInfo latestVersionInfo,
-}) async {
- final navigator = Navigator.of(context);
- final l10n = context.strings;
- final shouldForceUpdate = UpdateService.instance.shouldForceUpdate(
- latestVersionInfo,
- );
- final updateMessage = l10n.aNewVersionOfEnteLockerIsAvailable;
- final title = shouldForceUpdate
- ? l10n.criticalUpdateAvailable
- : l10n.updateAvailable;
-
- await showBottomSheetComponent<void>(
- context: context,
- isDismissible: !shouldForceUpdate,
- enableDrag: !shouldForceUpdate,
- builder: (_) => BottomSheetComponent(
- title: title,
- message: updateMessage,
- illustration: LockerBottomSheetIllustration.warningBlue,
- showCloseButton: !shouldForceUpdate,
- actions: [
- ButtonComponent(
- label: l10n.downloadApplicationUpdate,
- onTap: () {
- unawaited(
- launchUrlString(
- latestVersionInfo.url,
- mode: LaunchMode.externalApplication,
- ),
- );
- if (!shouldForceUpdate) {
- navigator.pop();
- }
- },
- ),
- ],
- ),
- );
-}
diff --git a/mobile/apps/photos/lib/services/update_service.dart b/mobile/apps/photos/lib/services/update_service.dart
index 10d772ab4a..3a464d1a8c 100644
--- a/mobile/apps/photos/lib/services/update_service.dart
+++ b/mobile/apps/photos/lib/services/update_service.dart
@@ -15,6 +15,7 @@ enum ChangeLogAction { skip, consumeWithoutShowing, show }
class UpdateService {
static const kUpdateAvailableShownTimeKey = "update_available_shown_time_key";
+ static const _updateNotificationsEnabledKey = "update_notifications_enabled";
static const changeLogVersionKey = "update_change_log_key";
static const currentChangeLogVersion = 58;
@@ -98,10 +99,23 @@ class UpdateService {
return _latestVersion;
}
+ bool get updateNotificationsEnabled =>
+ _prefs.getBool(_updateNotificationsEnabledKey) ?? true;
+
+ Future<void> setUpdateNotificationsEnabled(bool enabled) async {
+ await _prefs.setBool(_updateNotificationsEnabledKey, enabled);
+ }
+
Future<bool> shouldShowUpdateNotification() async {
final shouldUpdate = await this.shouldUpdate();
- if (!shouldUpdate) {
+ if (!shouldUpdate || _latestVersion == null) {
+ return false;
+ }
+ if (shouldForceUpdate(_latestVersion!)) {
+ return true;
+ }
+ if (!updateNotificationsEnabled) {
return false;
}
@@ -112,7 +126,7 @@ class UpdateService {
(now - lastNotificationShownTime) >
((_latestVersion!.shouldNotify ? 1 : 3) * microSecondsInDay);
- return shouldUpdate && hasBeenThresholdDaysSinceLastNotification;
+ return hasBeenThresholdDaysSinceLastNotification;
}
Future<void> showUpdateNotification() async {
diff --git a/mobile/apps/photos/lib/ui/settings/about/about_us_page.dart b/mobile/apps/photos/lib/ui/settings/about/about_us_page.dart
index 6109476b7f..2ecc9e84ee 100644
--- a/mobile/apps/photos/lib/ui/settings/about/about_us_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/about/about_us_page.dart
@@ -4,7 +4,7 @@ import "package:ente_ui/components/settings/about_settings_section.dart";
import "package:flutter/material.dart";
import "package:photos/service_locator.dart";
import "package:photos/ui/notification/toast.dart";
-import "package:photos/ui/settings/app_update_dialog.dart";
+import "package:photos/ui/settings/app_update_sheet.dart";
class AboutUsPage extends StatelessWidget {
const AboutUsPage({super.key});
@@ -37,11 +37,6 @@ class AboutUsPage extends StatelessWidget {
showShortToast(context, context.strings.youAreOnTheLatestVersion);
return;
}
- await showDialog(
- useRootNavigator: false,
- context: context,
- builder: (_) => AppUpdateDialog(latestVersion),
- barrierColor: Colors.black.withValues(alpha: 0.85),
- );
+ await showAppUpdateSheet(context, latestVersionInfo: latestVersion);
}
}
diff --git a/mobile/apps/photos/lib/ui/settings/app_update_dialog.dart b/mobile/apps/photos/lib/ui/settings/app_update_dialog.dart
deleted file mode 100644
index 046ff729f1..0000000000
--- a/mobile/apps/photos/lib/ui/settings/app_update_dialog.dart
+++ /dev/null
@@ -1,114 +0,0 @@
-import "package:ente_strings/ente_strings.dart";
-import 'package:flutter/material.dart';
-import "package:photos/service_locator.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 {
- final LatestVersionInfo? latestVersionInfo;
-
- const AppUpdateDialog(this.latestVersionInfo, {super.key});
-
- @override
- State<AppUpdateDialog> createState() => _AppUpdateDialogState();
-}
-
-class _AppUpdateDialogState extends State<AppUpdateDialog> {
- @override
- Widget build(BuildContext context) {
- final List<Widget> changelog = [];
- final enteTextTheme = getEnteTextTheme(context);
- final enteColor = getEnteColorScheme(context);
- for (final log in widget.latestVersionInfo!.changelog) {
- changelog.add(
- Padding(
- padding: const EdgeInsets.fromLTRB(0, 4, 0, 4),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- "- ",
- style: enteTextTheme.small.copyWith(color: enteColor.textMuted),
- ),
- Flexible(
- child: Text(
- log,
- softWrap: true,
- style: enteTextTheme.small.copyWith(
- color: enteColor.textMuted,
- ),
- ),
- ),
- ],
- ),
- ),
- );
- }
- final content = Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- context.strings.aNewVersionOfEnteIsAvailable,
- style: enteTextTheme.body.copyWith(color: enteColor.textMuted),
- ),
- const Padding(padding: EdgeInsets.all(8)),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: changelog,
- ),
- const Padding(padding: EdgeInsets.all(8)),
- ButtonWidget(
- buttonType: ButtonType.primary,
- labelText: context.strings.download,
- onTap: () async {
- // ignore: unawaited_futures
- launchUrlString(
- widget.latestVersionInfo!.url,
- mode: LaunchMode.externalApplication,
- );
- },
- ),
- const SizedBox(height: 6),
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: context.strings.cancel,
- onTap: () async {
- Navigator.of(context).pop();
- },
- ),
- ],
- );
- final shouldForceUpdate = updateService.shouldForceUpdate(
- widget.latestVersionInfo!,
- );
- return PopScope(
- canPop: !shouldForceUpdate,
- child: AlertDialog(
- key: const ValueKey("updateAppDialog"),
- title: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Icon(
- Icons.auto_awesome_outlined,
- size: 48,
- color: enteColor.strokeMuted,
- ),
- const SizedBox(height: 16),
- Text(
- shouldForceUpdate
- ? context.strings.criticalUpdateAvailable
- : context.strings.updateAvailable,
- style: enteTextTheme.h3Bold,
- ),
- ],
- ),
- content: content,
- ),
- );
- }
-}
diff --git a/mobile/apps/photos/lib/ui/settings/app_update_sheet.dart b/mobile/apps/photos/lib/ui/settings/app_update_sheet.dart
new file mode 100644
index 0000000000..28e70e9551
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/settings/app_update_sheet.dart
@@ -0,0 +1,21 @@
+import "package:ente_ui/components/app_update_sheet.dart" as shared;
+import "package:flutter/material.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/services/update_service.dart";
+
+const _changelogUrl = "https://ente.com/help/photos/changelog";
+
+Future<void> showAppUpdateSheet(
+ BuildContext context, {
+ required LatestVersionInfo latestVersionInfo,
+}) {
+ return shared.showAppUpdateSheet(
+ context,
+ version: latestVersionInfo.name,
+ downloadUrl: latestVersionInfo.url,
+ changelogUrl: _changelogUrl,
+ isCritical: updateService.shouldForceUpdate(latestVersionInfo),
+ notificationsEnabled: updateService.updateNotificationsEnabled,
+ onNotificationsChanged: updateService.setUpdateNotificationsEnabled,
+ );
+}
diff --git a/mobile/apps/photos/lib/ui/tabs/home_widget.dart b/mobile/apps/photos/lib/ui/tabs/home_widget.dart
index f5c3870a96..b217746dbe 100644
--- a/mobile/apps/photos/lib/ui/tabs/home_widget.dart
+++ b/mobile/apps/photos/lib/ui/tabs/home_widget.dart
@@ -75,7 +75,7 @@ import "package:photos/ui/notification/update/change_log_page.dart";
import "package:photos/ui/rituals/ritual_camera_page.dart";
import "package:photos/ui/rituals/ritual_page.dart";
import "package:photos/ui/rituals/ritual_privacy.dart";
-import "package:photos/ui/settings/app_update_dialog.dart";
+import "package:photos/ui/settings/app_update_sheet.dart";
import "package:photos/ui/settings_page.dart";
import "package:photos/ui/social/feed_screen.dart";
import "package:photos/ui/tabs/albums_tab.dart";
@@ -275,14 +275,10 @@ class _HomeWidgetState extends State<HomeWidget> {
Future.delayed(Duration.zero, () {
if (value) {
if (!mounted) return;
- showDialog(
- useRootNavigator: false,
- context: context,
- builder: (BuildContext context) {
- return AppUpdateDialog(updateService.getLatestVersionInfo());
- },
- barrierColor: Colors.black.withValues(alpha: 0.85),
- );
+ showAppUpdateSheet(
+ context,
+ latestVersionInfo: updateService.getLatestVersionInfo()!,
+ ).ignore();
updateService.resetUpdateAvailableShownTime();
}
});
diff --git a/mobile/packages/ui/lib/components/app_update_sheet.dart b/mobile/packages/ui/lib/components/app_update_sheet.dart
new file mode 100644
index 0000000000..2607f09d58
--- /dev/null
+++ b/mobile/packages/ui/lib/components/app_update_sheet.dart
@@ -0,0 +1,162 @@
+import "package:ente_components/ente_components.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
+import "package:url_launcher/url_launcher_string.dart";
+
+Future<void> showAppUpdateSheet(
+ BuildContext context, {
+ required String version,
+ required String downloadUrl,
+ required String changelogUrl,
+ required bool isCritical,
+ required bool notificationsEnabled,
+ required Future<void> Function(bool) onNotificationsChanged,
+ bool useRootNavigator = false,
+}) {
+ return showBottomSheetComponent<void>(
+ context: context,
+ isDismissible: !isCritical,
+ enableDrag: !isCritical,
+ useRootNavigator: useRootNavigator,
+ builder: (_) => _AppUpdateSheet(
+ version: version,
+ downloadUrl: downloadUrl,
+ changelogUrl: changelogUrl,
+ isCritical: isCritical,
+ notificationsEnabled: notificationsEnabled,
+ onNotificationsChanged: onNotificationsChanged,
+ ),
+ );
+}
+
+class _AppUpdateSheet extends StatefulWidget {
+ const _AppUpdateSheet({
+ required this.version,
+ required this.downloadUrl,
+ required this.changelogUrl,
+ required this.isCritical,
+ required this.notificationsEnabled,
+ required this.onNotificationsChanged,
+ });
+
+ final String version;
+ final String downloadUrl;
+ final String changelogUrl;
+ final bool isCritical;
+ final bool notificationsEnabled;
+ final Future<void> Function(bool) onNotificationsChanged;
+
+ @override
+ State<_AppUpdateSheet> createState() => _AppUpdateSheetState();
+}
+
+class _AppUpdateSheetState extends State<_AppUpdateSheet> {
+ late bool _notificationsEnabled = widget.notificationsEnabled;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+ final l10n = context.strings;
+ return BottomSheetComponent(
+ title: widget.isCritical
+ ? l10n.criticalUpdateAvailable
+ : l10n.updateAvailable,
+ illustration: Container(
+ width: 56,
+ height: 56,
+ decoration: BoxDecoration(
+ color: colors.primaryLight,
+ borderRadius: BorderRadius.circular(Radii.lg),
+ ),
+ child: Center(
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedSparkles,
+ size: IconSizes.medium,
+ color: colors.primary,
+ ),
+ ),
+ ),
+ content: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Text(
+ widget.version,
+ textAlign: TextAlign.center,
+ style: TextStyles.body.copyWith(color: colors.textLight),
+ ),
+ const SizedBox(height: Spacing.lg),
+ Align(
+ child: ButtonComponent(
+ label: l10n.whatsNew,
+ variant: ButtonComponentVariant.secondary,
+ size: ButtonComponentSize.small,
+ density: ButtonComponentDensity.compact,
+ shouldSurfaceExecutionStates: false,
+ leading: HugeIcon(
+ icon: HugeIcons.strokeRoundedArrowUpRight01,
+ size: IconSizes.small,
+ color: colors.textBase,
+ ),
+ onTap: () async {
+ await launchUrlString(
+ widget.changelogUrl,
+ mode: LaunchMode.externalApplication,
+ );
+ },
+ ),
+ ),
+ if (!widget.isCritical) ...[
+ const SizedBox(height: Spacing.xxl),
+ Divider(height: 1, thickness: 1, color: colors.strokeFaint),
+ const SizedBox(height: Spacing.lg),
+ Semantics(
+ toggled: _notificationsEnabled,
+ label: l10n.notifyMe,
+ onTap: () => _setNotificationsEnabled(!_notificationsEnabled),
+ excludeSemantics: true,
+ child: InkWell(
+ onTap: () => _setNotificationsEnabled(!_notificationsEnabled),
+ borderRadius: BorderRadius.circular(Radii.sm),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: Spacing.xs),
+ child: Row(
+ children: [
+ Text(
+ l10n.notifyMe,
+ style: TextStyles.body.copyWith(color: colors.textBase),
+ ),
+ const Spacer(),
+ ToggleSwitchComponent(
+ selected: _notificationsEnabled,
+ onChanged: _setNotificationsEnabled,
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ],
+ ],
+ ),
+ showCloseButton: !widget.isCritical,
+ actions: [
+ ButtonComponent(
+ label: l10n.downloadApplicationUpdate,
+ shouldSurfaceExecutionStates: false,
+ onTap: () async {
+ await launchUrlString(
+ widget.downloadUrl,
+ mode: LaunchMode.externalApplication,
+ );
+ },
+ ),
+ ],
+ );
+ }
+
+ void _setNotificationsEnabled(bool enabled) {
+ setState(() => _notificationsEnabled = enabled);
+ widget.onNotificationsChanged(enabled).ignore();
+ }
+}