Fix issues related to emailing logs
This commit is contained in:
parent
3489172067
commit
80bbcd8816
2 changed files with 35 additions and 21 deletions
|
@ -33,10 +33,12 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
detector = ShakeDetector.waitForStart(onPhoneShake: () {
|
||||
logger.info("Emailing logs");
|
||||
emailLogs();
|
||||
});
|
||||
detector = ShakeDetector.waitForStart(
|
||||
shakeThresholdGravity: 2,
|
||||
onPhoneShake: () {
|
||||
logger.info("Emailing logs");
|
||||
LoggingUtil.instance.emailLogs();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -4,21 +4,33 @@ import 'package:archive/archive_io.dart';
|
|||
import 'package:flutter_email_sender/flutter_email_sender.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
Future<void> emailLogs() async {
|
||||
final tempPath = (await getTemporaryDirectory()).path;
|
||||
final zipFilePath = tempPath + "/logs.zip";
|
||||
Directory logsDirectory = Directory(tempPath + "/logs");
|
||||
var encoder = ZipFileEncoder();
|
||||
encoder.create(zipFilePath);
|
||||
encoder.addDirectory(logsDirectory);
|
||||
encoder.close();
|
||||
final Email email = Email(
|
||||
body: 'Logs attached.',
|
||||
subject: 'Error, error, share the terror.',
|
||||
recipients: ['android-support@ente.io'],
|
||||
cc: ['vishnumohandas@gmail.com'],
|
||||
attachmentPaths: [zipFilePath],
|
||||
isHTML: false,
|
||||
);
|
||||
await FlutterEmailSender.send(email);
|
||||
class LoggingUtil {
|
||||
LoggingUtil._privateConstructor();
|
||||
|
||||
static final LoggingUtil instance = LoggingUtil._privateConstructor();
|
||||
|
||||
bool _isInProgress = false;
|
||||
Future<void> emailLogs() async {
|
||||
if (_isInProgress) {
|
||||
return;
|
||||
}
|
||||
_isInProgress = true;
|
||||
final tempPath = (await getTemporaryDirectory()).path;
|
||||
final zipFilePath = tempPath + "/logs.zip";
|
||||
Directory logsDirectory = Directory(tempPath + "/logs");
|
||||
var encoder = ZipFileEncoder();
|
||||
encoder.create(zipFilePath);
|
||||
encoder.addDirectory(logsDirectory);
|
||||
encoder.close();
|
||||
final Email email = Email(
|
||||
body: 'Logs attached.',
|
||||
subject: 'Error, error, share the terror.',
|
||||
recipients: ['android-support@ente.io'],
|
||||
cc: ['vishnumohandas@gmail.com'],
|
||||
attachmentPaths: [zipFilePath],
|
||||
isHTML: false,
|
||||
);
|
||||
await FlutterEmailSender.send(email);
|
||||
_isInProgress = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue