auto-save improvement

This commit is contained in:
bancika
2017-05-10 16:12:46 +02:00
parent d1a7227f4c
commit 0e04d168e7
4 changed files with 24 additions and 3 deletions
@@ -42,6 +42,7 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
public static final String CONTINUOUS_CREATION_KEY = "continuousCreation";
public static final String AUTO_EDIT_KEY = "autoEdit";
public static final String ABNORMAL_EXIT_KEY = "abnormalExit";
public static final String HEARTBEAT = "heartbeat";
public static final String WHEEL_ZOOM_KEY = "wheelZoom";
public static final String OUTLINE_KEY = "outline";
public static final String THEME_KEY = "theme";
@@ -366,7 +366,7 @@ public class Presenter implements IPlugInPort {
for (Class<?> clazz : classes) {
if (IAutoCreator.class.isAssignableFrom(clazz)) {
autoCreators.add((IAutoCreator) clazz.newInstance());
LOG.debug("Loaded auto-cretor: " + clazz.getName());
LOG.debug("Loaded auto-creator: " + clazz.getName());
}
}
} catch (Exception e) {
@@ -1,6 +1,7 @@
package org.diylc.swing.plugins.autosave;
import java.io.File;
import java.util.Date;
import java.util.EnumSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -41,9 +42,12 @@ public class AutoSavePlugin implements IPlugIn {
@Override
public void run() {
boolean wasAbnormal = ConfigurationManager.getInstance().readBoolean(IPlugInPort.ABNORMAL_EXIT_KEY, false);
Date lastHeartbeat = (Date) ConfigurationManager.getInstance().readObject(IPlugInPort.HEARTBEAT, new Date());
long msSinceHeartbeat = new Date().getTime() - lastHeartbeat.getTime();
File autoSaved = new File(AUTO_SAVE_FILE_NAME);
if (autoSaved.exists())
if (wasAbnormal) {
// try to figure out if another instance is running. Only pull auto-saved file if there's no recent heartbeat
if (wasAbnormal && msSinceHeartbeat > autoSaveFrequency) {
IPlugInPort testPresenter = new Presenter(new DummyView());
testPresenter.loadProjectFromFile(AUTO_SAVE_FILE_NAME);
// Only prompt if there is something saved in the
@@ -51,7 +55,7 @@ public class AutoSavePlugin implements IPlugIn {
if (!testPresenter.getCurrentProject().getComponents().isEmpty()) {
int decision =
view.showConfirmDialog(
"It appears that aplication was not closed normally in the previous session. Do you want to open the last auto-saved file?",
"It appears that application was not closed normally in the previous session. Do you want to open the last auto-saved file?",
"Auto-Save", IView.YES_NO_OPTION, IView.QUESTION_MESSAGE);
if (decision == IView.YES_OPTION) {
AutoSavePlugin.this.plugInPort.loadProjectFromFile(AUTO_SAVE_FILE_NAME);
@@ -64,6 +68,18 @@ public class AutoSavePlugin implements IPlugIn {
ConfigurationManager.getInstance().writeValue(IPlugInPort.ABNORMAL_EXIT_KEY, true);
}
});
// write heartbeat periodically
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(autoSaveFrequency);
} catch (InterruptedException e) {
}
ConfigurationManager.getInstance().writeValue(IPlugInPort.HEARTBEAT, new Date());
}
}).start();
}
@Override
+4
View File
@@ -1822,6 +1822,10 @@
<changeType>NEW_FEATURE</changeType>
<description>Using right click to draw a selection rectangle doesn't move objects under the cursor (useful for selecting multiple components that have a big board below)</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Auto-save dialog pops up when running multiple instances of the app at the same time</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>