Skip to content

Commit 394ca19

Browse files
committed
Always run nsurlconnection requests on the main thread
1 parent c878fc7 commit 394ca19

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

Info.plist

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
<key>CFBundlePackageType</key>
2020
<string>BNDL</string>
2121
<key>CFBundleShortVersionString</key>
22-
<string>1.0.2</string>
22+
<string>1.0.3</string>
2323
<key>CFBundleVersion</key>
24-
<string>A4</string>
24+
<string>A5</string>
2525
<key>NSPrincipalClass</key>
2626
<string>QSTwitterUtil</string>
2727
<key>QSActions</key>
@@ -148,17 +148,17 @@
148148
&lt;p&gt;Enables posting of tweets, messages and direct messages to Twitter from within Quicksilver&lt;/p&gt;
149149
&lt;h4&gt;Setup&lt;/h4&gt;
150150
&lt;p&gt;&lt;strong&gt;Twitter Login&lt;/strong&gt;&lt;/p&gt;
151-
&lt;p&gt;In order to post tweets from Quicksilver, you must authenticate Quicksilver with your Twitter account. Do this by going to the &lt;a href="qs://preferences#QSTwitterPrefPane"&gt;Twitter plugin preferences&lt;/a&gt; and clicking the 'Sign In' button.
152-
Your Twitter login details are stored securely in OS X's Keychain.app for access across computer and app relaunches. You can remove the login details at any time by clicking the 'Sign Out' button in the Twitter preference pane.&lt;/p&gt;
151+
&lt;p&gt;In order to post tweets from Quicksilver, you must authenticate Quicksilver with your Twitter account. Do this by going to the &lt;a href=&quot;qs://preferences#QSTwitterPrefPane&quot;&gt;Twitter plugin preferences&lt;/a&gt; and clicking the &apos;Sign In&apos; button.
152+
Your Twitter login details are stored securely in OS X&apos;s Keychain.app for access across computer and app relaunches. You can remove the login details at any time by clicking the &apos;Sign Out&apos; button in the Twitter preference pane.&lt;/p&gt;
153153
&lt;p&gt;&lt;strong&gt;Twitter Contacts&lt;/strong&gt;&lt;/p&gt;
154-
&lt;p&gt;Some actions require a contact to send a direct message/message to. These actions accept both text (e.g. in the form '@Twitter') or a contact from your Address Book (requires the Contacts plugin). In order to use contacts directly, you must ensure that your contacts have their Twitter username field set in Address Book.app / Contacts.app&lt;/p&gt;
154+
&lt;p&gt;Some actions require a contact to send a direct message/message to. These actions accept both text (e.g. in the form &apos;@Twitter&apos;) or a contact from your Address Book (requires the Contacts plugin). In order to use contacts directly, you must ensure that your contacts have their Twitter username field set in Address Book.app / Contacts.app&lt;/p&gt;
155155
&lt;h4&gt;Actions&lt;/h4&gt;
156156
&lt;p&gt;&lt;strong&gt;Send Tweet&lt;/strong&gt;&lt;/p&gt;
157-
&lt;p&gt;The 'Send Tweet' action takes text in Quicksilver's 1st pane and posts a tweet directly to Twitter&lt;/p&gt;
157+
&lt;p&gt;The &apos;Tweet&apos; action takes text in Quicksilver&apos;s 1st pane and posts a tweet directly to Twitter&lt;/p&gt;
158158
&lt;p&gt;&lt;strong&gt;Send Tweet… / Send Tweet To…&lt;/strong&gt;&lt;/p&gt;
159-
&lt;p&gt;Use the 'Send Tweet…' action to send a contact selected in Quicksilver's 1st pane (either a contact from your Contacts list or a username entered as text) the text entered in Quicksilver's 3rd pane. The 'Send Tweet To…' action works in reverse, taking text in Quicksilver's 1st pane and a contact in Quicksilver's 3rd pane.&lt;/p&gt;
159+
&lt;p&gt;Use the &apos;Tweet…&apos; action to send a contact selected in Quicksilver&apos;s 1st pane (either a contact from your Contacts list or a username entered as text) the text entered in Quicksilver&apos;s 3rd pane. The &apos;Send Tweet To…&apos; action works in reverse, taking text in Quicksilver&apos;s 1st pane and a contact in Quicksilver&apos;s 3rd pane.&lt;/p&gt;
160160
&lt;p&gt;&lt;strong&gt;Send Direct Message… / Send Direct Message To…&lt;/strong&gt;&lt;/p&gt;
161-
&lt;p&gt;'Send Direct Message…' can be used to send a contact (selected in Quicksilver's 1st pane) a direct message entered as text in Quicksilver's 3rd pane. The 'Send Direct Message To…' action works in reverse.&lt;/p&gt;</string>
161+
&lt;p&gt;&apos;Send Direct Message…&apos; can be used to send a contact (selected in Quicksilver&apos;s 1st pane) a direct message entered as text in Quicksilver&apos;s 3rd pane. The &apos;Send Direct Message To…&apos; action works in reverse.&lt;/p&gt;</string>
162162
<key>icon</key>
163163
<string>QSTwit</string>
164164
<key>relatedBundles</key>

QSTwitter.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
CDB3CD1516FD61CE00DF06BF /* GTMMIMEDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = CDB3CD0C16FD61CD00DF06BF /* GTMMIMEDocument.m */; };
3030
CDB3CD1616FD61CE00DF06BF /* GTMReadMonitorInputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = CDB3CD0E16FD61CE00DF06BF /* GTMReadMonitorInputStream.m */; };
3131
CDB3CD1816FDD79800DF06BF /* YAJL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDB3CD1716FDD79800DF06BF /* YAJL.framework */; };
32+
CDB485A8176B514B0093B282 /* QSFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7F35FF3E07F9ACD90056051D /* QSFoundation.framework */; };
3233
CDB497CE1718E49C0055F0C4 /* YAJL.framework in Copy Files */ = {isa = PBXBuildFile; fileRef = CDB3CD1716FDD79800DF06BF /* YAJL.framework */; };
3334
CDE38B231702ED2D007A6BC1 /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDE38B221702ED2D007A6BC1 /* AddressBook.framework */; };
3435
CDE38B241702ED45007A6BC1 /* QSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7F35FF3C07F9ACD90056051D /* QSCore.framework */; };
@@ -113,6 +114,7 @@
113114
35857B6810E213AB0054319B /* SystemConfiguration.framework in Frameworks */,
114115
CDB3CCFB16FD5EB600DF06BF /* Security.framework in Frameworks */,
115116
CDB3CCE416FD58A600DF06BF /* QSInterface.framework in Frameworks */,
117+
CDB485A8176B514B0093B282 /* QSFoundation.framework in Frameworks */,
116118
CDE38B241702ED45007A6BC1 /* QSCore.framework in Frameworks */,
117119
CDB3CD1816FDD79800DF06BF /* YAJL.framework in Frameworks */,
118120
);

QSTwitterUtil.m

+21-17
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,20 @@ -(QSObject *)tweet:(NSString *)message toUser:(NSString*)user {
8383
message = (NSString*) CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)message, NULL,CFSTR(":/?#[]@!$&’'()*+,;=."), kCFStringEncodingUTF8);
8484
[request setHTTPBody:[[NSString stringWithFormat:@"%@%@=%@", user ? [NSString stringWithFormat:@"screen_name=%@&", user] : @"" , user ? @"text" : @"status", message] dataUsingEncoding:NSUTF8StringEncoding]];
8585
[authentication authorizeRequest:request];
86-
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *resp, NSData *data, NSError *err) {
87-
if (err != nil) {
88-
[self twitterNotify:[NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"[Error] %@", nil, [NSBundle bundleForClass:[self class]], @"error sending tweet message"), [err localizedDescription]]];
89-
} else {
90-
NSDictionary *response = [data yajl_JSON];
91-
if ([response valueForKey:@"text"]) {
92-
[self twitterNotify:NSLocalizedStringFromTableInBundle(@"Tweet sent successfully", nil, [NSBundle bundleForClass:[self class]], nil)];
86+
runOnMainQueueSync(^{
87+
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *resp, NSData *data, NSError *err) {
88+
if (err != nil) {
89+
[self twitterNotify:[NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"[Error] %@", nil, [NSBundle bundleForClass:[self class]], @"error sending tweet message"), [err localizedDescription]]];
9390
} else {
94-
[self twitterNotify:[NSString stringWithFormat:@"[ERROR] %@",[response valueForKey:@"error"]]];
91+
NSDictionary *response = [data yajl_JSON];
92+
if ([response valueForKey:@"text"]) {
93+
[self twitterNotify:NSLocalizedStringFromTableInBundle(@"Tweet sent successfully", nil, [NSBundle bundleForClass:[self class]], nil)];
94+
} else {
95+
[self twitterNotify:[NSString stringWithFormat:@"[ERROR] %@",[response valueForKey:@"error"]]];
96+
}
9597
}
96-
}
97-
}];
98+
}];
99+
});
98100
return nil;
99101

100102
}
@@ -153,13 +155,15 @@ - (void)windowController:(GTMOAuthWindowController *)windowController
153155
-(void)getCredentials {
154156
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:kTwitterUserCredURL];
155157
[authentication authorizeRequest:request];
156-
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *err) {
157-
if (data) {
158-
[self.prefPane updateCredentials:[data yajl_JSON]];
159-
} else {
160-
[self.prefPane updateCredentials:@{@"name": [NSString stringWithFormat:@"[ERROR]: %@",[err localizedDescription]]}];
161-
}
162-
}];
158+
runOnMainQueueSync(^{
159+
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *err) {
160+
if (data) {
161+
[self.prefPane updateCredentials:[data yajl_JSON]];
162+
} else {
163+
[self.prefPane updateCredentials:@{@"name": [NSString stringWithFormat:@"[ERROR]: %@",[err localizedDescription]]}];
164+
}
165+
}];
166+
});
163167
}
164168

165169
- (BOOL)isSignedIn {

0 commit comments

Comments
 (0)