Prettying the updater UI
Doesn't freeze on "check for updates". Pop-up confirmation dialog.
This commit is contained in:
parent
72cd101d2a
commit
1c2871a389
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
|||||||
<groupId>com.rarchives.ripme</groupId>
|
<groupId>com.rarchives.ripme</groupId>
|
||||||
<artifactId>ripme</artifactId>
|
<artifactId>ripme</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.0.3</version>
|
<version>1.0.4</version>
|
||||||
<name>ripme</name>
|
<name>ripme</name>
|
||||||
<url>http://rip.rarchives.com</url>
|
<url>http://rip.rarchives.com</url>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -19,6 +19,7 @@ import java.net.URL;
|
|||||||
|
|
||||||
import javax.swing.DefaultListModel;
|
import javax.swing.DefaultListModel;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
@ -80,10 +81,13 @@ public class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
private static JPanel configurationPanel;
|
private static JPanel configurationPanel;
|
||||||
private static JButton configUpdateButton;
|
private static JButton configUpdateButton;
|
||||||
private static JLabel configUpdateLabel;
|
private static JLabel configUpdateLabel;
|
||||||
|
private static JTextField configTimeoutText;
|
||||||
|
private static JTextField configThreadsText;
|
||||||
|
private static JCheckBox configOverwriteCheckbox;
|
||||||
// TODO Configuration components
|
// TODO Configuration components
|
||||||
|
|
||||||
public MainWindow() {
|
public MainWindow() {
|
||||||
mainFrame = new JFrame(WINDOW_TITLE);
|
mainFrame = new JFrame(WINDOW_TITLE + " v" + UpdateUtils.getThisJarVersion());
|
||||||
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
//mainFrame.setPreferredSize(new Dimension(400, 180));
|
//mainFrame.setPreferredSize(new Dimension(400, 180));
|
||||||
//mainFrame.setResizable(false);
|
//mainFrame.setResizable(false);
|
||||||
@ -196,14 +200,22 @@ public class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
configurationPanel.setVisible(false);
|
configurationPanel.setVisible(false);
|
||||||
configurationPanel.setPreferredSize(new Dimension(300, 250));
|
configurationPanel.setPreferredSize(new Dimension(300, 250));
|
||||||
// TODO Configuration components
|
// TODO Configuration components
|
||||||
JLabel configLabel = new JLabel("Version: " + UpdateUtils.getThisJarVersion());
|
|
||||||
configUpdateButton = new JButton("Check for updates");
|
configUpdateButton = new JButton("Check for updates");
|
||||||
configUpdateLabel = new JLabel("");
|
configUpdateLabel = new JLabel("Current version: " + UpdateUtils.getThisJarVersion(), JLabel.RIGHT);
|
||||||
gbc.gridy = 0; configurationPanel.add(configLabel, gbc);
|
JLabel configTimeoutLabel = new JLabel("Timeout (in milliseconds):", JLabel.RIGHT);
|
||||||
gbc.gridy = 1; configurationPanel.add(configUpdateButton, gbc);
|
JLabel configThreadsLabel = new JLabel("Maximum download threads:", JLabel.RIGHT);
|
||||||
gbc.ipady = 50;
|
configTimeoutText = new JTextField(Integer.toString(Utils.getConfigInteger("download.timeout", 60000)));
|
||||||
gbc.gridy = 2; configurationPanel.add(configUpdateLabel, gbc);
|
configThreadsText = new JTextField(Integer.toString(Utils.getConfigInteger("threads.size", 3)));
|
||||||
gbc.ipady = 10;
|
configOverwriteCheckbox = new JCheckBox("Overwrite existing files?", Utils.getConfigBoolean("file.overwrite", false));
|
||||||
|
configOverwriteCheckbox.setHorizontalAlignment(JCheckBox.RIGHT);
|
||||||
|
configOverwriteCheckbox.setHorizontalTextPosition(JCheckBox.LEFT);
|
||||||
|
gbc.gridy = 0; gbc.gridx = 0; configurationPanel.add(configUpdateLabel, gbc);
|
||||||
|
gbc.gridx = 1; configurationPanel.add(configUpdateButton, gbc);
|
||||||
|
gbc.gridy = 1; gbc.gridx = 0; configurationPanel.add(configTimeoutLabel, gbc);
|
||||||
|
gbc.gridx = 1; configurationPanel.add(configTimeoutText, gbc);
|
||||||
|
gbc.gridy = 2; gbc.gridx = 0; configurationPanel.add(configThreadsLabel, gbc);
|
||||||
|
gbc.gridx = 1; configurationPanel.add(configThreadsText, gbc);
|
||||||
|
gbc.gridy = 3; gbc.gridx = 0; configurationPanel.add(configOverwriteCheckbox, gbc);
|
||||||
|
|
||||||
gbc.gridy = 0; pane.add(ripPanel, gbc);
|
gbc.gridy = 0; pane.add(ripPanel, gbc);
|
||||||
gbc.gridy = 1; pane.add(statusPanel, gbc);
|
gbc.gridy = 1; pane.add(statusPanel, gbc);
|
||||||
@ -295,12 +307,17 @@ public class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
configUpdateButton.addActionListener(new ActionListener() {
|
configUpdateButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
|
Thread t = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
UpdateUtils.updateProgram(configUpdateLabel);
|
UpdateUtils.updateProgram(configUpdateLabel);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void appendLog(final String text, final Color color) {
|
private void appendLog(final String text, final Color color) {
|
||||||
SimpleAttributeSet sas = new SimpleAttributeSet();
|
SimpleAttributeSet sas = new SimpleAttributeSet();
|
||||||
StyleConstants.setForeground(sas, color);
|
StyleConstants.setForeground(sas, color);
|
||||||
|
@ -5,6 +5,7 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
@ -16,7 +17,7 @@ import org.jsoup.nodes.Document;
|
|||||||
public class UpdateUtils {
|
public class UpdateUtils {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(UpdateUtils.class);
|
private static final Logger logger = Logger.getLogger(UpdateUtils.class);
|
||||||
private static final String DEFAULT_VERSION = "100.0.0";
|
private static final String DEFAULT_VERSION = "1.0.4";
|
||||||
private static final String updateJsonURL = "http://rarchives.com/ripme.json";
|
private static final String updateJsonURL = "http://rarchives.com/ripme.json";
|
||||||
private static final String updateJarURL = "http://rarchives.com/ripme.jar";
|
private static final String updateJarURL = "http://rarchives.com/ripme.jar";
|
||||||
private static final String mainFileName = "ripme.jar";
|
private static final String mainFileName = "ripme.jar";
|
||||||
@ -32,7 +33,7 @@ public class UpdateUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void updateProgram(JLabel configUpdateLabel) {
|
public static void updateProgram(JLabel configUpdateLabel) {
|
||||||
configUpdateLabel.setText("Checking for update...:");
|
configUpdateLabel.setText("Checking for update...");
|
||||||
|
|
||||||
Document doc = null;
|
Document doc = null;
|
||||||
try {
|
try {
|
||||||
@ -40,32 +41,53 @@ public class UpdateUtils {
|
|||||||
.ignoreContentType(true)
|
.ignoreContentType(true)
|
||||||
.get();
|
.get();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
configUpdateLabel.setText("Error while fetching update: " + e.getMessage());
|
|
||||||
logger.error("Error while fetching update: ", e);
|
logger.error("Error while fetching update: ", e);
|
||||||
|
JOptionPane.showMessageDialog(null,
|
||||||
|
"<html><font color=\"red\">Error while fetching update: " + e.getMessage() + "</font></html>",
|
||||||
|
"RipMe Updater",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
|
} finally {
|
||||||
|
configUpdateLabel.setText("Current version: " + getThisJarVersion());
|
||||||
}
|
}
|
||||||
String jsonString = doc.body().html().replaceAll(""", "\"");
|
String jsonString = doc.body().html().replaceAll(""", "\"");
|
||||||
JSONObject json = new JSONObject(jsonString);
|
JSONObject json = new JSONObject(jsonString);
|
||||||
JSONArray jsonChangeList = json.getJSONArray("changeList");
|
JSONArray jsonChangeList = json.getJSONArray("changeList");
|
||||||
configUpdateLabel.setText("Most recent changes:");
|
StringBuilder changeList = new StringBuilder();
|
||||||
for (int i = 0; i < jsonChangeList.length(); i++) {
|
for (int i = 0; i < jsonChangeList.length(); i++) {
|
||||||
String change = jsonChangeList.getString(i);
|
String change = jsonChangeList.getString(i);
|
||||||
configUpdateLabel.setText(configUpdateLabel.getText() + "<br> + " + change);
|
changeList.append("<br> + " + change);
|
||||||
}
|
}
|
||||||
|
|
||||||
String latestVersion = json.getString("latestVersion");
|
String latestVersion = json.getString("latestVersion");
|
||||||
if (UpdateUtils.isNewerVersion(latestVersion)) {
|
if (UpdateUtils.isNewerVersion(latestVersion)) {
|
||||||
configUpdateLabel.setText("<html>Newer version found! <br><br>" + configUpdateLabel.getText() + "</html>");
|
int result = JOptionPane.showConfirmDialog(
|
||||||
|
null,
|
||||||
|
"<html><font color=\"green\">New version (" + latestVersion + ") is available!</font>"
|
||||||
|
+ "<br><br>Recent changes:" + changeList.toString()
|
||||||
|
+ "<br><br>Do you want to download and run the newest version?</html>",
|
||||||
|
"RipMe Updater",
|
||||||
|
JOptionPane.YES_NO_OPTION);
|
||||||
|
if (result != JOptionPane.YES_OPTION) {
|
||||||
|
configUpdateLabel.setText("<html>Current Version: " + getThisJarVersion()
|
||||||
|
+ "<br><font color=\"green\">Latest version: " + latestVersion + "</font></html>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
configUpdateLabel.setText("<html><font color=\"green\">Downloading new version...</font></html>");
|
||||||
logger.info("New version found, downloading...");
|
logger.info("New version found, downloading...");
|
||||||
try {
|
try {
|
||||||
UpdateUtils.downloadJarAndReplace(updateJarURL);
|
UpdateUtils.downloadJarAndReplace(updateJarURL);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
configUpdateLabel.setText("Error while updating: " + e.getMessage());
|
JOptionPane.showMessageDialog(null,
|
||||||
|
"Error while updating: " + e.getMessage(),
|
||||||
|
"RipMe Updater",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
configUpdateLabel.setText("");
|
||||||
logger.error("Error while updating: ", e);
|
logger.error("Error while updating: ", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
configUpdateLabel.setText("Running latest version: " + UpdateUtils.getThisJarVersion());
|
configUpdateLabel.setText("<html><font color=\"green\">v" + UpdateUtils.getThisJarVersion() + " is the latest version</font></html>");
|
||||||
logger.info("Running latest version: " + UpdateUtils.getThisJarVersion());
|
logger.info("Running latest version: " + UpdateUtils.getThisJarVersion());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user