mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
auto-save improvement
This commit is contained in:
@@ -42,6 +42,7 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
|||||||
public static final String CONTINUOUS_CREATION_KEY = "continuousCreation";
|
public static final String CONTINUOUS_CREATION_KEY = "continuousCreation";
|
||||||
public static final String AUTO_EDIT_KEY = "autoEdit";
|
public static final String AUTO_EDIT_KEY = "autoEdit";
|
||||||
public static final String ABNORMAL_EXIT_KEY = "abnormalExit";
|
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 WHEEL_ZOOM_KEY = "wheelZoom";
|
||||||
public static final String OUTLINE_KEY = "outline";
|
public static final String OUTLINE_KEY = "outline";
|
||||||
public static final String THEME_KEY = "theme";
|
public static final String THEME_KEY = "theme";
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
for (Class<?> clazz : classes) {
|
for (Class<?> clazz : classes) {
|
||||||
if (IAutoCreator.class.isAssignableFrom(clazz)) {
|
if (IAutoCreator.class.isAssignableFrom(clazz)) {
|
||||||
autoCreators.add((IAutoCreator) clazz.newInstance());
|
autoCreators.add((IAutoCreator) clazz.newInstance());
|
||||||
LOG.debug("Loaded auto-cretor: " + clazz.getName());
|
LOG.debug("Loaded auto-creator: " + clazz.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.diylc.swing.plugins.autosave;
|
package org.diylc.swing.plugins.autosave;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@@ -41,9 +42,12 @@ public class AutoSavePlugin implements IPlugIn {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean wasAbnormal = ConfigurationManager.getInstance().readBoolean(IPlugInPort.ABNORMAL_EXIT_KEY, false);
|
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);
|
File autoSaved = new File(AUTO_SAVE_FILE_NAME);
|
||||||
if (autoSaved.exists())
|
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());
|
IPlugInPort testPresenter = new Presenter(new DummyView());
|
||||||
testPresenter.loadProjectFromFile(AUTO_SAVE_FILE_NAME);
|
testPresenter.loadProjectFromFile(AUTO_SAVE_FILE_NAME);
|
||||||
// Only prompt if there is something saved in the
|
// Only prompt if there is something saved in the
|
||||||
@@ -51,7 +55,7 @@ public class AutoSavePlugin implements IPlugIn {
|
|||||||
if (!testPresenter.getCurrentProject().getComponents().isEmpty()) {
|
if (!testPresenter.getCurrentProject().getComponents().isEmpty()) {
|
||||||
int decision =
|
int decision =
|
||||||
view.showConfirmDialog(
|
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);
|
"Auto-Save", IView.YES_NO_OPTION, IView.QUESTION_MESSAGE);
|
||||||
if (decision == IView.YES_OPTION) {
|
if (decision == IView.YES_OPTION) {
|
||||||
AutoSavePlugin.this.plugInPort.loadProjectFromFile(AUTO_SAVE_FILE_NAME);
|
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);
|
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
|
@Override
|
||||||
|
|||||||
@@ -1822,6 +1822,10 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<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>
|
<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>
|
||||||
|
<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>
|
</changes>
|
||||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||||
</org.diylc.appframework.update.Version>
|
</org.diylc.appframework.update.Version>
|
||||||
|
|||||||
Reference in New Issue
Block a user