Skip to content

Commit 58a0b61

Browse files
Merge pull request kishikawakatsumi#2 from kishikawakatsumi/social
Supports `Social.framework`.
2 parents e78716e + 4096573 commit 58a0b61

26 files changed

Lines changed: 554 additions & 23 deletions

Classes/JSBScriptingSupport.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,13 @@ + (id)require:(NSString *)name
156156

157157
+ (void)dispatch_async:(id)queue block:(JSValue *)function
158158
{
159+
JSContext *context = [JSContext currentContext];
160+
id currentSelf = context[@"self"];
161+
159162
dispatch_block_t block = NULL;
160163
if (!function.isUndefined) {
161164
block = ^() {
162-
[function callWithArguments:nil];
165+
dispatchFunction(currentSelf, function, nil);
163166
};
164167
}
165168

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// ACAccountStore+JavaScriptBridge.h
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/05.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import <Accounts/Accounts.h>
10+
11+
@interface ACAccountStore (JavaScriptBridge)
12+
13+
@end
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//
2+
// ACAccountStore+JavaScriptBridge.m
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/05.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import "ACAccountStore+JavaScriptBridge.h"
10+
#import "JSBMessageForwarding.h"
11+
12+
@implementation ACAccountStore (JavaScriptBridge)
13+
14+
#pragma clang diagnostic push
15+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
16+
17+
- (void)__saveAccount:(ACAccount *)account withCompletionHandler:(JSValue *)handlerFunction
18+
{
19+
JSContext *context = [JSContext currentContext];
20+
id currentSelf = context[@"self"];
21+
22+
ACAccountStoreSaveCompletionHandler completionHandler = NULL;
23+
if (!handlerFunction.isUndefined) {
24+
completionHandler = ^(BOOL success, NSError *error) {
25+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
26+
[parameters addObject:@(success)];
27+
if (error) {
28+
[parameters addObject:error];
29+
} else {
30+
[parameters addObject:[NSNull null]];
31+
}
32+
33+
dispatchFunction(currentSelf, handlerFunction, parameters);
34+
};
35+
}
36+
37+
[self saveAccount:account withCompletionHandler:completionHandler];
38+
}
39+
40+
- (void)__requestAccessToAccountsWithType:(ACAccountType *)accountType
41+
withCompletionHandler:(JSValue *)handlerFunction
42+
{
43+
JSContext *context = [JSContext currentContext];
44+
id currentSelf = context[@"self"];
45+
46+
ACAccountStoreRequestAccessCompletionHandler handler = NULL;
47+
if (!handlerFunction.isUndefined) {
48+
handler = ^(BOOL granted, NSError *error) {
49+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
50+
[parameters addObject:@(granted)];
51+
if (error) {
52+
[parameters addObject:error];
53+
} else {
54+
[parameters addObject:[NSNull null]];
55+
}
56+
57+
dispatchFunction(currentSelf, handlerFunction, parameters);
58+
};
59+
}
60+
61+
[self requestAccessToAccountsWithType:accountType withCompletionHandler:handler];
62+
}
63+
64+
- (void)__requestAccessToAccountsWithType:(ACAccountType *)accountType
65+
options:(NSDictionary *)options
66+
completion:(JSValue *)completionFunction
67+
{
68+
JSContext *context = [JSContext currentContext];
69+
id currentSelf = context[@"self"];
70+
71+
ACAccountStoreRequestAccessCompletionHandler completion = NULL;
72+
if (!completionFunction.isUndefined) {
73+
completion = ^(BOOL granted, NSError *error) {
74+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
75+
[parameters addObject:@(granted)];
76+
if (error) {
77+
[parameters addObject:error];
78+
} else {
79+
[parameters addObject:[NSNull null]];
80+
}
81+
82+
dispatchFunction(currentSelf, completionFunction, parameters);
83+
};
84+
}
85+
86+
[self requestAccessToAccountsWithType:accountType options:options completion:completion];
87+
}
88+
89+
- (void)__renewCredentialsForAccount:(ACAccount *)account completion:(JSValue *)handlerFunction
90+
{
91+
JSContext *context = [JSContext currentContext];
92+
id currentSelf = context[@"self"];
93+
94+
ACAccountStoreCredentialRenewalHandler completionHandler = NULL;
95+
if (!handlerFunction.isUndefined) {
96+
completionHandler = ^(ACAccountCredentialRenewResult renewResult, NSError *error) {
97+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
98+
[parameters addObject:@(renewResult)];
99+
if (error) {
100+
[parameters addObject:error];
101+
} else {
102+
[parameters addObject:[NSNull null]];
103+
}
104+
105+
dispatchFunction(currentSelf, handlerFunction, parameters);
106+
};
107+
}
108+
109+
[self renewCredentialsForAccount:account completion:completionHandler];
110+
}
111+
112+
- (void)__removeAccount:(ACAccount *)account withCompletionHandler:(JSValue *)handlerFunction
113+
{
114+
JSContext *context = [JSContext currentContext];
115+
id currentSelf = context[@"self"];
116+
117+
ACAccountStoreRemoveCompletionHandler completionHandler = NULL;
118+
if (!handlerFunction.isUndefined) {
119+
completionHandler = ^(BOOL success, NSError *error) {
120+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
121+
[parameters addObject:@(success)];
122+
if (error) {
123+
[parameters addObject:error];
124+
} else {
125+
[parameters addObject:[NSNull null]];
126+
}
127+
128+
dispatchFunction(currentSelf, handlerFunction, parameters);
129+
};
130+
}
131+
132+
[self removeAccount:account withCompletionHandler:completionHandler];
133+
}
134+
135+
#pragma clang diagnostic pop
136+
137+
@end

Classes/Private/ALAssetsGroup+JavaScriptBridge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// JavaScriptBridge
44
//
55
// Created by kishikawa katsumi on 2014/01/05.
6-
// Copyright (c) 2014年 kishikawa katsumi. All rights reserved.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
77
//
88

99
#import <AssetsLibrary/AssetsLibrary.h>

Classes/Private/ALAssetsGroup+JavaScriptBridge.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// JavaScriptBridge
44
//
55
// Created by kishikawa katsumi on 2014/01/05.
6-
// Copyright (c) 2014年 kishikawa katsumi. All rights reserved.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
77
//
88

99
#import "ALAssetsGroup+JavaScriptBridge.h"

Classes/Private/JSBMessageForwarding.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// JavaScriptBridge
44
//
55
// Created by kishikawa katsumi on 2014/01/05.
6-
// Copyright (c) 2014年 kishikawa katsumi. All rights reserved.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
77
//
88

99
#import "JSBMessageForwarding.h"
@@ -294,6 +294,7 @@ void forwardInvocation(id self, SEL _cmd, NSInvocation *invocation)
294294
invokeSuper(invocation);
295295
}
296296

297+
id currentSelf = context[@"self"];
297298
context[@"self"] = self;
298299

299300
NSString *propertyName = propertyNameFromSelector(invocation.selector);
@@ -306,7 +307,7 @@ void forwardInvocation(id self, SEL _cmd, NSInvocation *invocation)
306307
setReturnValue(returnValue, invocation);
307308
}
308309

309-
context[@"self"] = nil;
310+
context[@"self"] = currentSelf;
310311
}
311312

312313
NSMethodSignature *methodSignatureForSelector(id self, SEL _cmd, SEL selector)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// NSURLConnection+JavaScriptBridge.h
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/06.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface NSURLConnection (JavaScriptBridge)
12+
13+
@end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// NSURLConnection+JavaScriptBridge.m
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/06.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import "NSURLConnection+JavaScriptBridge.h"
10+
#import "JSBMessageForwarding.h"
11+
12+
@implementation NSURLConnection (JavaScriptBridge)
13+
14+
+ (void)__sendAsynchronousRequest:(NSURLRequest *)request
15+
queue:(NSOperationQueue *)queue
16+
completionHandler:(JSValue *)handlerFunction
17+
{
18+
JSContext *context = [JSContext currentContext];
19+
id currentSelf = context[@"self"];
20+
21+
void(^completionHandler)(NSURLResponse *response , NSData *data , NSError *connectionError) = NULL;
22+
if (!handlerFunction.isUndefined) {
23+
completionHandler = ^(NSURLResponse *response , NSData *data , NSError *connectionError) {
24+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
25+
if (response) {
26+
[parameters addObject:response];
27+
} else {
28+
[parameters addObject:[NSNull null]];
29+
}
30+
if (data) {
31+
[parameters addObject:data];
32+
} else {
33+
[parameters addObject:[NSNull null]];
34+
}
35+
if (connectionError) {
36+
[parameters addObject:connectionError];
37+
} else {
38+
[parameters addObject:[NSNull null]];
39+
}
40+
41+
dispatchFunction(currentSelf, handlerFunction, parameters);
42+
};
43+
}
44+
45+
[self sendAsynchronousRequest:request queue:queue completionHandler:completionHandler];
46+
}
47+
48+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// SLComposeViewController+JavaScriptBridge.h
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/05.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import <Social/Social.h>
10+
11+
@interface SLComposeViewController (JavaScriptBridge)
12+
13+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// SLComposeViewController+JavaScriptBridge.m
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/05.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import "SLComposeViewController+JavaScriptBridge.h"
10+
11+
@implementation SLComposeViewController (JavaScriptBridge)
12+
13+
@end

0 commit comments

Comments
 (0)