1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-29 15:51:17 +00:00

Add ConfigRouter#getGui, updateGui (fixes #403) (#402)

* ConfigXml: Add updateGui

* ConfigRouter: Add getGui, updateGui

* ConfigXml: "apiKey" => "apikey"

* RestApi: Add updateGui
This commit is contained in:
Catfriend1 2019-04-14 16:31:46 +02:00 committed by GitHub
parent 4f461dce8a
commit 6e83b7c66d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 1 deletions

View file

@ -596,6 +596,13 @@ public class RestApi {
}
}
public void updateGui(Gui newGui) {
synchronized (mConfigLock) {
mConfig.gui = newGui;
sendConfig();
}
}
/**
* Returns a deep copy of object.
*

View file

@ -6,6 +6,7 @@ import android.content.Context;
import com.nutomic.syncthingandroid.model.Device;
import com.nutomic.syncthingandroid.model.Folder;
import com.nutomic.syncthingandroid.model.FolderIgnoreList;
import com.nutomic.syncthingandroid.model.Gui;
import com.nutomic.syncthingandroid.model.Options;
import com.nutomic.syncthingandroid.service.RestApi;
import com.nutomic.syncthingandroid.util.ConfigXml;
@ -164,6 +165,30 @@ public class ConfigRouter {
restApi.removeDevice(deviceID); // This will send the config afterwards.
}
public Gui getGui(RestApi restApi) {
if (restApi == null || !restApi.isConfigLoaded()) {
// Syncthing is not running or REST API is not (yet) available.
configXml.loadConfig();
return configXml.getGui();
}
// Syncthing is running and REST API is available.
return restApi.getGui();
}
public void updateGui(RestApi restApi, final Gui gui) {
if (restApi == null || !restApi.isConfigLoaded()) {
// Syncthing is not running or REST API is not (yet) available.
configXml.loadConfig();
configXml.updateGui(gui);
configXml.saveChanges();
return;
}
// Syncthing is running and REST API is available.
restApi.updateGui(gui); // This will send the config afterwards.
}
public Options getOptions(RestApi restApi) {
if (restApi == null || !restApi.isConfigLoaded()) {
// Syncthing is not running or REST API is not (yet) available.

View file

@ -838,7 +838,7 @@ public class ConfigXml {
gui.address = getContentOrDefault(elementGui.getElementsByTagName("address").item(0), gui.address);
gui.user = getContentOrDefault(elementGui.getElementsByTagName("user").item(0), gui.user);
gui.password = getContentOrDefault(elementGui.getElementsByTagName("password").item(0), "");
gui.apiKey = getContentOrDefault(elementGui.getElementsByTagName("apiKey").item(0), "");
gui.apiKey = getContentOrDefault(elementGui.getElementsByTagName("apikey").item(0), "");
gui.theme = getContentOrDefault(elementGui.getElementsByTagName("theme").item(0), gui.theme);
gui.insecureAdminAccess = getContentOrDefault(elementGui.getElementsByTagName("insecureAdminAccess").item(0), gui.insecureAdminAccess);
gui.insecureAllowFrameLoading = getContentOrDefault(elementGui.getElementsByTagName("insecureAllowFrameLoading").item(0), gui.insecureAllowFrameLoading);
@ -846,6 +846,27 @@ public class ConfigXml {
return gui;
}
public void updateGui(final Gui gui) {
Element elementGui = (Element) mConfig.getDocumentElement().getElementsByTagName("gui").item(0);
if (elementGui == null) {
Log.e(TAG, "updateGui: elementGui == null");
return;
}
elementGui.setAttribute("debugging", Boolean.toString(gui.debugging));
elementGui.setAttribute("enabled", Boolean.toString(gui.enabled));
elementGui.setAttribute("tls", Boolean.toString(gui.useTLS));
setConfigElement(elementGui, "address", gui.address);
setConfigElement(elementGui, "user", gui.user);
setConfigElement(elementGui, "password", gui.password);
setConfigElement(elementGui, "apikey", gui.apiKey);
setConfigElement(elementGui, "theme", gui.theme);
setConfigElement(elementGui, "insecureAdminAccess", Boolean.toString(gui.insecureAdminAccess));
setConfigElement(elementGui, "insecureAllowFrameLoading", Boolean.toString(gui.insecureAllowFrameLoading));
setConfigElement(elementGui, "insecureSkipHostCheck", Boolean.toString(gui.insecureSkipHostCheck));
}
public Options getOptions() {
Element elementOptions = (Element) mConfig.getDocumentElement().getElementsByTagName("options").item(0);
Options options = new Options();