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

Javascript method to get the name of the current version #170

Merged
merged 1 commit into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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