mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Support running installer after exiting
This commit is contained in:
@@ -3,9 +3,11 @@ package forge.app;
|
|||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
@@ -15,6 +17,7 @@ import com.badlogic.gdx.backends.android.AndroidApplication;
|
|||||||
|
|
||||||
import forge.Forge;
|
import forge.Forge;
|
||||||
import forge.interfaces.INetworkConnection;
|
import forge.interfaces.INetworkConnection;
|
||||||
|
import forge.util.Callback;
|
||||||
import forge.util.FileUtil;
|
import forge.util.FileUtil;
|
||||||
|
|
||||||
public class Main extends AndroidApplication {
|
public class Main extends AndroidApplication {
|
||||||
@@ -42,9 +45,14 @@ public class Main extends AndroidApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initialize(Forge.getApp(new AndroidClipboard(), new AndroidNetworkConnection(),
|
initialize(Forge.getApp(new AndroidClipboard(), new AndroidNetworkConnection(),
|
||||||
assetsDir, new Runnable() {
|
assetsDir, new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run(String runOnExit) {
|
||||||
|
if (runOnExit != null) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(runOnExit));
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
//ensure process doesn't stick around after exiting
|
//ensure process doesn't stick around after exiting
|
||||||
android.os.Process.killProcess(android.os.Process.myPid());
|
android.os.Process.killProcess(android.os.Process.myPid());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,17 +42,19 @@ public class Forge implements ApplicationListener {
|
|||||||
private static final ApplicationListener app = new Forge();
|
private static final ApplicationListener app = new Forge();
|
||||||
private static Clipboard clipboard;
|
private static Clipboard clipboard;
|
||||||
private static INetworkConnection networkConnection;
|
private static INetworkConnection networkConnection;
|
||||||
private static Runnable onExit;
|
private static Callback<String> onExit;
|
||||||
private static int screenWidth;
|
private static int screenWidth;
|
||||||
private static int screenHeight;
|
private static int screenHeight;
|
||||||
private static Graphics graphics;
|
private static Graphics graphics;
|
||||||
private static FScreen currentScreen;
|
private static FScreen currentScreen;
|
||||||
private static SplashScreen splashScreen;
|
private static SplashScreen splashScreen;
|
||||||
private static KeyInputAdapter keyInputAdapter;
|
private static KeyInputAdapter keyInputAdapter;
|
||||||
|
private static String runAfterExit;
|
||||||
|
private static boolean exited;
|
||||||
private static final SoundSystem soundSystem = new SoundSystem();
|
private static final SoundSystem soundSystem = new SoundSystem();
|
||||||
private static final Stack<FScreen> screens = new Stack<FScreen>();
|
private static final Stack<FScreen> screens = new Stack<FScreen>();
|
||||||
|
|
||||||
public static ApplicationListener getApp(Clipboard clipboard0, INetworkConnection networkConnection0, String assetDir0, Runnable onExit0) {
|
public static ApplicationListener getApp(Clipboard clipboard0, INetworkConnection networkConnection0, String assetDir0, Callback<String> onExit0) {
|
||||||
if (GuiBase.getInterface() == null) {
|
if (GuiBase.getInterface() == null) {
|
||||||
clipboard = clipboard0;
|
clipboard = clipboard0;
|
||||||
networkConnection = networkConnection0;
|
networkConnection = networkConnection0;
|
||||||
@@ -88,10 +90,8 @@ public class Forge implements ApplicationListener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
//see if app or assets need updating
|
//see if app or assets need updating
|
||||||
if (!AssetsDownloader.checkForUpdates(splashScreen)) {
|
AssetsDownloader.checkForUpdates(splashScreen);
|
||||||
Gdx.app.exit(); //exit if user chose to exit or couldn't download required assets
|
if (exited) { return; } //don't continue if user chose to exit or couldn't download required assets
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
FModel.initialize(splashScreen.getProgressBar());
|
FModel.initialize(splashScreen.getProgressBar());
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ public class Forge implements ApplicationListener {
|
|||||||
|
|
||||||
public static void back() {
|
public static void back() {
|
||||||
if (screens.size() < 2) {
|
if (screens.size() < 2) {
|
||||||
exit(); //prompt to exit if attempting to go back from home screen
|
exit(false, null); //prompt to exit if attempting to go back from home screen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
currentScreen.onClose(new Callback<Boolean>() {
|
currentScreen.onClose(new Callback<Boolean>() {
|
||||||
@@ -159,15 +159,25 @@ public class Forge implements ApplicationListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void exit() {
|
public static void exit(boolean silent, final String runAfterExit0) {
|
||||||
FOptionPane.showConfirmDialog("Are you sure you wish to exit Forge?", "Exit Forge", "Exit", "Cancel", new Callback<Boolean>() {
|
if (exited) { return; } //don't allow exiting multiple times
|
||||||
|
|
||||||
|
Callback<Boolean> callback = new Callback<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(Boolean result) {
|
public void run(Boolean result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
|
exited = true;
|
||||||
|
runAfterExit = runAfterExit0;
|
||||||
Gdx.app.exit();
|
Gdx.app.exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
if (silent) {
|
||||||
|
callback.run(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FOptionPane.showConfirmDialog("Are you sure you wish to exit Forge?", "Exit Forge", "Exit", "Cancel", callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openScreen(final FScreen screen0) {
|
public static void openScreen(final FScreen screen0) {
|
||||||
@@ -283,7 +293,7 @@ public class Forge implements ApplicationListener {
|
|||||||
soundSystem.dispose();
|
soundSystem.dispose();
|
||||||
|
|
||||||
if (onExit != null) {
|
if (onExit != null) {
|
||||||
onExit.run();
|
onExit.run(runAfterExit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ import forge.util.FileUtil;
|
|||||||
import forge.util.gui.SOptionPane;
|
import forge.util.gui.SOptionPane;
|
||||||
|
|
||||||
public class AssetsDownloader {
|
public class AssetsDownloader {
|
||||||
public static final boolean SHARE_DESKTOP_ASSETS = true; //change to false to test downloading separate assets for desktop version
|
public static final boolean SHARE_DESKTOP_ASSETS = false; //change to false to test downloading separate assets for desktop version
|
||||||
|
|
||||||
//if not sharing desktop assets, check whether assets are up to date
|
//if not sharing desktop assets, check whether assets are up to date
|
||||||
public static boolean checkForUpdates(final SplashScreen splashScreen) {
|
public static void checkForUpdates(final SplashScreen splashScreen) {
|
||||||
if (Gdx.app.getType() == ApplicationType.Desktop && SHARE_DESKTOP_ASSETS) { return true; }
|
if (Gdx.app.getType() == ApplicationType.Desktop && SHARE_DESKTOP_ASSETS) { return; }
|
||||||
|
|
||||||
splashScreen.getProgressBar().setDescription("Checking for updates...");
|
splashScreen.getProgressBar().setDescription("Checking for updates...");
|
||||||
|
|
||||||
@@ -49,11 +49,18 @@ public class AssetsDownloader {
|
|||||||
"You are currently on an older version (" + Forge.CURRENT_VERSION + ").\n\n" +
|
"You are currently on an older version (" + Forge.CURRENT_VERSION + ").\n\n" +
|
||||||
"Would you like to update to the new version now?";
|
"Would you like to update to the new version now?";
|
||||||
if (!Forge.getNetworkConnection().isConnectedToWifi()) {
|
if (!Forge.getNetworkConnection().isConnectedToWifi()) {
|
||||||
message += " If so, you may want to connect to wifi first. The installer download is 6.5MB.";
|
message += " If so, you may want to connect to wifi first. The download is around 6.5MB.";
|
||||||
}
|
}
|
||||||
if (SOptionPane.showConfirmDialog(message, "New Version Available", "Update Now", "Update Later")) {
|
if (SOptionPane.showConfirmDialog(message, "New Version Available", "Update Now", "Update Later")) {
|
||||||
|
String apkFile = downloadFile("update", "forge-android-" + version + "-signed-aligned.apk",
|
||||||
return false;
|
"http://cardforge.org/android/releases/forge/forge-gui-android/" + version + "/",
|
||||||
|
ForgeConstants.ASSETS_DIR, splashScreen.getProgressBar());
|
||||||
|
if (apkFile != null) {
|
||||||
|
Forge.exit(true, apkFile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SOptionPane.showMessageDialog("Could not download update. " +
|
||||||
|
"Press OK to proceed without update.", "Update Failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,11 +77,12 @@ public class AssetsDownloader {
|
|||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false; //can't continue if this fails
|
Forge.exit(true, null); //can't continue if this fails
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Forge.CURRENT_VERSION.equals(FileUtil.readFileToString(versionFile)) && FSkin.getSkinDir() != null) {
|
else if (Forge.CURRENT_VERSION.equals(FileUtil.readFileToString(versionFile)) && FSkin.getSkinDir() != null) {
|
||||||
return true; //if version matches what had been previously saved and FSkin isn't requesting assets download, no need to download assets
|
return; //if version matches what had been previously saved and FSkin isn't requesting assets download, no need to download assets
|
||||||
}
|
}
|
||||||
|
|
||||||
splashScreen.prepareForDialogs(); //ensure colors set up for showing message dialogs
|
splashScreen.prepareForDialogs(); //ensure colors set up for showing message dialogs
|
||||||
@@ -90,7 +98,10 @@ public class AssetsDownloader {
|
|||||||
message += "You cannot start the app since you haven't previously downloaded these files.";
|
message += "You cannot start the app since you haven't previously downloaded these files.";
|
||||||
}
|
}
|
||||||
SOptionPane.showMessageDialog(message, "No Internet Connection");
|
SOptionPane.showMessageDialog(message, "No Internet Connection");
|
||||||
return canIgnoreDownload; //exit if can't ignore download
|
if (!canIgnoreDownload) {
|
||||||
|
Forge.exit(true, null); //exit if can't ignore download
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//prompt user whether they wish to download the updated resource files
|
//prompt user whether they wish to download the updated resource files
|
||||||
@@ -115,9 +126,13 @@ public class AssetsDownloader {
|
|||||||
switch (SOptionPane.showOptionDialog(message, "Download Resource Files?",
|
switch (SOptionPane.showOptionDialog(message, "Download Resource Files?",
|
||||||
null, options)) {
|
null, options)) {
|
||||||
case 1:
|
case 1:
|
||||||
return canIgnoreDownload; //return true or false based on whether second option is Ignore vs. Exit
|
if (!canIgnoreDownload) {
|
||||||
|
Forge.exit(true, null); //exit if can't ignore download
|
||||||
|
}
|
||||||
|
return;
|
||||||
case 2:
|
case 2:
|
||||||
return false; //return false to indicate to exit application
|
Forge.exit(true, null);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadAssets(splashScreen.getProgressBar());
|
downloadAssets(splashScreen.getProgressBar());
|
||||||
@@ -136,7 +151,6 @@ public class AssetsDownloader {
|
|||||||
//save version string to file once assets finish downloading
|
//save version string to file once assets finish downloading
|
||||||
//so they don't need to be re-downloaded until you upgrade again
|
//so they don't need to be re-downloaded until you upgrade again
|
||||||
FileUtil.writeFile(versionFile, Forge.CURRENT_VERSION);
|
FileUtil.writeFile(versionFile, Forge.CURRENT_VERSION);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String downloadFile(final String desc, final String filename, final String sourceFolder, final String destFolder, final FProgressBar progressBar) {
|
private static String downloadFile(final String desc, final String filename, final String sourceFolder, final String destFolder, final FProgressBar progressBar) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package forge.error;
|
package forge.error;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
|
||||||
|
|
||||||
@@ -63,7 +62,7 @@ public class BugReportDialog extends FScreen { //use screen rather than dialog s
|
|||||||
btnExit.setCommand(new FEventHandler() {
|
btnExit.setCommand(new FEventHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(FEvent e) {
|
public void handleEvent(FEvent e) {
|
||||||
Gdx.app.exit();
|
Forge.exit(true, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user