Skip to content

Commit

Permalink
Reset stored server path on new binary
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Sep 5, 2018
1 parent 1bfea4f commit de67b99
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.graphics.Bitmap;
import android.util.Log;
import android.webkit.WebResourceRequest;
Expand All @@ -27,6 +28,7 @@ public class IonicWebViewEngine extends SystemWebViewEngine {

private WebViewLocalServer localServer;
private String CDV_LOCAL_SERVER;
private static final String LAST_BINARY_VERSION = "lastPackageVersion";

/** Used when created via reflection. */
public IonicWebViewEngine(Context context, CordovaPreferences preferences) {
Expand Down Expand Up @@ -62,11 +64,33 @@ public void init(CordovaWebView parentWebView, CordovaInterface cordova, final C
super.init(parentWebView, cordova, client, resourceApi, pluginManager, nativeToJsMessageQueue);
SharedPreferences prefs = cordova.getActivity().getApplicationContext().getSharedPreferences(IonicWebView.WEBVIEW_PREFS_NAME, Activity.MODE_PRIVATE);
String path = prefs.getString(IonicWebView.CDV_SERVER_PATH, null);
if (path != null) {
if (!isNewBinary() && path != null && !path.isEmpty()) {
setServerBasePath(path);
}
}

private boolean isNewBinary() {
String version = "";
SharedPreferences prefs = cordova.getActivity().getApplicationContext().getSharedPreferences(IonicWebView.WEBVIEW_PREFS_NAME, Activity.MODE_PRIVATE);
String lastVersion = prefs.getString(LAST_BINARY_VERSION, null);

try {
PackageInfo pInfo = this.cordova.getActivity().getPackageManager().getPackageInfo(this.cordova.getActivity().getPackageName(), 0);
version = Integer.toString(pInfo.versionCode);
} catch(Exception ex) {
Log.e(TAG, "Unable to get package info", ex);
}

if (!version.equals(lastVersion)) {
SharedPreferences.Editor editor = prefs.edit();
editor.putString(LAST_BINARY_VERSION, version);
editor.putString(IonicWebView.CDV_SERVER_PATH, "");
editor.apply();
return true;
}
return false;
}

private class ServerClient extends SystemWebViewClient
{
private ConfigXmlParser parser;
Expand Down

0 comments on commit de67b99

Please sign in to comment.