call rpc.start() before it is used

This commit is contained in:
adbenitez 2025-03-10 17:30:59 +01:00
parent 906db9155a
commit bcee64317d
2 changed files with 6 additions and 3 deletions

View file

@ -17,6 +17,7 @@ public class Rpc {
private final Map<Integer, SettableFuture<JsonElement>> requestFutures = new ConcurrentHashMap<>();
private final DcJsonrpcInstance dcJsonrpcInstance;
private int requestId = 0;
private boolean started = false;
private final Gson gson = new GsonBuilder().serializeNulls().create();
public Rpc(DcJsonrpcInstance dcJsonrpcInstance) {
@ -46,6 +47,7 @@ public class Rpc {
}
public void start() {
started = true;
new Thread(() -> {
while (true) {
try {
@ -57,7 +59,9 @@ public class Rpc {
}, "jsonrpcThread").start();
}
public SettableFuture<JsonElement> call(String method, Object... params) {
public SettableFuture<JsonElement> call(String method, Object... params) throws RpcException {
if (!started) throw new RpcException("RPC not started yet.");
int id;
synchronized (this) {
id = ++requestId;

View file

@ -88,6 +88,7 @@ public class ApplicationContext extends MultiDexApplication {
dcAccounts = new DcAccounts(new File(getFilesDir(), "accounts").getAbsolutePath());
rpc = new Rpc(dcAccounts.getJsonrpcInstance());
rpc.start();
AccountManager.getInstance().migrateToDcAccounts(this);
int[] allAccounts = dcAccounts.getAll();
for (int accountId : allAccounts) {
@ -126,8 +127,6 @@ public class ApplicationContext extends MultiDexApplication {
Log.i("DeltaChat", "shutting down event handler");
}, "eventThread").start();
rpc.start();
// migrating global notifications pref. to per-account config, added 10/July/24
final String NOTIFICATION_PREF = "pref_key_enable_notifications";
boolean isMuted = !Prefs.getBooleanPreference(this, NOTIFICATION_PREF, true);