Skip to content

Commit

Permalink
Export fixes (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
ua741 authored Feb 9, 2024
1 parent 310d32d commit 27c6d8f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions lib/ui/settings/data/export_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -122,8 +124,11 @@ Future<void> _showExportWarningDialog(BuildContext context) async {
}

Future<void> _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);
Expand All @@ -135,8 +140,21 @@ Future<void> _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();
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 27c6d8f

Please sign in to comment.