From 27c6d8ffde62a315cfce8c7f9916e31f3a0661ff Mon Sep 17 00:00:00 2001 From: Neeraj Gupta Date: Fri, 9 Feb 2024 12:28:36 +0530 Subject: [PATCH] Export fixes (#445) --- lib/ui/settings/data/export_widget.dart | 24 +++++++++++++++++++++--- pubspec.yaml | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/ui/settings/data/export_widget.dart b/lib/ui/settings/data/export_widget.dart index 2de904417..cc9a1638b 100644 --- a/lib/ui/settings/data/export_widget.dart +++ b/lib/ui/settings/data/export_widget.dart @@ -12,10 +12,12 @@ import 'package:ente_auth/ui/components/models/button_type.dart'; import 'package:ente_auth/utils/crypto_util.dart'; import 'package:ente_auth/utils/dialog_util.dart'; import 'package:ente_auth/utils/toast_util.dart'; +import 'package:file_saver/file_saver.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_sodium/flutter_sodium.dart'; +import 'package:intl/intl.dart'; import 'package:logging/logging.dart'; import 'package:share_plus/share_plus.dart'; @@ -122,8 +124,11 @@ Future _showExportWarningDialog(BuildContext context) async { } Future _exportCodes(BuildContext context, String fileContent) async { + DateTime now = DateTime.now().toUtc(); + String formattedDate = DateFormat('yyyy-MM-dd').format(now); + String exportFileName = 'ente-auth-codes-$formattedDate.txt'; final _codeFile = File( - Configuration.instance.getTempDirectory() + "ente-authenticator-codes.txt", + Configuration.instance.getTempDirectory() + exportFileName, ); final hasAuthenticated = await LocalAuthenticationService.instance .requestLocalAuthentication(context, context.l10n.authToExportCodes); @@ -135,8 +140,21 @@ Future _exportCodes(BuildContext context, String fileContent) async { } _codeFile.writeAsStringSync(fileContent); final Size size = MediaQuery.of(context).size; - await Share.shareFiles([_codeFile.path], sharePositionOrigin: Rect.fromLTWH(0, 0, size.width, size.height / 2),); - Future.delayed(const Duration(seconds: 15), () async { + + if (Platform.isAndroid) { + await FileSaver.instance.saveAs( + name: exportFileName, + filePath: _codeFile.path, + mimeType: MimeType.text, + ext: 'txt', + ); + } else { + await Share.shareFiles( + [_codeFile.path], + sharePositionOrigin: Rect.fromLTWH(0, 0, size.width, size.height / 2), + ); + } + Future.delayed(const Duration(seconds: 30), () async { if (_codeFile.existsSync()) { _codeFile.deleteSync(); } diff --git a/pubspec.yaml b/pubspec.yaml index 42063a122..cc7adfee2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: ente_auth description: ente two-factor authenticator -version: 2.0.32+232 +version: 2.0.33+233 publish_to: none environment: