Automatic check for updates
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
package games.rednblack.editor.plugin.skincomposer;
|
||||
package games.rednblack.h2d.common.network;
|
||||
|
||||
import games.rednblack.h2d.common.ProgressHandler;
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package games.rednblack.editor.plugin.skincomposer;
|
||||
package games.rednblack.h2d.common.network.model;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
@@ -8,7 +8,7 @@ public class GithubReleaseData {
|
||||
public Array<GithubReleaseAssetData> assets;
|
||||
|
||||
public static class GithubReleaseAssetData {
|
||||
String name;
|
||||
String browser_download_url;
|
||||
public String name;
|
||||
public String browser_download_url;
|
||||
}
|
||||
}
|
||||
+2
@@ -2,7 +2,9 @@ package games.rednblack.editor.plugin.skincomposer;
|
||||
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.kotcrab.vis.ui.util.dialog.Dialogs;
|
||||
import games.rednblack.h2d.common.network.HttpDownloadUtility;
|
||||
import games.rednblack.h2d.common.MsgAPI;
|
||||
import games.rednblack.h2d.common.network.model.GithubReleaseData;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.puremvc.java.interfaces.INotification;
|
||||
import org.puremvc.java.patterns.mediator.Mediator;
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
package games.rednblack.editor.splash;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import games.rednblack.editor.HyperLap2DApp;
|
||||
import games.rednblack.editor.HyperLap2DFacade;
|
||||
import games.rednblack.editor.utils.AppConfig;
|
||||
import games.rednblack.h2d.common.network.HttpDownloadUtility;
|
||||
import games.rednblack.h2d.common.network.model.GithubReleaseData;
|
||||
import org.lwjgl.util.tinyfd.TinyFileDialogs;
|
||||
import org.puremvc.java.interfaces.INotification;
|
||||
import org.puremvc.java.patterns.mediator.Mediator;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class SplashMediator extends Mediator<Object> {
|
||||
|
||||
private static final String TAG = SplashMediator.class.getCanonicalName();
|
||||
@@ -33,12 +42,38 @@ public class SplashMediator extends Mediator<Object> {
|
||||
super.handleNotification(notification);
|
||||
System.out.println(notification.getBody().toString());
|
||||
|
||||
SplashScreenAdapter splash = (SplashScreenAdapter) (HyperLap2DApp.getInstance().splashWindow.getListener());
|
||||
|
||||
if (HyperLap2DApp.getInstance().splashWindow != null && HyperLap2DApp.getInstance().mainWindow != null) {
|
||||
((SplashScreenAdapter)(HyperLap2DApp.getInstance().splashWindow.getListener())).setProgressStatus(notification.getBody().toString());
|
||||
splash.setProgressStatus(notification.getBody().toString());
|
||||
|
||||
if (notification.getName().equals(SplashScreenAdapter.CLOSE_SPLASH)) {
|
||||
((SplashScreenAdapter)(HyperLap2DApp.getInstance().splashWindow.getListener())).loadedData();
|
||||
HyperLap2DApp.getInstance().mainWindow.setVisible(true);
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
executor.execute(() -> {
|
||||
splash.setProgressStatus("Checking for updates...");
|
||||
try {
|
||||
String data = HttpDownloadUtility.downloadToString("https://api.github.com/repos/rednblackgames/HyperLap2D/releases/latest");
|
||||
Json json = new Json();
|
||||
json.setIgnoreUnknownFields(true);
|
||||
GithubReleaseData jsonData = json.fromJson(GithubReleaseData.class, data);
|
||||
int latestVer = Integer.parseInt(jsonData.tag_name.replace("v", "").replace(".", ""));
|
||||
int currVer = Integer.parseInt(AppConfig.getInstance().version.replace(".", ""));
|
||||
if (latestVer > currVer) {
|
||||
boolean result = TinyFileDialogs.tinyfd_messageBox("New update found!",
|
||||
"A new version of HyperLap2D has found, would you like to download it?",
|
||||
"yesno", "info", true);
|
||||
if (result) {
|
||||
Gdx.net.openURI("https://github.com/rednblackgames/HyperLap2D/releases");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
splash.loadedData();
|
||||
HyperLap2DApp.getInstance().mainWindow.setVisible(true);
|
||||
});
|
||||
executor.shutdown();
|
||||
}
|
||||
|
||||
HyperLap2DApp.getInstance().splashWindow.focusWindow();
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package games.rednblack.editor.splash;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.InputAdapter;
|
||||
import com.badlogic.gdx.InputProcessor;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
@@ -55,7 +53,7 @@ public class SplashStage extends Stage {
|
||||
if (isLoading)
|
||||
addActor(progress);
|
||||
|
||||
Label companyName = new Label("Red & Black Games", whiteLabelStyle);
|
||||
Label companyName = new Label("Red & Black Games", whiteLabelStyle);
|
||||
companyName.setX(13);
|
||||
companyName.setY(55 - companyName.getHeight() - 7);
|
||||
addActor(companyName);
|
||||
@@ -84,7 +82,7 @@ public class SplashStage extends Stage {
|
||||
|
||||
public void setProgressStatus(String status) {
|
||||
progress.setText(status);
|
||||
progress.setX(logoText.getX() + ((logoText.getWidth() - progress.getWidth()) / 2));
|
||||
progress.setX(logoText.getX() + ((logoText.getWidth() - progress.getPrefWidth()) / 2));
|
||||
}
|
||||
|
||||
public void loadedData() {
|
||||
|
||||
Reference in New Issue
Block a user