- Some tweaks to the play again button handling

- Removed the very naughty interrupt swallowing used to detect if the process started correctly
under optimal arguments, replaced it with a busy-wait loop so the thread can still be used to
launch the application multiple times
This commit is contained in:
Mark Johnson
2012-03-30 03:33:51 +00:00
parent ba86664122
commit 73d5bcb605
@@ -27,6 +27,7 @@ package com.threerings.getdown.launcher;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Container; import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.awt.Image; import java.awt.Image;
@@ -775,21 +776,17 @@ public abstract class Getdown extends Thread
// if we have "optimum" arguments, we want to try launching with them first // if we have "optimum" arguments, we want to try launching with them first
proc = _app.createProcess(true); proc = _app.createProcess(true);
// wait a short amount of time for the process to exit; if it doesn't (or it long fallback = System.currentTimeMillis() + FALLBACK_CHECK_TIME;
// exits with a success code), assume everything's good boolean error = false;
Timer timer = new Timer("fallbackCheck", true); while (fallback > System.currentTimeMillis()) {
timer.schedule(new TimerTask() { try {
@Override public void run () { error = proc.exitValue() != 0;
interrupt(); break;
} catch (IllegalThreadStateException e) {
Thread.yield();
} }
}, FALLBACK_CHECK_TIME);
boolean error;
try {
error = (proc.waitFor() != 0);
} catch (InterruptedException e) {
error = false;
} }
timer.cancel();
if (error) { if (error) {
log.info("Failed to launch with optimum arguments; falling back."); log.info("Failed to launch with optimum arguments; falling back.");
proc = _app.createProcess(false); proc = _app.createProcess(false);
@@ -840,8 +837,14 @@ public abstract class Getdown extends Thread
// pump the percent up to 100% // pump the percent up to 100%
setStatus(null, 100, -1L, false); setStatus(null, 100, -1L, false);
exit(0); exit(0);
if (_playAgain != null) { if (_playAgain != null && _playAgain.isEnabled()) {
_playAgain.setVisible(true); // wait a little time before showing the button
Timer timer = new Timer("playAgain", true);
timer.schedule(new TimerTask() {
@Override public void run () {
_playAgain.setVisible(true);
}
}, PLAY_AGAIN_TIME);
} }
} catch (Exception e) { } catch (Exception e) {
@@ -876,18 +879,20 @@ public abstract class Getdown extends Thread
_patchNotes.setFont(StatusPanel.FONT); _patchNotes.setFont(StatusPanel.FONT);
_layers.add(_patchNotes); _layers.add(_patchNotes);
if (getApplet() != null && _ifc.playAgain != null) { if (getApplet() != null) {
Image image = loadImage(_ifc.playAgainImage); _playAgain = new JButton();
if (image != null) { _playAgain.setEnabled(false);
_playAgain = new JButton(new ImageIcon(image)); _playAgain.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
_playAgain.setBorderPainted(false); _playAgain.setFont(StatusPanel.FONT);
} else {
_playAgain = new JButton(_msgs.getString("m.play_again"));
}
_playAgain.addActionListener(new ActionListener() { _playAgain.addActionListener(new ActionListener() {
@Override public void actionPerformed (ActionEvent event) { @Override public void actionPerformed (ActionEvent event) {
getdown();
_playAgain.setVisible(false); _playAgain.setVisible(false);
_stepMinPercent = _lastGlobalPercent = 0;
EventQueue.invokeLater(new Runnable() {
public void run () {
getdown();
}
});
} }
}); });
_layers.add(_playAgain); _layers.add(_playAgain);
@@ -924,7 +929,22 @@ public abstract class Getdown extends Thread
_patchNotes.setVisible(false); _patchNotes.setVisible(false);
if (_playAgain != null) { if (_playAgain != null) {
_playAgain.setBounds(_ifc.playAgain); Image image = loadImage(_ifc.playAgainImage);
boolean hasImage = image != null;
if (hasImage) {
_playAgain.setIcon(new ImageIcon(image));
_playAgain.setText("");
} else {
_playAgain.setText(_msgs.getString("m.play_again"));
_playAgain.setIcon(null);
}
_playAgain.setBorderPainted(!hasImage);
_playAgain.setOpaque(!hasImage);
_playAgain.setContentAreaFilled(!hasImage);
if (_ifc.playAgain != null) {
_playAgain.setBounds(_ifc.playAgain);
_playAgain.setEnabled(true);
}
_playAgain.setVisible(false); _playAgain.setVisible(false);
} }
@@ -1206,6 +1226,7 @@ public abstract class Getdown extends Thread
protected static final int MAX_LOOPS = 5; protected static final int MAX_LOOPS = 5;
protected static final long MIN_EXIST_TIME = 5000L; protected static final long MIN_EXIST_TIME = 5000L;
protected static final long FALLBACK_CHECK_TIME = 1000L; protected static final long FALLBACK_CHECK_TIME = 1000L;
protected static final long PLAY_AGAIN_TIME = 3000L;
protected static final String PROXY_REGISTRY = protected static final String PROXY_REGISTRY =
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"; "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
} }