1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 22:31:16 +00:00

Don't restart before config has been updated (fixes #398).

This commit is contained in:
Felix Ableitner 2016-02-09 22:06:02 +01:00
parent 7117933b6d
commit af5ba5c0d9
3 changed files with 21 additions and 19 deletions

View file

@ -27,15 +27,13 @@ public class RestartActivity extends SyncthingActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final Intent intent = new Intent(this, SyncthingService.class)
.setAction(SyncthingService.ACTION_RESTART);
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.restart_title) builder.setMessage(R.string.restart_title)
.setPositiveButton(R.string.restart_now, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.restart_now, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
startService(intent); getService().getApi().updateConfig();
finish(); finish();
} }
}) })

View file

@ -385,7 +385,7 @@ public class SettingsFragment extends PreferenceFragment
Toast.makeText(getActivity(), Toast.makeText(getActivity(),
getString(R.string.config_imported_successful), getString(R.string.config_imported_successful),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
mSyncthingService.getApi().requireRestart(getActivity(), false); mSyncthingService.getApi().requireRestart(getActivity());
} else { } else {
Toast.makeText(getActivity(), Toast.makeText(getActivity(),
getString(R.string.config_import_failed, getString(R.string.config_import_failed,

View file

@ -341,28 +341,32 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
return json; return json;
} }
/**
* Either shows a restart dialog, or only updates the config, depending on
* {@link #mRestartPostponed}.
*/
public void requireRestart(Activity activity) { 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" * Sends the current config to Syncthing and restarts it.
* dialog or notification.
* *
* @param activity The calling activity. * This executes a restart immediately, and does not show a dialog.
* @param updateConfig If true, {@link #mConfig} will be sent to `/rest/system/config`.
*/ */
public void requireRestart(Activity activity, boolean updateConfig) { public void updateConfig() {
if (updateConfig) { new PostConfigTask(mHttpsCertPath) {
new PostConfigTask(mHttpsCertPath) @Override
.execute(mUrl, mApiKey, mConfig.toString()); protected void onPostExecute(Boolean aBoolean) {
} mContext.startService(new Intent(mContext, SyncthingService.class)
// TODO Should wait until PostConfigTask is completed, see #398 .setAction(SyncthingService.ACTION_RESTART));
}
}.execute(mUrl, mApiKey, mConfig.toString());
if (mRestartPostponed)
return;
activity.startActivity(new Intent(mContext, RestartActivity.class));
} }
/** /**