Feature: improve the application exit-button process (#214)

* Improve the application exit-button behaviour
This commit is contained in:
Luis Uguina
2020-04-27 22:28:04 +10:00
committed by GitHub
parent aae5ec3254
commit d6984fa450
3 changed files with 277 additions and 226 deletions

2
.idea/gradle.xml generated
View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
@@ -11,7 +12,6 @@
</set> </set>
</option> </option>
<option name="resolveModulePerSourceSet" value="false" /> <option name="resolveModulePerSourceSet" value="false" />
<option name="useAutoImport" value="true" />
<option name="useQualifiedModuleNames" value="true" /> <option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings> </GradleProjectSettings>
</option> </option>

View File

@@ -135,6 +135,7 @@ public class Client {
Thread thread_sender = new Thread(runnable_sender); Thread thread_sender = new Thread(runnable_sender);
thread_sender.start(); thread_sender.start();
do {
while (this.running == true) { while (this.running == true) {
this.renderingJob = null; this.renderingJob = null;
synchronized (this) { synchronized (this) {
@@ -155,7 +156,7 @@ public class Client {
long wait = next_request.getTimeInMillis() - now.getTime(); long wait = next_request.getTimeInMillis() - now.getTime();
if (wait < 0) { if (wait < 0) {
// it means the client has to wait until the next day // it means the client has to wait until the next day
wait += 24*3600*1000; wait += 24 * 3600 * 1000;
} }
try { try {
Thread.sleep(wait); Thread.sleep(wait);
@@ -368,14 +369,20 @@ public class Client {
this.log.removeCheckPoint(step); this.log.removeCheckPoint(step);
} }
// not running but maybe still sending frame // If we reach this point is bc the main loop (the one that controls all the workflow) has exited
while (this.jobsToValidate.isEmpty() == false) { // due to user requesting to exit the App and we are just waiting for the upload queue to empty
// If the user cancels the exit, then this.running will be true and the main loop will take
// control again
try { try {
Thread.sleep(2300); // wait a little bit Thread.sleep(2300); // wait a little bit
this.gui.status("Uploading rendered frames before exiting. Please wait");
} }
catch (InterruptedException e3) { catch (InterruptedException e3) {
} }
}
// This loop will remain valid until all the background uploads have
// finished (unless the stop() method has been triggered)
} while (this.uploadQueueSize > 0);
} }
catch (Exception e1) { catch (Exception e1) {
// no exception should be raised in the actual launcher (applet or standalone) // no exception should be raised in the actual launcher (applet or standalone)
@@ -532,7 +539,6 @@ public class Client {
} }
/** /**
*
* @return the date of the next request, or null if there is not delay (null <=> now) * @return the date of the next request, or null if there is not delay (null <=> now)
*/ */
public Calendar nextJobRequest() { public Calendar nextJobRequest() {
@@ -615,7 +621,8 @@ public class Client {
} }
Observer removeSceneDirectoryOnceRenderHasStartedObserver = new Observer() { Observer removeSceneDirectoryOnceRenderHasStartedObserver = new Observer() {
@Override public void update(Observable observable, Object o) { @Override
public void update(Observable observable, Object o) {
// only remove the .blend since it's most important data // only remove the .blend since it's most important data
// and it's the only file we are sure will not be needed anymore // and it's the only file we are sure will not be needed anymore
scene_file.delete(); scene_file.delete();

View File

@@ -39,6 +39,7 @@ import javax.swing.BoxLayout;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.Spring; import javax.swing.Spring;
@@ -230,7 +231,7 @@ public class Working implements Activity {
JButton blockJob = new JButton("Block this project"); JButton blockJob = new JButton("Block this project");
blockJob.addActionListener(new blockJobAction()); blockJob.addActionListener(new blockJobAction());
exitAfterFrame = new JButton("Exit after this frame"); exitAfterFrame = new JButton("Exit");
exitAfterFrame.addActionListener(new ExitAfterAction()); exitAfterFrame.addActionListener(new ExitAfterAction());
buttonsPanel.add(settingsButton); buttonsPanel.add(settingsButton);
@@ -315,6 +316,22 @@ public class Working implements Activity {
(queueSize > 0 ? String.format(" (%.2fMB) ", (queueVolume / 1024.0 / 1024.0)) : ""), (queueSize > 0 ? String.format(" (%.2fMB) ", (queueVolume / 1024.0 / 1024.0)) : ""),
(queueSize == this.parent.getConfiguration().getMaxUploadingJob() ? "- Queue full!" : "") (queueSize == this.parent.getConfiguration().getMaxUploadingJob() ? "- Queue full!" : "")
)); ));
// If the user has requested to exit, then we need to update the JButton with the queue size
if (this.exitAfterFrame.getText().startsWith("Cancel")) {
Client client = parent.getClient();
if (client != null) {
if (client.isRunning()) {
queueSize++;
}
}
exitAfterFrame.setText(String.format("Cancel exit (%s frame%s to go)",
queueSize,
(queueSize > 1 ? "s" : ""))
);
}
} }
public void updateTime() { public void updateTime() {
@@ -475,11 +492,39 @@ public class Working implements Activity {
Client client = parent.getClient(); Client client = parent.getClient();
if (client != null) { if (client != null) {
if (client.isRunning()) { if (client.isRunning()) {
exitAfterFrame.setText("Cancel exit"); String[] exitJobOptions = {"Exit after current Jobs", "Exit Immediately", "Do Nothing"};
int jobsQueueSize = client.getUploadQueueSize() + (client.isRunning() ? 1 : 0);
int userDecision = JOptionPane.showOptionDialog(
null,
String.format("<html>You have <strong>%d frame%s</strong> being uploaded or rendered. Do you want to finish the jobs or exit now?.\n\n",
jobsQueueSize , // Add the current frame to the total count ONLY if the client is running
(jobsQueueSize > 1 ? "s" : ""),
(jobsQueueSize > 1 ? (jobsQueueSize + " ") : ""),
(jobsQueueSize > 1 ? "s" : "")
),
"Exit Now or Later",
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
exitJobOptions,
exitJobOptions[2]); // Make the "Do nothing" button the default one to avoid mistakes
if (userDecision == 0) {
exitAfterFrame.setText(String.format("Cancel exit (%s frame%s to go)",
jobsQueueSize,
(jobsQueueSize > 1 ? "s" : ""))
);
client.askForStop(); client.askForStop();
} }
else if (userDecision == 1) {
client.stop();
System.exit(0);
}
}
else { else {
exitAfterFrame.setText("Exit after this frame"); exitAfterFrame.setText("Exit");
client.cancelStop(); client.cancelStop();
} }
} }
@@ -498,5 +543,4 @@ public class Working implements Activity {
} }
} }
} }
} }