Files
GitJournal/lib/apis/git.dart
Vishesh Handa 63170445d7 Move libgit2 code to git_bindings repo
We now have a much clearer separation between Git code and this app
specific code. This is awesome, it will allow other people to easily
integrate Git within their apps. Also, eventually it will be trivial to
switch to another implemention of Git (via JGit or a git client written
completely in Dart)

This breaks the iOS version as I haven't moved the code to build the ios
version. Maybe this will be a good excuse for me to setup a proper CI/CD
system for ios builds.

There is also a chance this breaks Crashalytics NDK symbols :(
2019-12-21 01:06:15 +01:00

57 lines
1.4 KiB
Dart

import 'dart:async';
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:flutter_crashlytics/flutter_crashlytics.dart';
const _platform = MethodChannel('gitjournal.io/git');
bool shouldIgnorePlatformException(PlatformException ex) {
var msg = ex.message.toLowerCase();
if (msg.contains("failed to resolve address for")) {
return true;
}
if (msg.contains("failed to connect to")) {
return true;
}
if (msg.contains("no address associated with hostname")) {
return true;
}
if (msg.contains("failed to connect to")) {
return true;
}
if (msg.contains("unauthorized")) {
return true;
}
if (msg.contains("invalid credentials")) {
return true;
}
if (msg.contains("failed to start ssh session")) {
return true;
}
return false;
}
Future invokePlatformMethod(String method, [dynamic arguments]) async {
try {
return await _platform.invokeMethod(method, arguments);
} on PlatformException catch (e, stacktrace) {
if (!shouldIgnorePlatformException(e)) {
await FlutterCrashlytics().logException(e, stacktrace);
}
throw e;
}
}
///
/// This gives us the directory where all the git repos will be stored
///
Future<Directory> getGitBaseDirectory() async {
final String path = await invokePlatformMethod('getBaseDirectory');
if (path == null) {
return null;
}
return Directory(path);
}