mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 01:45:55 +08:00
Android: Do not call FlutterResult from any other thread
With Flutter 1.5 this is enforced and we get lots more crashes. It seems like the docs have always said this was a bad idea, and I seem to have missed it.
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
package io.gitjournal.gitjournal;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
|
||||
public class AnyThreadResult implements MethodChannel.Result {
|
||||
private Result result;
|
||||
|
||||
AnyThreadResult(Result r) {
|
||||
result = r;
|
||||
}
|
||||
|
||||
public void success(@Nullable Object var1) {
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
result.success(var1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void error(String var1, @Nullable String var2, @Nullable Object var3) {
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
result.error(var1, var2, var3);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void notImplemented() {
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
result.notImplemented();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -9,13 +9,11 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
|
||||
public class GenerateSSHKeysTask extends AsyncTask<String, Void, Void> {
|
||||
private final static String TAG = "GenerateSSHKeys";
|
||||
private Result result;
|
||||
private AnyThreadResult result;
|
||||
|
||||
public GenerateSSHKeysTask(Result _result) {
|
||||
public GenerateSSHKeysTask(AnyThreadResult _result) {
|
||||
result = _result;
|
||||
}
|
||||
|
||||
|
@ -3,13 +3,11 @@ package io.gitjournal.gitjournal;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
|
||||
public class GitAddTask extends AsyncTask<String, Void, Void> {
|
||||
private final static String TAG = "GitAdd";
|
||||
private Result result;
|
||||
private AnyThreadResult result;
|
||||
|
||||
public GitAddTask(Result _result) {
|
||||
public GitAddTask(AnyThreadResult _result) {
|
||||
result = _result;
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,11 @@ import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
|
||||
public class GitCloneTask extends AsyncTask<String, Void, Void> {
|
||||
private final static String TAG = "GitClone";
|
||||
private Result result;
|
||||
private AnyThreadResult result;
|
||||
|
||||
public GitCloneTask(Result _result) {
|
||||
public GitCloneTask(AnyThreadResult _result) {
|
||||
result = _result;
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,11 @@ import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
|
||||
public class GitCommitTask extends AsyncTask<String, Void, Void> {
|
||||
private final static String TAG = "GitCommit";
|
||||
private Result result;
|
||||
private AnyThreadResult result;
|
||||
|
||||
public GitCommitTask(Result _result) {
|
||||
public GitCommitTask(AnyThreadResult _result) {
|
||||
result = _result;
|
||||
}
|
||||
|
||||
|
@ -3,13 +3,11 @@ package io.gitjournal.gitjournal;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
|
||||
public class GitInitTask extends AsyncTask<String, Void, Void> {
|
||||
private final static String TAG = "GitInit";
|
||||
private Result result;
|
||||
private AnyThreadResult result;
|
||||
|
||||
public GitInitTask(Result _result) {
|
||||
public GitInitTask(AnyThreadResult _result) {
|
||||
result = _result;
|
||||
}
|
||||
|
||||
|
@ -3,13 +3,11 @@ package io.gitjournal.gitjournal;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
|
||||
public class GitPullTask extends AsyncTask<String, Void, Void> {
|
||||
private final static String TAG = "GitPull";
|
||||
private Result result;
|
||||
private AnyThreadResult result;
|
||||
|
||||
public GitPullTask(Result _result) {
|
||||
public GitPullTask(AnyThreadResult _result) {
|
||||
result = _result;
|
||||
}
|
||||
|
||||
|
@ -3,13 +3,11 @@ package io.gitjournal.gitjournal;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
|
||||
public class GitPushTask extends AsyncTask<String, Void, Void> {
|
||||
private final static String TAG = "GitPush";
|
||||
private Result result;
|
||||
private AnyThreadResult result;
|
||||
|
||||
public GitPushTask(Result _result) {
|
||||
public GitPushTask(AnyThreadResult _result) {
|
||||
result = _result;
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,11 @@ package io.gitjournal.gitjournal;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
|
||||
public class GitResetLastTask extends AsyncTask<String, Void, Void> {
|
||||
private final static String TAG = "GitResetLastTask";
|
||||
private Result result;
|
||||
private AnyThreadResult result;
|
||||
|
||||
public GitResetLastTask(Result _result) {
|
||||
public GitResetLastTask(AnyThreadResult _result) {
|
||||
result = _result;
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,11 @@ import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
|
||||
public class GitRmTask extends AsyncTask<String, Void, Void> {
|
||||
private final static String TAG = "GitRm";
|
||||
private Result result;
|
||||
private AnyThreadResult result;
|
||||
|
||||
public GitRmTask(Result _result) {
|
||||
public GitRmTask(AnyThreadResult _result) {
|
||||
result = _result;
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,8 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||
|
||||
String cloneLocation = filesDir + "/" + folderName;
|
||||
|
||||
new GitCloneTask(result).execute(cloneUrl, cloneLocation, publicKeyPath, privateKeyPath);
|
||||
AnyThreadResult anyResult = new AnyThreadResult(result);
|
||||
new GitCloneTask(anyResult).execute(cloneUrl, cloneLocation, publicKeyPath, privateKeyPath);
|
||||
return;
|
||||
} else if (call.method.equals("gitPull")) {
|
||||
String folderName = call.argument("folderName");
|
||||
@ -86,7 +87,8 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||
|
||||
String cloneLocation = filesDir + "/" + folderName;
|
||||
|
||||
new GitPullTask(result).execute(cloneLocation, publicKeyPath, privateKeyPath, authorName, authorEmail);
|
||||
AnyThreadResult anyResult = new AnyThreadResult(result);
|
||||
new GitPullTask(anyResult).execute(cloneLocation, publicKeyPath, privateKeyPath, authorName, authorEmail);
|
||||
return;
|
||||
} else if (call.method.equals("gitPush")) {
|
||||
String folderName = call.argument("folderName");
|
||||
@ -98,7 +100,8 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||
|
||||
String cloneLocation = filesDir + "/" + folderName;
|
||||
|
||||
new GitPushTask(result).execute(cloneLocation, publicKeyPath, privateKeyPath);
|
||||
AnyThreadResult anyResult = new AnyThreadResult(result);
|
||||
new GitPushTask(anyResult).execute(cloneLocation, publicKeyPath, privateKeyPath);
|
||||
return;
|
||||
} else if (call.method.equals("gitAdd")) {
|
||||
String folderName = call.argument("folderName");
|
||||
@ -115,7 +118,8 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||
|
||||
String cloneLocation = filesDir + "/" + folderName;
|
||||
|
||||
new GitAddTask(result).execute(cloneLocation, filePattern);
|
||||
AnyThreadResult anyResult = new AnyThreadResult(result);
|
||||
new GitAddTask(anyResult).execute(cloneLocation, filePattern);
|
||||
return;
|
||||
} else if (call.method.equals("gitRm")) {
|
||||
String folderName = call.argument("folderName");
|
||||
@ -132,7 +136,8 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||
|
||||
String cloneLocation = filesDir + "/" + folderName;
|
||||
|
||||
new GitRmTask(result).execute(cloneLocation, filePattern);
|
||||
AnyThreadResult anyResult = new AnyThreadResult(result);
|
||||
new GitRmTask(anyResult).execute(cloneLocation, filePattern);
|
||||
return;
|
||||
} else if (call.method.equals("gitCommit")) {
|
||||
String folderName = call.argument("folderName");
|
||||
@ -160,7 +165,8 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||
|
||||
String cloneLocation = filesDir + "/" + folderName;
|
||||
|
||||
new GitCommitTask(result).execute(cloneLocation, authorName, authorEmail, message, dateTimeStr);
|
||||
AnyThreadResult anyResult = new AnyThreadResult(result);
|
||||
new GitCommitTask(anyResult).execute(cloneLocation, authorName, authorEmail, message, dateTimeStr);
|
||||
return;
|
||||
} else if (call.method.equals("gitInit")) {
|
||||
String folderName = call.argument("folderName");
|
||||
@ -172,7 +178,8 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||
|
||||
String initLocation = filesDir + "/" + folderName;
|
||||
|
||||
new GitInitTask(result).execute(initLocation);
|
||||
AnyThreadResult anyResult = new AnyThreadResult(result);
|
||||
new GitInitTask(anyResult).execute(initLocation);
|
||||
return;
|
||||
} else if (call.method.equals("gitResetLast")) {
|
||||
String folderName = call.argument("folderName");
|
||||
@ -184,7 +191,8 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||
|
||||
String cloneLocation = filesDir + "/" + folderName;
|
||||
|
||||
new GitResetLastTask(result).execute(cloneLocation);
|
||||
AnyThreadResult anyResult = new AnyThreadResult(result);
|
||||
new GitResetLastTask(anyResult).execute(cloneLocation);
|
||||
return;
|
||||
} else if (call.method.equals("generateSSHKeys")) {
|
||||
String comment = call.argument("comment");
|
||||
@ -193,7 +201,8 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||
comment = "Generated on Android";
|
||||
}
|
||||
|
||||
new GenerateSSHKeysTask(result).execute(sshKeysLocation, comment);
|
||||
AnyThreadResult anyResult = new AnyThreadResult(result);
|
||||
new GenerateSSHKeysTask(anyResult).execute(sshKeysLocation, comment);
|
||||
return;
|
||||
} else if (call.method.equals("getSSHPublicKey")) {
|
||||
String publicKey = "";
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: journal
|
||||
description: A Journaling App Built on top of Git
|
||||
version: 1.1.9+10
|
||||
version: 1.1.10+10
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
|
Reference in New Issue
Block a user