mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 06:11:19 +00:00
* ConfigXml: Add updateGui * ConfigRouter: Add getGui, updateGui * ConfigXml: "apiKey" => "apikey" * RestApi: Add updateGui
This commit is contained in:
parent
4f461dce8a
commit
6e83b7c66d
3 changed files with 54 additions and 1 deletions
|
@ -596,6 +596,13 @@ public class RestApi {
|
|||
}
|
||||
}
|
||||
|
||||
public void updateGui(Gui newGui) {
|
||||
synchronized (mConfigLock) {
|
||||
mConfig.gui = newGui;
|
||||
sendConfig();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a deep copy of object.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue