Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Minor cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikDemyankov committed Dec 29, 2015
1 parent 85e2647 commit ceee58d
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/android/src/com/nordnetab/chcp/main/HotCodePushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ public void run() {
}
}

/**
* Check for update.
* Method is called from JS side.
*
* @param callback js callback
*/
private void jsFetchUpdate(CallbackContext callback) {
if (!isPluginReadyForWork) {
sendPluginNotReadyToWork(UpdateDownloadErrorEvent.EVENT_NAME, callback);
Expand All @@ -265,6 +271,12 @@ private void jsFetchUpdate(CallbackContext callback) {
fetchUpdate(callback);
}

/**
* Install the update.
* Method is called from JS side.
*
* @param callback js callback
*/
private void jsInstallUpdate(CallbackContext callback) {
if (!isPluginReadyForWork) {
sendPluginNotReadyToWork(UpdateInstallationErrorEvent.EVENT_NAME, callback);
Expand All @@ -274,6 +286,13 @@ private void jsInstallUpdate(CallbackContext callback) {
installUpdate(callback);
}

/**
* Send to JS side event with message, that plugin is installing assets on the external storage and not yet ready for work.
* That happens only on the first launch.
*
* @param eventName event name, that is send to JS side
* @param callback JS callback
*/
private void sendPluginNotReadyToWork(String eventName, CallbackContext callback) {
PluginResult pluginResult = PluginResultHelper.createPluginResult(eventName, null, ChcpError.ASSETS_FOLDER_IN_NOT_YET_INSTALLED);
callback.sendPluginResult(pluginResult);
Expand Down Expand Up @@ -332,7 +351,6 @@ private void jsRequestAppUpdate(final CordovaArgs arguments, final CallbackConte

/**
* Perform update availability check.
* Basically, queue update task.
*
* @param jsCallback callback where to send the result;
* used, when update is requested manually from JavaScript
Expand Down Expand Up @@ -388,9 +406,6 @@ private void installUpdate(CallbackContext jsCallback) {

/**
* Check if plugin can perform it's duties.
* Basically, we will check 2 main things:
* 1. if www folder installed
* 2. if application has been updated through the Goolge Play from the last launch.
*
* @return <code>true</code> - plugin is ready; otherwise - <code>false</code>
*/
Expand Down Expand Up @@ -697,6 +712,13 @@ public void onEvent(NothingToInstallEvent event) {

// endregion

// region Rollback process

/**
* Rollback to the previous/bundle version, if this is needed.
*
* @param error error, based on which we will decide
*/
private void rollbackIfCorrupted(ChcpError error) {
if (error != ChcpError.LOCAL_VERSION_OF_APPLICATION_CONFIG_NOT_FOUND &&
error != ChcpError.LOCAL_VERSION_OF_MANIFEST_NOT_FOUND) {
Expand All @@ -712,6 +734,9 @@ private void rollbackIfCorrupted(ChcpError error) {
}
}

/**
* Rollback to the previously installed version of the web content.
*/
private void rollbackToPreviousRelease() {
pluginInternalPrefs.setCurrentReleaseVersionName(pluginInternalPrefs.getPreviousReleaseVersionName());
pluginInternalPrefs.setPreviousReleaseVersionName("");
Expand All @@ -727,4 +752,6 @@ public void run() {
}
});
}

// endregion
}

0 comments on commit ceee58d

Please sign in to comment.