feat: support exporting log files (#4559)

* feat: support exporting log files

* feat: support uploading log files on Android
This commit is contained in:
Lucas.Xu 2024-01-31 10:07:50 +08:00 committed by GitHub
parent 0483e305e7
commit d410ffbaa8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 132 additions and 6 deletions

View File

@ -69,6 +69,8 @@ PODS:
- SDWebImage (5.14.2):
- SDWebImage/Core (= 5.14.2)
- SDWebImage/Core (5.14.2)
- share_plus (0.0.1):
- Flutter
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
@ -99,6 +101,7 @@ DEPENDENCIES:
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- rich_clipboard_ios (from `.symlinks/plugins/rich_clipboard_ios/ios`)
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- sqflite (from `.symlinks/plugins/sqflite/darwin`)
- super_native_extensions (from `.symlinks/plugins/super_native_extensions/ios`)
@ -146,6 +149,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
rich_clipboard_ios:
:path: ".symlinks/plugins/rich_clipboard_ios/ios"
share_plus:
:path: ".symlinks/plugins/share_plus/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
sqflite:
@ -176,6 +181,7 @@ SPEC CHECKSUMS:
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
rich_clipboard_ios: 7588abe18f881a6d0e9ec0b12e51cae2761e8942
SDWebImage: b9a731e1d6307f44ca703b3976d18c24ca561e84
share_plus: c3fef564749587fc939ef86ffb283ceac0baf9f5
shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695
sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec
super_native_extensions: 4916b3c627a9c7fffdc48a23a9eca0b1ac228fa7

View File

@ -29,6 +29,7 @@ class MobileLaunchSettingsPage extends StatelessWidget {
children: [
const LanguageSettingGroup(),
if (Env.enableCustomCloud) const SelfHostSettingGroup(),
const SupportSettingGroup(),
],
),
),

View File

@ -1,6 +1,9 @@
import 'dart:io';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/show_mobile_bottom_sheet.dart';
import 'package:appflowy/mobile/presentation/widgets/widgets.dart';
import 'package:appflowy/util/share_log_files.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
@ -33,10 +36,17 @@ class SupportSettingGroup extends StatelessWidget {
Icons.chevron_right,
),
onTap: () {
final String? version = snapshot.data?.version;
final String os = Platform.operatingSystem;
safeLaunchUrl(
'https://github.com/AppFlowy-IO/AppFlowy/issues/new?assignees=&labels=&projects=&template=bug_report.yaml&title=[Bug]%20Mobile:%20&version=$version&os=$os',
showMobileBottomSheet(
context,
showDragHandle: true,
showHeader: true,
title: LocaleKeys.workspace_errorActions_reportIssue.tr(),
backgroundColor: Theme.of(context).colorScheme.surface,
builder: (context) {
return _ReportIssuesWidget(
version: snapshot.data?.version ?? '',
);
},
);
},
),
@ -45,3 +55,35 @@ class SupportSettingGroup extends StatelessWidget {
);
}
}
class _ReportIssuesWidget extends StatelessWidget {
const _ReportIssuesWidget({
required this.version,
});
final String version;
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
FlowyOptionTile.text(
showTopBorder: false,
text: LocaleKeys.workspace_errorActions_reportIssueOnGithub.tr(),
onTap: () {
final String os = Platform.operatingSystem;
safeLaunchUrl(
'https://github.com/AppFlowy-IO/AppFlowy/issues/new?assignees=&labels=&projects=&template=bug_report.yaml&title=[Bug]%20Mobile:%20&version=$version&os=$os',
);
},
),
FlowyOptionTile.text(
showTopBorder: false,
text: LocaleKeys.workspace_errorActions_exportLogFiles.tr(),
onTap: () => shareLogFiles(context),
),
],
);
}
}

View File

@ -0,0 +1,57 @@
import 'dart:io';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:archive/archive_io.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:share_plus/share_plus.dart';
Future<void> shareLogFiles(BuildContext? context) async {
final dir = await getApplicationSupportDirectory();
final zipEncoder = ZipEncoder();
final archiveLogFiles = dir
.listSync(recursive: true)
.where((e) => p.basename(e.path).startsWith('log.'))
.map((e) {
final bytes = File(e.path).readAsBytesSync();
return ArchiveFile(p.basename(e.path), bytes.length, bytes);
});
if (archiveLogFiles.isEmpty) {
if (context != null && context.mounted) {
showSnackBarMessage(
context,
LocaleKeys.noLogFiles.tr(),
);
}
return;
}
final archive = Archive();
for (final file in archiveLogFiles) {
archive.addFile(file);
}
final zip = zipEncoder.encode(archive);
if (zip == null) {
return;
}
// create a zipped appflowy logs file
final path = Platform.isAndroid ? '/storage/emulated/0/Download' : dir.path;
final zipFile =
await File(p.join(path, 'appflowy_logs.zip')).writeAsBytes(zip);
if (Platform.isIOS) {
await Share.shareUri(zipFile.uri);
} else {
await Share.shareXFiles([XFile(zipFile.path)]);
}
// delete the zipped appflowy logs file
await zipFile.delete();
}

View File

@ -1522,6 +1522,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.3.8"
share_plus:
dependency: "direct main"
description:
name: share_plus
sha256: f74fc3f1cbd99f39760182e176802f693fa0ec9625c045561cfad54681ea93dd
url: "https://pub.dev"
source: hosted
version: "7.2.1"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: df08bc3a07d01f5ea47b45d03ffcba1fa9cd5370fb44b3f38c70e42cced0f956
url: "https://pub.dev"
source: hosted
version: "3.3.1"
shared_preferences:
dependency: "direct main"
description:

View File

@ -98,7 +98,7 @@ dependencies:
http: ^1.0.0
path: ^1.8.3
mocktail: ^1.0.1
archive: ^3.3.7
archive: ^3.4.10
nanoid: ^1.0.0
supabase_flutter: ^1.10.4
envied: ^0.5.2
@ -128,6 +128,7 @@ dependencies:
keyboard_height_plugin: ^0.0.5
scrollable_positioned_list: ^0.3.8
flutter_cache_manager: ^3.3.1
share_plus: ^7.2.1
dev_dependencies:
flutter_lints: ^3.0.1

View File

@ -60,6 +60,8 @@
"failedToLoad": "Something went wrong! Failed to load the workspace. Try to close any open instance of AppFlowy and try again.",
"errorActions": {
"reportIssue": "Report an issue",
"reportIssueOnGithub": "Report an issue on Github",
"exportLogFiles": "Export log files",
"reachOut": "Reach out on Discord"
}
},
@ -1243,5 +1245,6 @@
"date": "Date",
"addField": "Add field",
"userIcon": "User icon"
}
},
"noLogFiles": "There're no log files"
}