Skip to content

Commit

Permalink
Fix export logs for droid
Browse files Browse the repository at this point in the history
  • Loading branch information
ua741 committed Oct 19, 2023
1 parent cc4008e commit 361ad64
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
34 changes: 31 additions & 3 deletions lib/utils/email_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import 'dart:io';

import 'package:archive/archive_io.dart';
import 'package:email_validator/email_validator.dart';
import "package:file_saver/file_saver.dart";
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_email_sender/flutter_email_sender.dart';
import "package:intl/intl.dart";
import 'package:logging/logging.dart';
import 'package:open_mail_app/open_mail_app.dart';
import 'package:package_info_plus/package_info_plus.dart';
Expand Down Expand Up @@ -75,6 +77,15 @@ Future<void> sendLogs(
);
},
),
ButtonWidget(
buttonType: ButtonType.secondary,
labelText: S.of(context).exportLogs,
buttonAction: ButtonAction.third,
onTap: () async {
final zipFilePath = await getZippedLogsFile(context);
await exportLogs(context, zipFilePath);
},
),
ButtonWidget(
isInAlert: true,
buttonType: ButtonType.secondary,
Expand Down Expand Up @@ -159,9 +170,26 @@ Future<void> shareLogs(
],
);
if (result?.action != null && result!.action == ButtonAction.second) {
final Size size = MediaQuery.of(context).size;
await Share.shareFiles(
[zipFilePath],
await exportLogs(context, zipFilePath);
}
}

Future<void> exportLogs(BuildContext context, String zipFilePath) async {
final Size size = MediaQuery.of(context).size;
if (Platform.isAndroid) {
final DateTime now = DateTime.now().toUtc();
final String shortMonthName = DateFormat('MMM').format(now); // Short month
final String logFileName =
'ente-logs-${now.year}-$shortMonthName-${now.day}-${now.hour}-${now.minute}';
await FileSaver.instance.saveAs(
name: logFileName,
filePath: zipFilePath,
mimeType: MimeType.zip,
ext: 'zip',
);
} else {
await Share.shareXFiles(
[XFile(zipFilePath, mimeType: 'application/zip')],
sharePositionOrigin: Rect.fromLTWH(0, 0, size.width, size.height / 2),
);
}
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.1.4"
file_saver:
dependency: "direct main"
description:
name: file_saver
sha256: "8ffd91ae9f543c5ebbfec71a814ee5aa9e21176d31335133308abf63f4c42e8a"
url: "https://pub.dev"
source: hosted
version: "0.2.9"
firebase_core:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies:
expansion_tile_card: ^3.0.0
extended_image: ^8.1.1
fast_base58: ^0.2.1
file_saver: ^0.2.9
firebase_core: ^2.13.1
firebase_messaging: ^14.6.2
fk_user_agent: ^2.0.1
Expand Down

0 comments on commit 361ad64

Please sign in to comment.