mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-23 04:41:16 +00:00
Don't restart before config has been updated (fixes #398).
This commit is contained in:
parent
7117933b6d
commit
af5ba5c0d9
3 changed files with 21 additions and 19 deletions
|
@ -27,15 +27,13 @@ public class RestartActivity extends SyncthingActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final Intent intent = new Intent(this, SyncthingService.class)
|
||||
.setAction(SyncthingService.ACTION_RESTART);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(R.string.restart_title)
|
||||
.setPositiveButton(R.string.restart_now, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
startService(intent);
|
||||
getService().getApi().updateConfig();
|
||||
finish();
|
||||
}
|
||||
})
|
||||
|
|
|
@ -385,7 +385,7 @@ public class SettingsFragment extends PreferenceFragment
|
|||
Toast.makeText(getActivity(),
|
||||
getString(R.string.config_imported_successful),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
mSyncthingService.getApi().requireRestart(getActivity(), false);
|
||||
mSyncthingService.getApi().requireRestart(getActivity());
|
||||
} else {
|
||||
Toast.makeText(getActivity(),
|
||||
getString(R.string.config_import_failed,
|
||||
|
|
|
@ -341,28 +341,32 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
|||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Either shows a restart dialog, or only updates the config, depending on
|
||||
* {@link #mRestartPostponed}.
|
||||
*/
|
||||
public void requireRestart(Activity activity) {
|
||||
requireRestart(activity, true);
|
||||
if (mRestartPostponed) {
|
||||
new PostConfigTask(mHttpsCertPath).execute(mUrl, mApiKey, mConfig.toString());
|
||||
} else {
|
||||
activity.startActivity(new Intent(mContext, RestartActivity.class));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the updated mConfig via Rest API to syncthing and displays a "restart"
|
||||
* dialog or notification.
|
||||
* Sends the current config to Syncthing and restarts it.
|
||||
*
|
||||
* @param activity The calling activity.
|
||||
* @param updateConfig If true, {@link #mConfig} will be sent to `/rest/system/config`.
|
||||
* This executes a restart immediately, and does not show a dialog.
|
||||
*/
|
||||
public void requireRestart(Activity activity, boolean updateConfig) {
|
||||
if (updateConfig) {
|
||||
new PostConfigTask(mHttpsCertPath)
|
||||
.execute(mUrl, mApiKey, mConfig.toString());
|
||||
public void updateConfig() {
|
||||
new PostConfigTask(mHttpsCertPath) {
|
||||
@Override
|
||||
protected void onPostExecute(Boolean aBoolean) {
|
||||
mContext.startService(new Intent(mContext, SyncthingService.class)
|
||||
.setAction(SyncthingService.ACTION_RESTART));
|
||||
}
|
||||
// TODO Should wait until PostConfigTask is completed, see #398
|
||||
}.execute(mUrl, mApiKey, mConfig.toString());
|
||||
|
||||
if (mRestartPostponed)
|
||||
return;
|
||||
|
||||
activity.startActivity(new Intent(mContext, RestartActivity.class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue