mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-26 00:29:20 +08:00
Move fetch application logs to its own plugin
Maybe it will be useful to others. This way we're also closer to removing almost all java / objective-c custom code.
This commit is contained in:
@ -1,29 +0,0 @@
|
||||
package io.gitjournal.gitjournal;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class LogDumper {
|
||||
public static void dumpLogs(String filePath) throws Exception {
|
||||
File file = new File(filePath);
|
||||
|
||||
// Truncate the existing file
|
||||
PrintWriter pw = new PrintWriter(file);
|
||||
pw.close();
|
||||
|
||||
FileOutputStream stream = new FileOutputStream(file, true);
|
||||
|
||||
Process logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d"});
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(logcat.getInputStream()), 4 * 1024);
|
||||
String line;
|
||||
String separator = System.getProperty("line.separator");
|
||||
while ((line = br.readLine()) != null) {
|
||||
stream.write(line.getBytes());
|
||||
stream.write(separator.getBytes());
|
||||
}
|
||||
stream.close();
|
||||
}
|
||||
}
|
@ -56,23 +56,9 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||
if (call.method.equals("getBaseDirectory")) {
|
||||
result.success(filesDir);
|
||||
return;
|
||||
} else if (call.method.equals("dumpAppLogs")) {
|
||||
String filePath = filesDir + "/app-logs.txt";
|
||||
|
||||
try {
|
||||
LogDumper.dumpLogs(filePath);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
result.error("FAILED", e.toString(), null);
|
||||
return;
|
||||
}
|
||||
|
||||
result.success(filePath);
|
||||
return;
|
||||
} else if (call.method.equals("shouldEnableAnalytics")) {
|
||||
boolean shouldBe = true;
|
||||
String testLabSetting =
|
||||
Settings.System.getString(context.getContentResolver(), "firebase.test.lab");
|
||||
String testLabSetting = Settings.System.getString(context.getContentResolver(), "firebase.test.lab");
|
||||
if ("true".equals(testLabSetting)) {
|
||||
shouldBe = false;
|
||||
}
|
||||
|
@ -34,14 +34,6 @@ Future<bool> shouldEnableAnalytics() async {
|
||||
}
|
||||
}
|
||||
|
||||
/// adb logcat
|
||||
/// Returns the file path where the logs were dumped
|
||||
Future<String> dumpAppLogs() async {
|
||||
const _platform = MethodChannel('gitjournal.io/git');
|
||||
final String logsFilePath = await _platform.invokeMethod('dumpAppLogs');
|
||||
return logsFilePath;
|
||||
}
|
||||
|
||||
void showUndoDeleteSnackbar(
|
||||
BuildContext context,
|
||||
StateContainerState stateContainer,
|
||||
|
@ -6,6 +6,7 @@ import 'package:launch_review/launch_review.dart';
|
||||
import 'package:share/share.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:page_transition/page_transition.dart';
|
||||
import 'package:fetch_app_logs/fetch_app_logs.dart';
|
||||
|
||||
import 'package:gitjournal/analytics.dart';
|
||||
import 'package:gitjournal/state_container.dart';
|
||||
@ -163,7 +164,7 @@ class AppDrawer extends StatelessWidget {
|
||||
onTap: () async {
|
||||
var platform = Platform.operatingSystem;
|
||||
var versionText = await getVersionString();
|
||||
var appLogsFilePath = await dumpAppLogs();
|
||||
var appLogsFilePath = await FetchAppLogs.dumpAppLogsToFile();
|
||||
|
||||
final Email email = Email(
|
||||
body:
|
||||
|
@ -113,6 +113,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
fetch_app_logs:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: fetch_app_logs
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.1"
|
||||
file:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -30,7 +30,8 @@ dependencies:
|
||||
flutter_staggered_grid_view: ^0.3.0
|
||||
page_transition: "^1.1.5"
|
||||
provider: ^3.2.0
|
||||
git_bindings: 0.0.2
|
||||
git_bindings: ^0.0.2
|
||||
fetch_app_logs: ^0.0.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_launcher_icons: "^0.7.2"
|
||||
|
Reference in New Issue
Block a user