From 9a86761dab1d5ae90e4272960718a660a34623bf Mon Sep 17 00:00:00 2001 From: Jakub Suder Date: Mon, 24 Feb 2014 13:57:47 +0100 Subject: [PATCH] [#280] added bitcoin.getApplication --- Hive/Backend/HIApplicationsManager.h | 1 + Hive/Backend/HIApplicationsManager.m | 7 +++++++ Hive/Controllers/HIAppRuntimeBridge.m | 19 ++++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Hive/Backend/HIApplicationsManager.h b/Hive/Backend/HIApplicationsManager.h index 2d3fa94b..3d66bea4 100644 --- a/Hive/Backend/HIApplicationsManager.h +++ b/Hive/Backend/HIApplicationsManager.h @@ -26,6 +26,7 @@ extern const NSInteger HIApplicationManagerInvalidAppFileError; - (BOOL)requestLocalAppInstallation:(NSURL *)applicationURL showAppsPage:(BOOL)showAppsPage error:(NSError **)error; - (void)requestRemoteAppInstallation:(NSURL *)remoteURL onCompletion:(void (^)(BOOL, NSError *))completionBlock; - (BOOL)hasApplicationOfId:(NSString *)applicationId; +- (HIApplication *)getApplicationById:(NSString *)applicationId; - (NSDictionary *)applicationMetadata:(NSURL *)applicationPath; - (void)preinstallApps; - (void)rebuildAppsList; diff --git a/Hive/Backend/HIApplicationsManager.m b/Hive/Backend/HIApplicationsManager.m index 427f610e..11f67c49 100644 --- a/Hive/Backend/HIApplicationsManager.m +++ b/Hive/Backend/HIApplicationsManager.m @@ -47,6 +47,13 @@ - (BOOL)hasApplicationOfId:(NSString *)applicationId { return (count > 0); } +- (HIApplication *)getApplicationById:(NSString *)applicationId { + NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:HIApplicationEntity]; + request.predicate = [NSPredicate predicateWithFormat:@"id == %@", applicationId]; + + return [[DBM executeFetchRequest:request error:NULL] firstObject]; +} + - (void)removeAllApps { NSError *error = nil; NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:HIApplicationEntity]; diff --git a/Hive/Controllers/HIAppRuntimeBridge.m b/Hive/Controllers/HIAppRuntimeBridge.m index 210a2ce3..1313f56d 100644 --- a/Hive/Controllers/HIAppRuntimeBridge.m +++ b/Hive/Controllers/HIAppRuntimeBridge.m @@ -21,7 +21,7 @@ // MINOR version must be incremented when new API features are added // MAJOR version must be incremented when existing API features are changed incompatibly. static const NSUInteger API_VERSION_MAJOR = 0; -static const NSUInteger API_VERSION_MINOR = 1; +static const NSUInteger API_VERSION_MINOR = 2; static NSString * const kHIAppRuntimeBridgeErrorDomain = @"HIAppRuntimeBridgeErrorDomain"; static const NSInteger kHIAppRuntimeBridgeParsingError = -1000; @@ -76,6 +76,7 @@ + (NSDictionary *)selectorMap { @"getSystemInfoWithCallback:": @"getSystemInfo", @"makeProxiedRequestToURL:options:": @"makeRequest", @"installAppFromURL:callback:": @"installApp", + @"applicationDataById:callback:": @"getApplication", @"addExchangeRateListener:": @"addExchangeRateListener", @"removeExchangeRateListener:": @"removeExchangeRateListener", @"updateExchangeRateForCurrency:": @"updateExchangeRate", @@ -246,6 +247,22 @@ - (void)transactionWithHash:(NSString *)hash callback:(WebScriptObject *)callbac [self callCallbackMethod:callback withArguments:&jsonValue count:1]; } +- (void)applicationDataById:(NSString *)applicationId callback:(WebScriptObject *)callback { + ValidateArgument(NSString, applicationId); + ValidateArgument(WebScriptObject, callback); + + NSDictionary *manifest = [[[HIApplicationsManager sharedManager] getApplicationById:applicationId] manifest]; + JSValueRef value; + + if (manifest) { + value = [self valueObjectFromDictionary:manifest]; + } else { + value = JSValueMakeNull(self.context); + } + + [self callCallbackMethod:callback withArguments:&value count:1]; +} + - (void)getUserInformationWithCallback:(WebScriptObject *)callback { ValidateArgument(WebScriptObject, callback);