Revision: 27859
          http://sourceforge.net/p/bibdesk/svn/27859
Author:   hofman
Date:     2022-09-06 23:08:52 +0000 (Tue, 06 Sep 2022)
Log Message:
-----------
dispatch to main thread inside panel methods

Modified Paths:
--------------
    trunk/bibdesk/BDSKSharingClient.m

Modified: trunk/bibdesk/BDSKSharingClient.m
===================================================================
--- trunk/bibdesk/BDSKSharingClient.m   2022-09-06 23:01:38 UTC (rev 27858)
+++ trunk/bibdesk/BDSKSharingClient.m   2022-09-06 23:08:52 UTC (rev 27859)
@@ -252,17 +252,23 @@
 
 - (NSString *)passwordFromPanel;
 {
+    if ([NSThread isMainThread] == NO) {
+        __block NSString *password = nil;
+        dispatch_sync(dispatch_get_main_queue(), ^{ password = [self 
passwordFromPanel]; });
+        return password;
+    }
     NSAssert([NSThread isMainThread] == 1, @"password controller must be run 
from the main thread");
     return [BDSKPasswordController passwordFromPanelWithMessage:[NSString 
stringWithFormat:NSLocalizedString(@"Enter password for %@", @"Prompt for 
Password dialog"), [service name]]];
 }
 
-- (NSInteger)runAuthenticationFailedAlert;
+- (void)runAuthenticationFailedAlert;
 {
-    NSAssert([NSThread isMainThread] == 1, @"runAuthenticationFailedAlert must 
be run from the main thread");
-    NSAlert *alert = [[[NSAlert alloc] init] autorelease];
-    [alert setMessageText:NSLocalizedString(@"Authentication Failed", 
@"Message in alert dialog when authentication failed")];
-    [alert setInformativeText:[NSString 
stringWithFormat:NSLocalizedString(@"Incorrect password for BibDesk Sharing on 
server %@.  Reselect to try again.", @"Informative text in alert dialog"), 
[service name]]];
-    return [alert runModal];
+    dispatch_sync(dispatch_get_main_queue(), ^{
+        NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+        [alert setMessageText:NSLocalizedString(@"Authentication Failed", 
@"Message in alert dialog when authentication failed")];
+        [alert setInformativeText:[NSString 
stringWithFormat:NSLocalizedString(@"Incorrect password for BibDesk Sharing on 
server %@.  Reselect to try again.", @"Informative text in alert dialog"), 
[service name]]];
+        [alert runModal];
+    });
 }
 
 - (NSString *)passwordFromKeychain {
@@ -288,7 +294,7 @@
         return YES;
     }
     while ([self shouldKeepRunning] && uniqueIdentifier != nil) {
-        __block NSString *password = nil;
+        NSString *password = nil;
         BOOL fromPanel = NO;
         
         OSAtomicCompareAndSwap32Barrier(1, 0, &flags.canceledAuthentication);
@@ -302,9 +308,7 @@
         
         if (password == nil) {
             // run the prompt on the main thread
-            dispatch_sync(dispatch_get_main_queue(), ^{
-                password = [self passwordFromPanel];
-            });
+            password = [self passwordFromPanel];
             
             if (password == nil) {
                 // cancceled by user
@@ -326,11 +330,8 @@
             NSLog(@"%@: unable to authenticate with remote server %@", [self 
class], [service hostName]);
             OSAtomicCompareAndSwap32Barrier(0, 1, &flags.authenticationFailed);
             // don't show the alert when we couldn't authenticate when 
cleaning up
-            if ([self shouldKeepRunning]) {
-                dispatch_sync(dispatch_get_main_queue(), ^{
-                    [self runAuthenticationFailedAlert];
-                });
-            }
+            if ([self shouldKeepRunning])
+                [self runAuthenticationFailedAlert];
             return NO;
         }
         
@@ -354,7 +355,7 @@
     if (flags.needsAuthentication == 3) {
         // legacy server of version 0 expect authentication through this method
         
-        __block NSString *password = nil;
+        NSString *password = nil;
         
         OSAtomicCompareAndSwap32Barrier(1, 0, &flags.canceledAuthentication);
         
@@ -365,13 +366,7 @@
         if(password == nil && [self shouldKeepRunning]){
             
             // run the prompt on the main thread
-            if ([NSThread isMainThread]) {
-                password = [self passwordFromPanel];
-            } else {
-                dispatch_sync(dispatch_get_main_queue(), ^{
-                    password = [self passwordFromPanel];
-                });
-            }
+            password = [self passwordFromPanel];
             
             // retry from the keychain
             if (password){
@@ -454,11 +449,8 @@
                 if(flags.canceledAuthentication == 0){
                     OSAtomicCompareAndSwap32Barrier(0, 1, 
&flags.authenticationFailed);
                     // don't show the alert when we couldn't authenticate when 
cleaning up
-                    if([self shouldKeepRunning]){
-                        dispatch_sync(dispatch_get_main_queue(), ^{
-                            [self runAuthenticationFailedAlert];
-                        });
-                    }
+                    if([self shouldKeepRunning])
+                        [self runAuthenticationFailedAlert];
                 }
                 
             } else if([exception respondsToSelector:@selector(name)] && 
[[exception name] isEqual:NSGenericException]){

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to