Skip to content

Commit

Permalink
Avoid overlapping calls to the launcher by returning after each case
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Bad Name authored and Kevin Bad Name committed Jun 22, 2024
1 parent ca1b663 commit 6d86ec6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
12 changes: 10 additions & 2 deletions lib/src/main/java/com/commonwealthrobotics/JvmManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ public static String getCommandString(String project, String repo, String versio
File dest = new File(bindir + name);
if (!dest.exists()) {
if (type.toLowerCase().contains("zip")) {
unzip(jvmArchive, bindir);
try {
unzip(jvmArchive, bindir);
}catch(java.util.zip.ZipException ex) {
System.out.println("Failed the extract, erasing and re-downloading");
jvmArchive.delete();
ex.printStackTrace();
return getCommandString(project, repo, version, downloadJsonURL,
sizeOfJson, progress, bindir);
}
}
if (type.toLowerCase().contains("tar.gz")) {
untar(jvmArchive, bindir);
Expand Down Expand Up @@ -218,7 +226,7 @@ private static File download(String version, String downloadJsonURL, long sizeOf
pis.addListener(new Listener() {
@Override
public void process(double percent) {
System.out.println("Download percent " + percent);
//System.out.println("Download percent " + percent);
Platform.runLater(() -> {
progress.setProgress(percent);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,15 @@ public void process(double percent) {
launchApplication();
}).start();
}

private boolean launched=false;
public void launchApplication() {
if(launched)
throw new RuntimeException("Applicaion is already launched!");
launched=true;
Platform.runLater(() -> {
yesButton.setDisable(true);
noButton.setDisable(true);
stage.close();

});
new Thread(() -> {
String command;
Expand All @@ -154,7 +157,9 @@ public void launchApplication() {
System.exit(1);
return;
}

// Run this later to show downloading the JVM
Platform.runLater(() ->stage.close());

try {
Thread.sleep(100);
} catch (InterruptedException e1) {
Expand Down Expand Up @@ -295,6 +300,7 @@ void initialize() {
if (!myVersionFile.exists()) {

onYes(null);
return;
} else {
try {
myVersionString = new String(Files.readAllBytes(Paths.get(myVersionFileString))).trim();
Expand All @@ -308,14 +314,19 @@ void initialize() {
}
}
if(!noInternet) {
if(myVersionString==null)
if(myVersionString==null) {
launchApplication();
return;
}
else
if (myVersionString.contentEquals(latestVersionString)) {
launchApplication();
return;
}
}else
}else {
onNo(null);
return;
}

}
}

0 comments on commit 6d86ec6

Please sign in to comment.