Feature: improve the application exit-button process (#214)
* Improve the application exit-button behaviour
This commit is contained in:
2
.idea/gradle.xml
generated
2
.idea/gradle.xml
generated
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
@@ -11,7 +12,6 @@
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="useAutoImport" value="true" />
|
||||
<option name="useQualifiedModuleNames" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
|
||||
@@ -135,6 +135,7 @@ public class Client {
|
||||
Thread thread_sender = new Thread(runnable_sender);
|
||||
thread_sender.start();
|
||||
|
||||
do {
|
||||
while (this.running == true) {
|
||||
this.renderingJob = null;
|
||||
synchronized (this) {
|
||||
@@ -155,7 +156,7 @@ public class Client {
|
||||
long wait = next_request.getTimeInMillis() - now.getTime();
|
||||
if (wait < 0) {
|
||||
// it means the client has to wait until the next day
|
||||
wait += 24*3600*1000;
|
||||
wait += 24 * 3600 * 1000;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(wait);
|
||||
@@ -368,14 +369,20 @@ public class Client {
|
||||
this.log.removeCheckPoint(step);
|
||||
}
|
||||
|
||||
// not running but maybe still sending frame
|
||||
while (this.jobsToValidate.isEmpty() == false) {
|
||||
// If we reach this point is bc the main loop (the one that controls all the workflow) has exited
|
||||
// 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 {
|
||||
Thread.sleep(2300); // wait a little bit
|
||||
this.gui.status("Uploading rendered frames before exiting. Please wait");
|
||||
}
|
||||
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) {
|
||||
// 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)
|
||||
*/
|
||||
public Calendar nextJobRequest() {
|
||||
@@ -615,7 +621,8 @@ public class Client {
|
||||
}
|
||||
|
||||
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
|
||||
// and it's the only file we are sure will not be needed anymore
|
||||
scene_file.delete();
|
||||
|
||||
@@ -39,6 +39,7 @@ import javax.swing.BoxLayout;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.Spring;
|
||||
@@ -230,7 +231,7 @@ public class Working implements Activity {
|
||||
JButton blockJob = new JButton("Block this project");
|
||||
blockJob.addActionListener(new blockJobAction());
|
||||
|
||||
exitAfterFrame = new JButton("Exit after this frame");
|
||||
exitAfterFrame = new JButton("Exit");
|
||||
exitAfterFrame.addActionListener(new ExitAfterAction());
|
||||
|
||||
buttonsPanel.add(settingsButton);
|
||||
@@ -315,6 +316,22 @@ public class Working implements Activity {
|
||||
(queueSize > 0 ? String.format(" (%.2fMB) ", (queueVolume / 1024.0 / 1024.0)) : ""),
|
||||
(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() {
|
||||
@@ -475,11 +492,39 @@ public class Working implements Activity {
|
||||
Client client = parent.getClient();
|
||||
if (client != null) {
|
||||
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();
|
||||
}
|
||||
else if (userDecision == 1) {
|
||||
client.stop();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
exitAfterFrame.setText("Exit after this frame");
|
||||
exitAfterFrame.setText("Exit");
|
||||
client.cancelStop();
|
||||
}
|
||||
}
|
||||
@@ -498,5 +543,4 @@ public class Working implements Activity {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user