Skip to content
Snippets Groups Projects
Commit 78e0d9d9 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#172 - do not pre-calculate next save time since the user may change the autosave interval:

Otherwise, if the user switches from a high interval to a small one, the next save is performed after the high interval has passed and therefore too late.
parent 2a078bb1
No related branches found
No related tags found
No related merge requests found
...@@ -815,25 +815,26 @@ public class MainViewController extends NVC implements IMainViewController, Noti ...@@ -815,25 +815,26 @@ public class MainViewController extends NVC implements IMainViewController, Noti
@SuppressWarnings("java:S2189") @SuppressWarnings("java:S2189")
private void autosave() { private void autosave() {
long autosaveDurationInMilliseconds = PlayPadPlugin.getInstance().getGlobalSettings().getAutosaveIntervalInMinutes() * 60 * 1000L; long lastSaveTime = System.currentTimeMillis();
long nextSaveTime = System.currentTimeMillis() + autosaveDurationInMilliseconds;
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//noinspection InfiniteLoopStatement //noinspection InfiniteLoopStatement
while(true) while(true)
{ {
final long currentMillis = System.currentTimeMillis(); final long currentMillis = System.currentTimeMillis();
if(currentMillis > nextSaveTime)
// autosave interval may be changed by user in global settings, therefore the current setting needs to be fetched every time
if(currentMillis > lastSaveTime + getAutosaveIntervalInMillis())
{ {
// autosave interval may be changed by user in global settings, therefore get the current setting again lastSaveTime = currentMillis;
autosaveDurationInMilliseconds = PlayPadPlugin.getInstance().getGlobalSettings().getAutosaveIntervalInMinutes() * 60 * 1000L;
nextSaveTime = currentMillis + autosaveDurationInMilliseconds;
if(PlayPadPlugin.getInstance().getGlobalSettings().isEnableAutosave()) if(PlayPadPlugin.getInstance().getGlobalSettings().isEnableAutosave())
{ {
Logger.debug("Performing autosave..."); Logger.debug("Performing autosave...");
save(); save();
Logger.debug("Autosave done. Next autosave: " + dateFormat.format(new Date(nextSaveTime)));
long nextSaveTime = currentMillis + getAutosaveIntervalInMillis();
Logger.debug("Autosave done. Next predicted autosave: " + dateFormat.format(new Date(nextSaveTime)));
} }
} }
...@@ -849,4 +850,8 @@ public class MainViewController extends NVC implements IMainViewController, Noti ...@@ -849,4 +850,8 @@ public class MainViewController extends NVC implements IMainViewController, Noti
} }
} }
} }
private long getAutosaveIntervalInMillis() {
return PlayPadPlugin.getInstance().getGlobalSettings().getAutosaveIntervalInMinutes() * 60 * 1000L;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment