Skip to content

Commit

Permalink
Update no longer occurs on first-time launch
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Jun 12, 2018
1 parent 57189eb commit 8dd84e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/me/coley/recaf/Recaf.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class Recaf {

public static void main(String[] args) {
launchArgs = args;
if (ConfUpdate.instance().shouldCheck()) {
Updater.run(args);
}
Updater.run(args);
Bus.subscribe(new Recaf());
FxWindow.init(args);
}
Expand Down
14 changes: 10 additions & 4 deletions src/me/coley/recaf/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@
@SuppressWarnings("unused")
public class Updater {
private final static String API_LATEST = "https://api.github.com/repos/Col-E/Recaf/releases/latest";

public static void run(String[] args) {
// check if updates should occur
if (!ConfUpdate.instance().shouldCheck()) {
return;
}
try {
ConfUpdate.instance().lastCheck = System.currentTimeMillis();
// get self data
SelfReference self = Files.getSelf();
if (!self.isJar()) {
// If the execuatable context is not a runnable jar, do not attempt to update.
// Methods to do so exist should this functionality be wanted in the future.
// If the execuatable context is not a runnable jar, do not
// attempt to update.
// Methods to do so exist should this functionality be wanted in
// the future.
return;
}
String selfVersion = Recaf.VERSION;
Expand Down Expand Up @@ -139,7 +145,7 @@ private static boolean isOutdated(String self, String latest) {
}
return false;
}

private static String getVersionFromJar(SelfReference self) throws IOException {
String file = "META-INF/maven/me.coley/recaf/pom.xml";
URL url = Thread.currentThread().getContextClassLoader().getResource(file);
Expand Down
6 changes: 6 additions & 0 deletions src/me/coley/recaf/config/impl/ConfUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ protected Object parse(Class<?> type, JsonValue value) {
* frequency.
*/
public boolean shouldCheck() {
// check for first-time
if (lastCheck == 0) {
lastCheck = System.currentTimeMillis();
return false;
}
// check for valid check interval
return active && frequency.check(lastCheck);
}

Expand Down

0 comments on commit 8dd84e7

Please sign in to comment.