diff --git a/src/android/src/com/nordnetab/chcp/main/HotCodePushPlugin.java b/src/android/src/com/nordnetab/chcp/main/HotCodePushPlugin.java index 48f869e5..35b1b88b 100644 --- a/src/android/src/com/nordnetab/chcp/main/HotCodePushPlugin.java +++ b/src/android/src/com/nordnetab/chcp/main/HotCodePushPlugin.java @@ -34,6 +34,8 @@ import com.nordnetab.chcp.main.utils.Paths; import com.nordnetab.chcp.main.utils.VersionHelper; +import com.nordnetab.chcp.main.model.ChcpError; + import org.apache.cordova.CallbackContext; import org.apache.cordova.ConfigXmlParser; import org.apache.cordova.CordovaArgs; @@ -368,7 +370,12 @@ private void installUpdate(CallbackContext jsCallback) { installJsCallback = jsCallback; } - UpdatesInstaller.install(fileStructure); + if (UpdatesInstaller.install(fileStructure)) { + // ensure that we set the www folder as invalid, temporarily, + // so that if the app crashes or is killed we don't run from a corrupted www folder + pluginInternalPrefs.setWwwFolderInstalled(false); + pluginInternalPrefsStorage.storeInPreference(pluginInternalPrefs); + } } // endregion @@ -436,6 +443,7 @@ private void redirectToLocalStorage() { currentUrl = currentUrl.replace(LOCAL_ASSETS_FOLDER, ""); String external = Paths.get(fileStructure.wwwFolder(), currentUrl); if (!new File(external).exists()) { + Log.d("CHCP", "External starting page not found. Aborting page change."); return; } @@ -617,6 +625,10 @@ public void onEvent(NothingToUpdateEvent event) { @SuppressWarnings("unused") public void onEvent(UpdateDownloadErrorEvent event) { Log.d("CHCP", "Failed to update"); + if (event.error() == ChcpError.LOCAL_VERSION_OF_APPLICATION_CONFIG_NOT_FOUND || event.error() == ChcpError.LOCAL_VERSION_OF_MANIFEST_NOT_FOUND) { + Log.d("CHCP", "Can't load application config from installation folder. Reinstalling external folder"); + installWwwFolder(); + } PluginResult jsResult = PluginResultHelper.pluginResultFromEvent(event); @@ -645,6 +657,10 @@ public void onEvent(UpdateDownloadErrorEvent event) { public void onEvent(UpdateInstalledEvent event) { Log.d("CHCP", "Update is installed"); + // reconfirm that our www folder is now valid + pluginInternalPrefs.setWwwFolderInstalled(true); + pluginInternalPrefsStorage.storeInPreference(pluginInternalPrefs); + final PluginResult jsResult = PluginResultHelper.pluginResultFromEvent(event); if (installJsCallback != null) { @@ -666,8 +682,12 @@ private void resetApplicationToStartingPage() { public void run() { webView.clearHistory(); webView.clearCache(); - final String startingPage = getStartingPage() + "?" + System.currentTimeMillis(); - final String externalStartingPage = FILE_PREFIX + Paths.get(fileStructure.wwwFolder(), startingPage); + final String external = Paths.get(fileStructure.wwwFolder(), getStartingPage()); + if (!new File(external).exists()) { + Log.d("CHCP", "External starting page not found. Aborting page change."); + return; + } + final String externalStartingPage = FILE_PREFIX + external + "?" + System.currentTimeMillis(); webView.loadUrlIntoView(externalStartingPage, false); } }); diff --git a/src/android/src/com/nordnetab/chcp/main/updater/UpdatesInstaller.java b/src/android/src/com/nordnetab/chcp/main/updater/UpdatesInstaller.java index 5394de72..5c66302b 100644 --- a/src/android/src/com/nordnetab/chcp/main/updater/UpdatesInstaller.java +++ b/src/android/src/com/nordnetab/chcp/main/updater/UpdatesInstaller.java @@ -53,10 +53,10 @@ public static boolean isInstalling() { } private static void execute(final InstallationWorker task) { + isInstalling = true; new Thread(new Runnable() { @Override public void run() { - isInstalling = true; task.run(); isInstalling = false; }