Prechádzať zdrojové kódy

Rate Us: Open playstore app for rating with fallback to https url

Neeraj Gupta 2 rokov pred
rodič
commit
5c8cdd2bb0

+ 20 - 4
lib/services/update_service.dart

@@ -8,6 +8,7 @@ import 'package:photos/core/network.dart';
 import 'package:photos/services/notification_service.dart';
 import 'package:shared_preferences/shared_preferences.dart';
 import 'package:tuple/tuple.dart';
+import 'package:url_launcher/url_launcher_string.dart';
 
 class UpdateService {
   UpdateService._privateConstructor();
@@ -137,15 +138,30 @@ class UpdateService {
       );
     }
     return Platform.isAndroid
-        ? const Tuple2(
-            "play store",
-            "https://play.google.com/store/apps/details?id=io.ente.photos",
-          )
+        ? const Tuple2("play store", "market://details?id=io.ente.photos")
         : const Tuple2(
             "app store",
             "https://apps.apple.com/in/app/ente-photos/id1542026904",
           );
   }
+
+  Future<void> launchReviewUrl() async {
+    // TODO: Replace with https://pub.dev/packages/in_app_review
+    final String url = getRateDetails().item2;
+    try {
+      await launchUrlString(url, mode: LaunchMode.externalApplication);
+    } catch (e) {
+      _logger.severe("Failed top open launch url $url", e);
+      // Fall back if we fail to open play-store market app on android
+      if (Platform.isAndroid && url.startsWith("market://")) {
+        launchUrlString(
+                "https://play.google.com/store/apps/details?id=io"
+                ".ente.photos",
+                mode: LaunchMode.externalApplication)
+            .ignore();
+      }
+    }
+  }
 }
 
 class LatestVersionInfo {

+ 1 - 4
lib/ui/notification/update/change_log_page.dart

@@ -6,7 +6,6 @@ import 'package:photos/ui/components/divider_widget.dart';
 import 'package:photos/ui/components/models/button_type.dart';
 import 'package:photos/ui/components/title_bar_title_widget.dart';
 import 'package:photos/ui/notification/update/change_log_entry.dart';
-import 'package:url_launcher/url_launcher_string.dart';
 
 class ChangeLogPage extends StatefulWidget {
   const ChangeLogPage({
@@ -85,9 +84,7 @@ class _ChangeLogPageState extends State<ChangeLogPage> {
                       icon: Icons.favorite_rounded,
                       iconColor: enteColorScheme.primary500,
                       onTap: () async {
-                        launchUrlString(
-                          UpdateService.instance.getRateDetails().item2,
-                        );
+                        await UpdateService.instance.launchReviewUrl();
                       },
                     ),
                     const SizedBox(height: 8),

+ 2 - 8
lib/ui/settings/backup_section_widget.dart

@@ -1,5 +1,3 @@
-
-
 import 'dart:io';
 
 import 'package:flutter/material.dart';
@@ -23,7 +21,6 @@ import 'package:photos/utils/data_util.dart';
 import 'package:photos/utils/dialog_util.dart';
 import 'package:photos/utils/navigation_util.dart';
 import 'package:photos/utils/toast_util.dart';
-import 'package:url_launcher/url_launcher_string.dart';
 
 class BackupSectionWidget extends StatefulWidget {
   const BackupSectionWidget({Key? key}) : super(key: key);
@@ -167,8 +164,7 @@ class BackupSectionWidgetState extends State<BackupSectionWidget> {
       body: "You have successfully freed up " + formatBytes(status.size) + "!",
       firstButtonLabel: "Rate us",
       firstButtonOnTap: () async {
-        final url = UpdateService.instance.getRateDetails().item2;
-        launchUrlString(url);
+        UpdateService.instance.launchReviewUrl();
       },
       firstButtonType: ButtonType.primary,
       secondButtonLabel: "OK",
@@ -206,9 +202,7 @@ class BackupSectionWidgetState extends State<BackupSectionWidget> {
           "!",
       firstButtonLabel: "Rate us",
       firstButtonOnTap: () async {
-        // TODO: Replace with https://pub.dev/packages/in_app_review
-        final url = UpdateService.instance.getRateDetails().item2;
-        launchUrlString(url);
+        UpdateService.instance.launchReviewUrl();
       },
       firstButtonType: ButtonType.primary,
       secondButtonLabel: "OK",

+ 1 - 6
lib/ui/viewer/gallery/gallery_app_bar_widget.dart

@@ -1,5 +1,3 @@
-
-
 import 'dart:async';
 import 'dart:io';
 
@@ -31,7 +29,6 @@ import 'package:photos/utils/dialog_util.dart';
 import 'package:photos/utils/magic_util.dart';
 import 'package:photos/utils/navigation_util.dart';
 import 'package:photos/utils/toast_util.dart';
-import 'package:url_launcher/url_launcher_string.dart';
 
 class GalleryAppBarWidget extends StatefulWidget {
   final GalleryType type;
@@ -206,9 +203,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
       body: "You have successfully freed up " + formatBytes(status.size) + "!",
       firstButtonLabel: "Rate us",
       firstButtonOnTap: () async {
-        // TODO: Replace with https://pub.dev/packages/in_app_review
-        final url = UpdateService.instance.getRateDetails().item2;
-        launchUrlString(url);
+        UpdateService.instance.launchReviewUrl();
       },
       firstButtonType: ButtonType.primary,
       secondButtonLabel: "OK",