mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-22 12:21:15 +00:00
Create default config on first start.
This commit is contained in:
parent
83dc3a6c65
commit
5e3f097aa4
2 changed files with 62 additions and 3 deletions
18
res/raw/config_default.xml
Normal file
18
res/raw/config_default.xml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<configuration version="2">
|
||||||
|
<gui enabled="true">
|
||||||
|
<address>127.0.0.1:8080</address>
|
||||||
|
</gui>
|
||||||
|
<options>
|
||||||
|
<listenAddress>:22000</listenAddress>
|
||||||
|
<globalAnnounceServer>announce.syncthing.net:22025</globalAnnounceServer>
|
||||||
|
<globalAnnounceEnabled>true</globalAnnounceEnabled>
|
||||||
|
<localAnnounceEnabled>true</localAnnounceEnabled>
|
||||||
|
<parallelRequests>16</parallelRequests>
|
||||||
|
<maxSendKbps>0</maxSendKbps>
|
||||||
|
<rescanIntervalS>60</rescanIntervalS>
|
||||||
|
<reconnectionIntervalS>60</reconnectionIntervalS>
|
||||||
|
<maxChangeKbps>1000</maxChangeKbps>
|
||||||
|
<startBrowser>false</startBrowser>
|
||||||
|
<upnpEnabled>true</upnpEnabled>
|
||||||
|
</options>
|
||||||
|
</configuration>
|
|
@ -5,6 +5,7 @@ import android.app.AlertDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -14,6 +15,9 @@ import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class WebGuiActivity extends Activity {
|
public class WebGuiActivity extends Activity {
|
||||||
|
|
||||||
|
@ -21,8 +25,6 @@ public class WebGuiActivity extends Activity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL of the local syncthing web UI.
|
* URL of the local syncthing web UI.
|
||||||
*
|
|
||||||
* TODO: read this out from native code.
|
|
||||||
*/
|
*/
|
||||||
private static final String SYNCTHING_URL = "http://127.0.0.1:8080";
|
private static final String SYNCTHING_URL = "http://127.0.0.1:8080";
|
||||||
|
|
||||||
|
@ -38,6 +40,11 @@ public class WebGuiActivity extends Activity {
|
||||||
*/
|
*/
|
||||||
private static final String CERT_FILE = "cert.pem";
|
private static final String CERT_FILE = "cert.pem";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File in the config folder that contains configuration.
|
||||||
|
*/
|
||||||
|
private static final String CONFIG_FILE = "config.xml";
|
||||||
|
|
||||||
private WebView mWebView;
|
private WebView mWebView;
|
||||||
private View mLoadingView;
|
private View mLoadingView;
|
||||||
|
|
||||||
|
@ -87,8 +94,10 @@ public class WebGuiActivity extends Activity {
|
||||||
mWebView.setWebViewClient(mWebViewClient);
|
mWebView.setWebViewClient(mWebViewClient);
|
||||||
mWebView.loadUrl(SYNCTHING_URL);
|
mWebView.loadUrl(SYNCTHING_URL);
|
||||||
|
|
||||||
|
// Handle first start.
|
||||||
if (!new File(CONFIG_FOLDER, CERT_FILE).exists()) {
|
if (!new File(CONFIG_FOLDER, CERT_FILE).exists()) {
|
||||||
// First start.
|
copyDefaultConfig();
|
||||||
|
|
||||||
TextView loadingText = (TextView) mLoadingView.findViewById(R.id.loading_text);
|
TextView loadingText = (TextView) mLoadingView.findViewById(R.id.loading_text);
|
||||||
loadingText.setText(R.string.web_gui_creating_key);
|
loadingText.setText(R.string.web_gui_creating_key);
|
||||||
new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
|
@ -119,5 +128,37 @@ public class WebGuiActivity extends Activity {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the default config file from res/raw/config_default.xml to CONFIG_FOLDER/CONFIG_FILE.
|
||||||
|
*/
|
||||||
|
private void copyDefaultConfig() {
|
||||||
|
File config = new File(CONFIG_FOLDER, CONFIG_FILE);
|
||||||
|
InputStream in = null;
|
||||||
|
FileOutputStream out = null;
|
||||||
|
try {
|
||||||
|
in = getResources().openRawResource(R.raw.config_default);
|
||||||
|
out = new FileOutputStream(config);
|
||||||
|
byte[] buff = new byte[1024];
|
||||||
|
int read = 0;
|
||||||
|
|
||||||
|
while ((read = in.read(buff)) > 0) {
|
||||||
|
out.write(buff, 0, read);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
Log.w(TAG, "Failed to write config file", e);
|
||||||
|
config.delete();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
Log.w(TAG, "Failed to close stream while copying config", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue