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

Commit

Permalink
Added isUpdateAvailableForInstallation() method to JS module.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikDemyankov committed Apr 22, 2016
1 parent 1242c12 commit 8b1e1bc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/ios/HCPPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@
*/
- (void)jsRequestAppUpdate:(CDVInvokedUrlCommand *)command;

/**
* Check if new version was loaded and can be installed.
*
* @param command command with which the method is called
*/
- (void)jsIsUpdateAvailableForInstallation:(CDVInvokedUrlCommand *)command;

@end
16 changes: 15 additions & 1 deletion src/ios/HCPPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -751,11 +751,25 @@ - (void)jsRequestAppUpdate:(CDVInvokedUrlCommand *)command {
[_appUpdateRequestDialog show];
}

- (void)jsIsUpdateAvailableForInstallation:(CDVInvokedUrlCommand *)command {
NSDictionary *data = nil;
NSError *error = nil;
if (_pluginInternalPrefs.readyForInstallationReleaseVersionName.length) {
data = @{@"currentVersion": _pluginInternalPrefs.currentReleaseVersionName,
@"readyToInstallVersion": _pluginInternalPrefs.readyForInstallationReleaseVersionName};
} else {
error = [NSError errorWithCode:kHCPNothingToInstallErrorCode description:@"Nothing to install"];
}

CDVPluginResult *result = [CDVPluginResult pluginResultWithActionName:nil data:data error:error];
[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."];
CDVPluginResult *errorResult = [CDVPluginResult pluginResultWithActionName:eventName
applicationConfig:nil
data:nil
error:error];
[self.commandDelegate sendPluginResult:errorResult callbackId:callbackID];
}
Expand Down
17 changes: 15 additions & 2 deletions www/chcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var exec = require('cordova/exec'),
FETCH_UPDATE: 'jsFetchUpdate',
INSTALL_UPDATE: 'jsInstallUpdate',
CONFIGURE: 'jsConfigure',
REQUEST_APP_UPDATE: 'jsRequestAppUpdate'
REQUEST_APP_UPDATE: 'jsRequestAppUpdate',
IS_UPDATE_AVAILABLE_FOR_INSTALLATION: 'jsIsUpdateAvailableForInstallation'
};

// Called when Cordova is ready for work.
Expand Down Expand Up @@ -239,10 +240,22 @@ var chcp = {
/**
* Install update if there is anything to install.
*
* @param (Callback(error)) callback - called when native side finishes installation process
* @param {Callback(error)} callback - called when native side finishes installation process
*/
installUpdate: function(callback) {
callNativeMethod(pluginNativeMethod.INSTALL_UPDATE, null, callback);
},

/**
* Check if update was loaded and ready to be installed.
* If update was loaded and can be installed - "data" property of the callback will contain the name of the current version and the name of the new
* version.
* If not - "error" will contain code chcp.error.NOTHING_TO_INSTALL.
*
* @param {Callback(error, data)} callback - called, when information is retrieved from the native side.
*/
isUpdateAvailableForInstallation: function(callback) {
callNativeMethod(pluginNativeMethod.IS_UPDATE_AVAILABLE_FOR_INSTALLATION, null, callback);
}
};

Expand Down

0 comments on commit 8b1e1bc

Please sign in to comment.