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

Commit

Permalink
Handle fetch update options: config-url and request headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikDemyankov committed May 9, 2016
1 parent f44d362 commit e31be1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
3 changes: 0 additions & 3 deletions src/ios/HCPPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,4 @@
*/
- (void)jsIsUpdateAvailableForInstallation:(CDVInvokedUrlCommand *)command;


@property (nonatomic, retain) NSDictionary* headers;

This comment has been minimized.

Copy link
@davidovich

davidovich May 10, 2016

Contributor

@nikDemyankov In my use case, where I use cordova embedded in a bigger project (to manage only one or two dynamic views), I find it practical to have a global property that I set from native side (The native side has the login credentials for example, and I fetch the chcp plugin and set the headers. Can this notion be kept ?

This comment has been minimized.

Copy link
@nikDemyankov

nikDemyankov May 10, 2016

Author Member

@davidovich Didn't think about that use case. Sure, thanks for the idea.


@end
24 changes: 14 additions & 10 deletions src/ios/HCPPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import "HCPAssetsFolderHelper.h"
#import "NSError+HCPExtension.h"
#import "HCPCleanupHelper.h"
#import "NSDictionary+HCPFetchUpdateOptions.h"

@interface HCPPlugin() {
HCPFilesStructure *_filesStructure;
Expand Down Expand Up @@ -160,17 +161,23 @@ - (void)doLocalInit {
*
* @return <code>YES</code> if download process started; <code>NO</code> otherwise
*/
- (BOOL)_fetchUpdate:(NSString *)callbackId {
- (BOOL)_fetchUpdate:(NSString *)callbackId withOptions:(NSDictionary *)options {
if (!_isPluginReadyForWork) {
return NO;
}

NSURL *configURL = [options configURL];
if (!configURL) {
configURL = _pluginXmlConfig.configUrl;
}
NSDictionary<NSString *, NSString *> *headers = [options requestHeaders];

NSError *error = nil;
[[HCPUpdateLoader sharedInstance] downloadUpdateWithConfigUrl:_pluginXmlConfig.configUrl
[[HCPUpdateLoader sharedInstance] downloadUpdateWithConfigUrl:configURL
currentWebVersion:_pluginInternalPrefs.currentReleaseVersionName
currentNativeVersion:_pluginXmlConfig.nativeInterfaceVersion
error:&error
headers:self.headers];
headers:headers];
if (error) {
if (callbackId) {
CDVPluginResult *errorResult = [CDVPluginResult pluginResultWithActionName:kHCPUpdateDownloadErrorEvent
Expand Down Expand Up @@ -465,7 +472,7 @@ - (void)onAssetsInstalledOnExternalStorageEvent:(NSNotification *)notification {
if (_pluginXmlConfig.isUpdatesAutoDownloadAllowed &&
![HCPUpdateLoader sharedInstance].isDownloadInProgress &&
![HCPUpdateInstaller sharedInstance].isInstallationInProgress) {
[self _fetchUpdate:nil];
[self _fetchUpdate:nil withOptions:nil];
}
}

Expand Down Expand Up @@ -695,7 +702,7 @@ - (void)jsInitPlugin:(CDVInvokedUrlCommand *)command {
if (_pluginXmlConfig.isUpdatesAutoDownloadAllowed &&
![HCPUpdateLoader sharedInstance].isDownloadInProgress &&
![HCPUpdateInstaller sharedInstance].isInstallationInProgress) {
[self _fetchUpdate:nil];
[self _fetchUpdate:nil withOptions:nil];
}
}

Expand All @@ -718,12 +725,9 @@ - (void)jsFetchUpdate:(CDVInvokedUrlCommand *)command {
[self sendPluginNotReadyToWorkMessageForEvent:kHCPUpdateDownloadErrorEvent callbackID:command.callbackId];
}

// headers may be passed as first argument, as a dict
if (command.arguments.count == 1) {
self.headers = command.arguments[0];
}
NSDictionary *options = command.arguments.count ? command.arguments[0] : nil;

[self _fetchUpdate:command.callbackId];
[self _fetchUpdate:command.callbackId withOptions:options];
}

- (void)jsInstallUpdate:(CDVInvokedUrlCommand *)command {
Expand Down

0 comments on commit e31be1d

Please sign in to comment.