Преглед на файлове

[mob][photos] Show custom error on ip mismatch

Neeraj Gupta преди 1 година
родител
ревизия
5c645d50f0

+ 12 - 4
mobile/lib/gateways/cast_gw.dart

@@ -12,10 +12,14 @@ class CastGateway {
       );
       return response.data["publicKey"];
     } catch (e) {
-      if (e is DioError &&
-          e.response != null &&
-          e.response!.statusCode == 404) {
-        return null;
+      if (e is DioError && e.response != null) {
+        if (e.response!.statusCode == 404) {
+          return null;
+        } else if (e.response!.statusCode == 403) {
+          throw CastIPMismatchException();
+        } else {
+          rethrow;
+        }
       }
       rethrow;
     }
@@ -48,3 +52,7 @@ class CastGateway {
     }
   }
 }
+
+class CastIPMismatchException implements Exception {
+  CastIPMismatchException();
+}

+ 4 - 0
mobile/lib/generated/intl/messages_en.dart

@@ -394,6 +394,10 @@ class MessageLookup extends MessageLookupByLibrary {
         "cannotAddMorePhotosAfterBecomingViewer": m9,
         "cannotDeleteSharedFiles":
             MessageLookupByLibrary.simpleMessage("Cannot delete shared files"),
+        "castIPMismatchBody": MessageLookupByLibrary.simpleMessage(
+            "Please make sure you are on the same network as the TV."),
+        "castIPMismatchTitle":
+            MessageLookupByLibrary.simpleMessage("Failed to cast album"),
         "castInstruction": MessageLookupByLibrary.simpleMessage(
             "Visit cast.ente.io on the device you want to pair.\n\nEnter the code below to play the album on your TV."),
         "centerPoint": MessageLookupByLibrary.simpleMessage("Center point"),

+ 20 - 0
mobile/lib/generated/l10n.dart

@@ -8663,6 +8663,26 @@ class S {
       args: [],
     );
   }
+
+  /// `Failed to cast album`
+  String get castIPMismatchTitle {
+    return Intl.message(
+      'Failed to cast album',
+      name: 'castIPMismatchTitle',
+      desc: '',
+      args: [],
+    );
+  }
+
+  /// `Please make sure you are on the same network as the TV.`
+  String get castIPMismatchBody {
+    return Intl.message(
+      'Please make sure you are on the same network as the TV.',
+      name: 'castIPMismatchBody',
+      desc: '',
+      args: [],
+    );
+  }
 }
 
 class AppLocalizationDelegate extends LocalizationsDelegate<S> {

+ 3 - 1
mobile/lib/l10n/intl_en.arb

@@ -1222,5 +1222,7 @@
   "autoCastiOSPermission": "Make sure Local Network permissions are turned on for the Ente Photos app, in Settings.",
   "noDeviceFound": "No device found",
   "stopCastingTitle": "Stop casting",
-  "stopCastingBody": "Do you want to stop casting?"
+  "stopCastingBody": "Do you want to stop casting?",
+  "castIPMismatchTitle": "Failed to cast album",
+  "castIPMismatchBody": "Please make sure you are on the same network as the TV."
 }

+ 9 - 1
mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart

@@ -948,7 +948,15 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
       return true;
     } catch (e, s) {
       _logger.severe("Failed to cast album", e, s);
-      await showGenericErrorDialog(context: context, error: e);
+      if (e is CastIPMismatchException) {
+        await showErrorDialog(
+          context,
+          S.of(context).castIPMismatchTitle,
+          S.of(context).castIPMismatchBody,
+        );
+      } else {
+        await showGenericErrorDialog(context: context, error: e);
+      }
       return false;
     }
   }