π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[auth] Hide unsupported Linux QR sharing
Neeraj Gupta962c3edd12a2
diff --git a/mobile/apps/auth/lib/ui/components/auth_qr_dialog.dart b/mobile/apps/auth/lib/ui/components/auth_qr_dialog.dartindex 385669dc37..0257c3b20b 100644--- a/mobile/apps/auth/lib/ui/components/auth_qr_dialog.dart+++ b/mobile/apps/auth/lib/ui/components/auth_qr_dialog.dart@@ -7,6 +7,7 @@ import 'package:ente_auth/theme/colors.dart';import 'package:ente_auth/theme/ente_theme.dart';import 'package:ente_components/ente_components.dart' hide textBaseLight;import 'package:ente_strings/ente_strings.dart';+import 'package:flutter/foundation.dart' show kIsWeb;import 'package:flutter/material.dart';import 'package:flutter/rendering.dart';import 'package:flutter_svg/flutter_svg.dart';@@ -44,6 +45,7 @@ class _AuthQrDialogState extends State<AuthQrDialog> {Future<void> _shareQrCode() async {try {+ if (!kIsWeb && Platform.isLinux) return;if (!mounted) return;final boundary =_qrKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;@@ -201,7 +203,8 @@ class _AuthQrDialogState extends State<AuthQrDialog> {),),actions: [- ButtonComponent(label: widget.shareButtonText, onTap: _shareQrCode),+ if (kIsWeb || !Platform.isLinux)+ ButtonComponent(label: widget.shareButtonText, onTap: _shareQrCode),],),);diff --git a/mobile/apps/auth/test/ui/auth_qr_dialog_test.dart b/mobile/apps/auth/test/ui/auth_qr_dialog_test.dartnew file mode 100644index 0000000000..392baa2e98--- /dev/null+++ b/mobile/apps/auth/test/ui/auth_qr_dialog_test.dart@@ -0,0 +1,107 @@+import 'dart:io';++import 'package:ente_auth/ui/components/auth_qr_dialog.dart';+import 'package:ente_components/ente_components.dart';+import 'package:ente_strings/ente_strings.dart';+import 'package:flutter/foundation.dart';+import 'package:flutter/material.dart';+import 'package:flutter/services.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:qr_flutter/qr_flutter.dart';++const _fileName = 'ente_auth_qr_synthetic.png';+const _data = 'otpauth://totp/Synthetic:test?secret=JBSWY3DPEHPK3PXP';++Future<void> _pumpDialog(WidgetTester tester) async {+ await tester.pumpWidget(+ const MaterialApp(+ localizationsDelegates: StringsLocalizations.localizationsDelegates,+ supportedLocales: StringsLocalizations.supportedLocales,+ home: Scaffold(+ body: AuthQrDialog(+ data: _data,+ title: 'Synthetic issuer',+ subtitle: 'Synthetic account',+ shareFileName: _fileName,+ shareText: 'Synthetic QR code',+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+}++void main() {+ testWidgets('keeps the QR visible and gates sharing by the native platform', (+ tester,+ ) async {+ await _pumpDialog(tester);++ expect(find.text('Synthetic issuer'), findsOneWidget);+ expect(find.text('Synthetic account'), findsOneWidget);+ expect(find.byType(QrImageView), findsOneWidget);+ final sheet = tester.widget<BottomSheetComponent>(+ find.byType(BottomSheetComponent),+ );+ if (!kIsWeb && Platform.isLinux) {+ expect(sheet.actions, isEmpty);+ expect(find.text('Share'), findsNothing);+ } else {+ expect(sheet.actions, hasLength(1));+ expect(find.text('Share'), findsOneWidget);+ }++ await tester.tap(find.byType(QrImageView));+ await tester.pump();+ expect(find.byType(QrImageView), findsOneWidget);+ expect(tester.takeException(), isNull);+ });++ testWidgets('native sharing only creates a PNG on supported platforms', (+ tester,+ ) async {+ final directory = Directory.systemTemp.createTempSync('auth-qr-test-');+ addTearDown(() => directory.deleteSync(recursive: true));+ var temporaryDirectoryRequests = 0;+ final shares = <MethodCall>[];+ const pathChannel = MethodChannel('plugins.flutter.io/path_provider');+ const shareChannel = MethodChannel('dev.fluttercommunity.plus/share');+ final messenger =+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;+ messenger.setMockMethodCallHandler(pathChannel, (call) async {+ expect(call.method, 'getTemporaryDirectory');+ temporaryDirectoryRequests++;+ return directory.path;+ });+ messenger.setMockMethodCallHandler(shareChannel, (call) async {+ shares.add(call);+ return 'test';+ });+ addTearDown(() {+ messenger.setMockMethodCallHandler(pathChannel, null);+ messenger.setMockMethodCallHandler(shareChannel, null);+ });++ await _pumpDialog(tester);+ if (Platform.isLinux) {+ expect(find.text('Share'), findsNothing);+ expect(temporaryDirectoryRequests, 0);+ expect(shares, isEmpty);+ expect(directory.listSync(), isEmpty);+ } else {+ final button = tester.widget<ButtonComponent>(+ find.widgetWithText(ButtonComponent, 'Share'),+ );+ await tester.runAsync(() async => button.onTap!());+ expect(temporaryDirectoryRequests, 1);+ final png = File('${directory.path}/$_fileName');+ expect(png.existsSync(), isTrue);+ expect(png.readAsBytesSync().take(8), [137, 80, 78, 71, 13, 10, 26, 10]);+ expect(shares, hasLength(1));+ expect(shares.single.method, 'share');+ expect(shares.single.arguments['paths'], [png.path]);+ expect(shares.single.arguments['text'], 'Synthetic QR code');+ }+ expect(tester.takeException(), isNull);+ }, skip: kIsWeb);+}