mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-22 12:21:15 +00:00
Fixed crash on first start after install.
This commit is contained in:
parent
d6025a5e6b
commit
ce7773bac7
1 changed files with 79 additions and 81 deletions
|
@ -106,17 +106,11 @@ public class SyncthingService extends Service {
|
|||
return super.getMessage() + "\n" + mLog;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Runs the syncthing binary from command line, and prints its output to logcat.
|
||||
*/
|
||||
private class NativeSyncthingRunnable implements Runnable {
|
||||
@Override
|
||||
public void run() throws NativeExecutionException {
|
||||
if (isFirstStart(SyncthingService.this)) {
|
||||
copyDefaultConfig();
|
||||
}
|
||||
updateConfig();
|
||||
|
||||
/**
|
||||
* Runs the syncthing binary from command line, and prints its output to logcat (on exit).
|
||||
*/
|
||||
private void runNative() {
|
||||
DataOutputStream dos = null;
|
||||
InputStreamReader isr = null;
|
||||
int ret = 1;
|
||||
|
@ -172,7 +166,6 @@ public class SyncthingService extends Service {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Polls SYNCTHING_URL until it returns HTTP status OK, then calls all listeners
|
||||
|
@ -232,6 +225,14 @@ public class SyncthingService extends Service {
|
|||
n.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
startForeground(NOTIFICATION_ID, n);
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isFirstStart(SyncthingService.this)) {
|
||||
copyDefaultConfig();
|
||||
}
|
||||
updateConfig();
|
||||
|
||||
String syncthingUrl = null;
|
||||
try {
|
||||
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
|
@ -239,23 +240,20 @@ public class SyncthingService extends Service {
|
|||
Element options = (Element)
|
||||
d.getDocumentElement().getElementsByTagName("gui").item(0);
|
||||
syncthingUrl = options.getElementsByTagName("address").item(0).getTextContent();
|
||||
}
|
||||
catch (SAXException e) {
|
||||
} catch (SAXException e) {
|
||||
throw new RuntimeException("Failed to read gui url, aborting", e);
|
||||
}
|
||||
catch (ParserConfigurationException e) {
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new RuntimeException("Failed to read gui url, aborting", e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read gui url, aborting", e);
|
||||
}
|
||||
finally {
|
||||
mApi = new RestApi(this, "http://" + syncthingUrl);
|
||||
} finally {
|
||||
mApi = new RestApi(SyncthingService.this, "http://" + syncthingUrl);
|
||||
registerOnWebGuiAvailableListener(mApi);
|
||||
}
|
||||
|
||||
new Thread(new NativeSyncthingRunnable()).start();
|
||||
new PollWebGuiAvailableTask().execute();
|
||||
runNative();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -347,7 +345,7 @@ public class SyncthingService extends Service {
|
|||
Log.w(TAG, "Failed to parse config", e);
|
||||
}
|
||||
catch (TransformerException e) {
|
||||
Log.d(TAG, "Failed to save updated config", e);
|
||||
Log.w(TAG, "Failed to save updated config", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue