π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Add support for closing session
Neeraj Gupta741112519465
diff --git a/mobile/lib/ui/cast/auto.dart b/mobile/lib/ui/cast/auto.dartindex 8afacf7db7..4dc9d5bd01 100644--- a/mobile/lib/ui/cast/auto.dart+++ b/mobile/lib/ui/cast/auto.dart@@ -100,7 +100,7 @@ class _AutoCastDialogState extends State<AutoCastDialog> {if (message.containsKey(CastMessageType.pairCode)) {final code = message[CastMessageType.pairCode]!['code'];widget.onConnect(code);- // Navigator.of(context).pop();+ Navigator.of(context).pop();}},);diff --git a/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dartindex 4365b78130..489d5478ec 100644--- a/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart+++ b/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart@@ -583,9 +583,14 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {Tooltip(message: "Cast album",child: IconButton(- icon: const Icon(Icons.cast_outlined),+ icon: castService.getActiveSessions().isNotEmpty+ ? const Icon(Icons.cast_connected_rounded)+ : const Icon(Icons.cast_outlined),onPressed: () async {await _castChoiceDialog();+ if (mounted) {+ setState(() {});+ }},),),@@ -855,6 +860,21 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {Future<void> _castChoiceDialog() async {final gw = CastGateway(NetworkClient.instance.enteDio);+ if (castService.getActiveSessions().isNotEmpty) {+ await showChoiceDialog(+ context,+ title: "Stop casting",+ firstButtonLabel: "Yes",+ secondButtonLabel: "No",+ body: "Do you want to stop casting?",+ firstButtonOnTap: () async {+ gw.revokeAllTokens().ignore();+ await castService.closeActiveCasts();+ },+ );+ return;+ }+// stop any existing cast sessiongw.revokeAllTokens().ignore();final result = await showDialog<ButtonAction?>(diff --git a/mobile/plugins/ente_cast/lib/src/service.dart b/mobile/plugins/ente_cast/lib/src/service.dartindex 82d8c5978c..2ab0961dbd 100644--- a/mobile/plugins/ente_cast/lib/src/service.dart+++ b/mobile/plugins/ente_cast/lib/src/service.dart@@ -12,7 +12,7 @@ abstract class CastService {void Function(Map<CastMessageType, Map<String, dynamic>>)? onMessage,});// returns a map of sessionID to deviceNames- Future<Map<String, String>> getActiveSessions();+ Map<String, String> getActiveSessions();Future<void> closeActiveCasts();}diff --git a/mobile/plugins/ente_cast_none/lib/src/service.dart b/mobile/plugins/ente_cast_none/lib/src/service.dartindex 007a4daaa0..c781889733 100644--- a/mobile/plugins/ente_cast_none/lib/src/service.dart+++ b/mobile/plugins/ente_cast_none/lib/src/service.dart@@ -28,7 +28,7 @@ class CastServiceImpl extends CastService {}@override- Future<Map<String, String>> getActiveSessions() {+ Map<String, String> getActiveSessions() {// TODO: implement getActiveSessionsthrow UnimplementedError();}diff --git a/mobile/plugins/ente_cast_normal/lib/src/service.dart b/mobile/plugins/ente_cast_normal/lib/src/service.dartindex 314194b944..a2c4206c87 100644--- a/mobile/plugins/ente_cast_normal/lib/src/service.dart+++ b/mobile/plugins/ente_cast_normal/lib/src/service.dart@@ -70,24 +70,27 @@ class CastServiceImpl extends CastService {Future<void> closeActiveCasts() {final sessions = CastSessionManager().sessions;for (final session in sessions) {- session.sendMessage(- _pairRequestNamespace,- {- "type": "CLOSE",- },- );+ debugPrint("send close message for ${session.sessionId}");+ session.sendMessage(CastSession.kNamespaceConnection, {+ 'type': 'CLOSE',+ });+ debugPrint("close session ${session.sessionId}");session.close();}+ CastSessionManager().sessions.clear();+ debugPrint("send close message");return Future.value();}@override- Future<Map<String, String>> getActiveSessions() {+ Map<String, String> getActiveSessions() {final sessions = CastSessionManager().sessions;final Map<String, String> result = {};for (final session in sessions) {- result[session.sessionId] = session.state.toString();+ if (session.state == CastSessionState.connected) {+ result[session.sessionId] = session.state.toString();+ }}- return Future.value(result);+ return result;}}