Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refine cast pairing flow

Priyanshu Dangare855eef429817
diff --git a/mobile/apps/photos/lib/ui/cast/cast.dart b/mobile/apps/photos/lib/ui/cast/cast.dart
index 1119393ff4..a208ca816d 100644
--- a/mobile/apps/photos/lib/ui/cast/cast.dart
+++ b/mobile/apps/photos/lib/ui/cast/cast.dart
@@ -1,4 +1,8 @@
+import "dart:async";
+import "dart:io";
+
import "package:ente_components/ente_components.dart";
+import "package:flutter/foundation.dart";
import "package:flutter/widgets.dart";
import "package:hugeicons/hugeicons.dart";
import "package:logging/logging.dart";
@@ -17,6 +21,7 @@ Future<void> showCastSheet(BuildContext context, Collection collection) async {
final l10n = AppLocalizations.of(context);
final textStyle = getEnteTextTheme(context);
final gw = CastGateway(NetworkClient.instance.enteDio);
+ final showAutoPair = Platform.isAndroid || kDebugMode;
if (!flagService.enableMultiCast) {
if (castService.getActiveSessions().isNotEmpty) {
await showChoiceDialog(
@@ -26,14 +31,16 @@ Future<void> showCastSheet(BuildContext context, Collection collection) async {
firstButtonLabel: l10n.yes,
secondButtonLabel: l10n.no,
firstButtonOnTap: () async {
- await gw.revokeAllTokens();
+ unawaited(gw.revokeAllTokens());
await castService.closeActiveCasts();
},
);
return;
}
+ unawaited(gw.revokeAllTokens());
+ } else {
+ await castService.closeActiveCasts();
}
- await castService.closeActiveCasts();
final logger = Logger("showCastSheet");
List<CastInfo> sessions = [];
if (flagService.enableMultiCast) {
@@ -54,17 +61,19 @@ Future<void> showCastSheet(BuildContext context, Collection collection) async {
snap: true,
title: l10n.castAlbum,
actions: [
- Text(l10n.pairWithAutoDesc, style: textStyle.smallMuted),
- ButtonComponent(
- label: l10n.autoPair,
- variant: .secondary,
- leading: const HugeIcon(icon: HugeIcons.strokeRoundedTvSmart),
- shouldSurfaceExecutionStates: false,
- onTap: () async {
- Navigator.of(context).pop();
- await showPairWithAutoSheet(context, collection);
- },
- ),
+ if (showAutoPair) ...[
+ Text(l10n.pairWithAutoDesc, style: textStyle.smallMuted),
+ ButtonComponent(
+ label: l10n.autoPair,
+ variant: .secondary,
+ leading: const HugeIcon(icon: HugeIcons.strokeRoundedTvSmart),
+ shouldSurfaceExecutionStates: false,
+ onTap: () async {
+ Navigator.of(context).pop();
+ await showPairWithAutoSheet(context, collection);
+ },
+ ),
+ ],
Text(l10n.pairWithCodeDesc, style: textStyle.smallMuted),
ButtonComponent(
label: l10n.pairUsingCode,
diff --git a/mobile/apps/photos/lib/ui/cast/pair_with_auto.dart b/mobile/apps/photos/lib/ui/cast/pair_with_auto.dart
index a8833a17d9..96b0830f9c 100644
--- a/mobile/apps/photos/lib/ui/cast/pair_with_auto.dart
+++ b/mobile/apps/photos/lib/ui/cast/pair_with_auto.dart
@@ -1,4 +1,3 @@
-import "dart:async";
import "dart:io";
import "package:ente_cast/ente_cast.dart";
@@ -27,9 +26,6 @@ Future<void> _pairWithAuto(
String code,
) async {
final gw = CastGateway(NetworkClient.instance.enteDio);
- if (!flagService.enableMultiCast) {
- await gw.revokeAllTokens();
- }
final publicKey = await gw.getPublicKey(code);
if (publicKey == null) {
throw const _DeviceNotFoundException();
@@ -148,25 +144,18 @@ class _PairWithAutoSheetState extends State<_PairWithAutoSheet> {
return;
}
setState(() => _devicesInProgress.add(device));
- final pairing = Completer<void>();
try {
await castService.connectDevice(
context,
device,
- collectionID: widget.collection.id,
onMessage: (message) async {
- if (pairing.isCompleted) {
- return;
- }
final code = message[CastMessageType.pairCode]?["code"];
if (code is! String) {
return;
}
await _handlePairCode(context, device, code);
- pairing.complete();
},
);
- await pairing.future;
} catch (e, s) {
await _handleError(context, device, e, s);
}