Move update checker to startup thread

master
skylarmt 9 years ago
parent 2cbfa3daa0
commit 56317f8a52

@ -43,7 +43,6 @@ import javax.swing.ImageIcon;
import javax.swing.JInternalFrame;
import javax.swing.ListModel;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
/**
* This class is like the Force: A light theme, a dark theme, and it binds the
@ -64,7 +63,8 @@ public class MainGUI extends javax.swing.JFrame {
private static boolean recentItemsMinimized = false;
private static final int RECENT_FILES = 10;
public static boolean updateAvailable = false;
public static String updateString = "";
/**
* Creates the main app window and does some quick things that aren't
@ -76,35 +76,6 @@ public class MainGUI extends javax.swing.JFrame {
getClass().getResource("icon.png"))).getImage());
setLocationRelativeTo(null);
// Check for updates.
try {
Debug.println("Checking for updates...");
URL url = new URL(API_URL + "version.php");
InputStream is = url.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = br.readLine();
br.close();
is.close();
double version = Double.parseDouble(line.split("\\|")[0]);
if (version > APP_CODE) {
if (PrefStorage.getSetting("update-ignore")
.equals(VERSION_NAME + "|" + line.split("\\|")[1])) {
System.out.println("An update was found, "
+ "but has been ignored by the user.");
} else {
Debug.println("Update available.");
loadFrame(new Update(line.split("\\|")[1]));
}
} else {
Debug.println("No updates found.");
}
} catch (IOException | NumberFormatException e) {
System.err.println("Fail: Cannot check update server. \n"
+ " Assuming local copy up-to-date.");
Debug.stacktrace(e);
}
setButtonShortcuts();
// Open initial windows
@ -140,6 +111,9 @@ public class MainGUI extends javax.swing.JFrame {
if (argfile.equals("") && !loaded) {
loadFrame(new Interpreter());
}
if (updateAvailable) {
loadFrame(new Update(updateString));
}
loadRecentFiles();
updateDisplay();
}

@ -29,6 +29,10 @@ package net.apocalypselabs.symat;
import java.awt.Color;
import java.awt.Graphics2D;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JProgressBar;
import javax.swing.Painter;
@ -36,6 +40,10 @@ import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
import static net.apocalypselabs.symat.MainGUI.API_URL;
import static net.apocalypselabs.symat.MainGUI.APP_CODE;
import static net.apocalypselabs.symat.MainGUI.VERSION_NAME;
import static net.apocalypselabs.symat.MainGUI.loadFrame;
/**
*
@ -53,7 +61,7 @@ public class SplashScreen extends javax.swing.JFrame {
defaults.put("ProgressBar[Enabled].foregroundPainter", new ProgressPainter(true));
progBar.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
progBar.putClientProperty("Nimbus.Overrides", defaults);
setIconImage((new ImageIcon(
getClass().getResource("icon.png"))).getImage());
setLocationRelativeTo(null);
@ -157,6 +165,9 @@ public class SplashScreen extends javax.swing.JFrame {
// Get editor going too
CodeEditor edit = new CodeEditor();
}
setProgress(75, "Checking for updates...");
checkUpdates();
setProgress(85, "Loading main interface...");
new MainGUI().setVisible(true);
@ -164,6 +175,38 @@ public class SplashScreen extends javax.swing.JFrame {
dispose();
}
private void checkUpdates() {
// Check for updates.
try {
Debug.println("Checking for updates...");
URL url = new URL(API_URL + "testversion.php");
InputStream is = url.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = br.readLine();
br.close();
is.close();
double version = Double.parseDouble(line.split("\\|")[0]);
if (version > APP_CODE) {
if (PrefStorage.getSetting("update-ignore")
.equals(VERSION_NAME + "|" + line.split("\\|")[1])) {
System.out.println("An update was found, "
+ "but has been ignored by the user.");
} else {
Debug.println("Update available.");
MainGUI.updateString = line.split("\\|")[1];
MainGUI.updateAvailable = true;
}
} else {
Debug.println("No updates found.");
}
} catch (Exception e) {
System.err.println("Fail: Cannot check update server. \n"
+ " Assuming local copy up-to-date.");
Debug.stacktrace(e);
}
}
/**
* Set the progress bar.
*

Loading…
Cancel
Save