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

Commit

Permalink
Javascript method to get the name of the current version
Browse files Browse the repository at this point in the history
  • Loading branch information
Manduro committed Jun 22, 2016
1 parent 9102cfd commit f5cacec
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/android/src/com/nordnetab/chcp/main/HotCodePushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ public boolean execute(String action, CordovaArgs args, CallbackContext callback
jsRequestAppUpdate(args, callbackContext);
} else if (JSAction.IS_UPDATE_AVAILABLE_FOR_INSTALLATION.equals(action)) {
jsIsUpdateAvailableForInstallation(callbackContext);
} else if (JSAction.GET_CURRENT_VERSION.equals(action)) {
jsGetCurrentVersion(callbackContext);
} else {
cmdProcessed = false;
}
Expand Down Expand Up @@ -444,6 +446,19 @@ private void jsIsUpdateAvailableForInstallation(final CallbackContext callback)
callback.sendPluginResult(pluginResult);
}

/**
* Check if new version was loaded and can be installed.
*
* @param callback callback where to send the result
*/
private void jsGetCurrentVersion(final CallbackContext callback) {
Map<String, Object> data = new HashMap<String, Object>();
data.put("currentVersion", pluginInternalPrefs.getCurrentReleaseVersionName());

PluginResult pluginResult = PluginResultHelper.createPluginResult(null, data, null);
callback.sendPluginResult(pluginResult);
}

// convenience method
private void fetchUpdate() {
fetchUpdate(null, new FetchUpdateOptions());
Expand Down
1 change: 1 addition & 0 deletions src/android/src/com/nordnetab/chcp/main/js/JSAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public final class JSAction {
public static final String CONFIGURE = "jsConfigure";
public static final String REQUEST_APP_UPDATE = "jsRequestAppUpdate";
public static final String IS_UPDATE_AVAILABLE_FOR_INSTALLATION = "jsIsUpdateAvailableForInstallation";
public static final String GET_CURRENT_VERSION = "jsGetCurrentVersion";

// Private API
public static final String INIT = "jsInitPlugin";
Expand Down
7 changes: 7 additions & 0 deletions src/ios/HCPPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@
*/
- (void)jsIsUpdateAvailableForInstallation:(CDVInvokedUrlCommand *)command;

/**
* Get the name of the current version.
*
* @param command command with which the method is called
*/
- (void)jsGetCurrentVersion:(CDVInvokedUrlCommand *)command;

@end
7 changes: 7 additions & 0 deletions src/ios/HCPPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,13 @@ - (void)jsIsUpdateAvailableForInstallation:(CDVInvokedUrlCommand *)command {
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}

- (void)jsGetCurrentVersion:(CDVInvokedUrlCommand *)command {
NSDictionary *data = @{@"currentVersion": _pluginInternalPrefs.currentReleaseVersionName};

CDVPluginResult *result = [CDVPluginResult pluginResultWithActionName:nil data:data error:nil];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}

- (void)sendPluginNotReadyToWorkMessageForEvent:(NSString *)eventName callbackID:(NSString *)callbackID {
NSError *error = [NSError errorWithCode:kHCPAssetsNotYetInstalledErrorCode
description:@"WWW folder from the bundle is not yet installed on the external device. Please, wait for this operation to finish."];
Expand Down
13 changes: 12 additions & 1 deletion www/chcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var exec = require('cordova/exec'),
INSTALL_UPDATE: 'jsInstallUpdate',
CONFIGURE: 'jsConfigure',
REQUEST_APP_UPDATE: 'jsRequestAppUpdate',
IS_UPDATE_AVAILABLE_FOR_INSTALLATION: 'jsIsUpdateAvailableForInstallation'
IS_UPDATE_AVAILABLE_FOR_INSTALLATION: 'jsIsUpdateAvailableForInstallation',
GET_CURRENT_VERSION: 'jsGetCurrentVersion'
};

// Called when Cordova is ready for work.
Expand Down Expand Up @@ -262,6 +263,16 @@ var chcp = {
*/
isUpdateAvailableForInstallation: function(callback) {
callNativeMethod(pluginNativeMethod.IS_UPDATE_AVAILABLE_FOR_INSTALLATION, null, callback);
},

/**
* Get the name of the current version.
* The "data" property of the callback will contain the name of the current version.
*
* @param {Callback(data)} callback - called, when information is retrieved from the native side.
*/
getCurrentVersion: function(callback) {
callNativeMethod(pluginNativeMethod.GET_CURRENT_VERSION, null, callback);
}
};

Expand Down

0 comments on commit f5cacec

Please sign in to comment.