From 7e3c6c0b8f8bbdc1788d9e0ea7aecadd851862e6 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Mon, 7 May 2018 14:47:05 +0200 Subject: [PATCH] Reread the config on configSaved event (fixes #1078) --- .../syncthingandroid/service/EventProcessor.java | 6 ++++++ .../com/nutomic/syncthingandroid/service/RestApi.java | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/EventProcessor.java b/app/src/main/java/com/nutomic/syncthingandroid/service/EventProcessor.java index 69195cf6..550de46a 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/EventProcessor.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/EventProcessor.java @@ -94,6 +94,12 @@ public class EventProcessor implements SyncthingService.OnWebGuiAvailableListene @Override public void onEvent(Event event) { switch (event.type) { + case "ConfigSaved": + if (mApi != null) { + Log.v(TAG, "Forwarding ConfigSaved event to RestApi to get the updated config."); + mApi.reloadConfig(); + } + break; case "DeviceRejected": String deviceId = (String) event.data.get("device"); Log.d(TAG, "Unknwon device " + deviceId + " wants to connect"); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java b/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java index a814e3ca..35ede351 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java @@ -156,6 +156,16 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener { }); } + public void reloadConfig() { + new GetRequest(mContext, mUrl, GetRequest.URI_CONFIG, mApiKey, null, result -> { + Log.v(TAG, "reloadConfig: " + result); + mConfig = new Gson().fromJson(result, Config.class); + if (mConfig == null) { + throw new RuntimeException("config is null: " + result); + } + }); + } + /** * Increments mAvailableCount by one, and, if it reached TOTAL_STARTUP_CALLS, * calls {@link SyncthingService#onApiChange}.