Move update checker to startup thread
This commit is contained in:
parent
2cbfa3daa0
commit
56317f8a52
@ -43,7 +43,6 @@ import javax.swing.ImageIcon;
|
|||||||
import javax.swing.JInternalFrame;
|
import javax.swing.JInternalFrame;
|
||||||
import javax.swing.ListModel;
|
import javax.swing.ListModel;
|
||||||
import javax.swing.UIManager;
|
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
|
* 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 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
|
* 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());
|
getClass().getResource("icon.png"))).getImage());
|
||||||
setLocationRelativeTo(null);
|
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();
|
setButtonShortcuts();
|
||||||
|
|
||||||
// Open initial windows
|
// Open initial windows
|
||||||
@ -140,6 +111,9 @@ public class MainGUI extends javax.swing.JFrame {
|
|||||||
if (argfile.equals("") && !loaded) {
|
if (argfile.equals("") && !loaded) {
|
||||||
loadFrame(new Interpreter());
|
loadFrame(new Interpreter());
|
||||||
}
|
}
|
||||||
|
if (updateAvailable) {
|
||||||
|
loadFrame(new Update(updateString));
|
||||||
|
}
|
||||||
loadRecentFiles();
|
loadRecentFiles();
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,10 @@ package net.apocalypselabs.symat;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
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.ImageIcon;
|
||||||
import javax.swing.JProgressBar;
|
import javax.swing.JProgressBar;
|
||||||
import javax.swing.Painter;
|
import javax.swing.Painter;
|
||||||
@ -36,6 +40,10 @@ import javax.swing.SwingUtilities;
|
|||||||
import javax.swing.UIDefaults;
|
import javax.swing.UIDefaults;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ColorUIResource;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -158,12 +166,47 @@ public class SplashScreen extends javax.swing.JFrame {
|
|||||||
CodeEditor edit = new CodeEditor();
|
CodeEditor edit = new CodeEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setProgress(75, "Checking for updates...");
|
||||||
|
checkUpdates();
|
||||||
|
|
||||||
setProgress(85, "Loading main interface...");
|
setProgress(85, "Loading main interface...");
|
||||||
new MainGUI().setVisible(true);
|
new MainGUI().setVisible(true);
|
||||||
setProgress(100, "Done!");
|
setProgress(100, "Done!");
|
||||||
dispose();
|
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.
|
* Set the progress bar.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user