Revision: 27844
          http://sourceforge.net/p/bibdesk/svn/27844
Author:   hofman
Date:     2022-08-27 13:45:31 +0000 (Sat, 27 Aug 2022)
Log Message:
-----------
only notify update without setting publications for shared group on 
authentication failure or cancel from sharing client, as we should not reload 
the publications

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

Modified: trunk/bibdesk/BDSKSharedGroup.m
===================================================================
--- trunk/bibdesk/BDSKSharedGroup.m     2022-08-27 06:30:18 UTC (rev 27843)
+++ trunk/bibdesk/BDSKSharedGroup.m     2022-08-27 13:45:31 UTC (rev 27844)
@@ -182,25 +182,30 @@
 #pragma mark notification handlers
 
 - (void)handleClientUpdatedNotification:(NSNotification *)notification {
-    NSData *pubsArchive = [client archivedPublications];
-    NSData *macrosArchive = [client archivedMacros];
-    NSArray *pubs = nil;
-    NSDictionary *macros = nil;
-    
-    [NSString setMacroResolverForUnarchiving:[self macroResolver]];
-    if (pubsArchive)
-        pubs = [NSKeyedUnarchiver unarchiveObjectWithData:pubsArchive];
-    if (macrosArchive)
-        macros = [NSKeyedUnarchiver unarchiveObjectWithData:macrosArchive];
-    [NSString setMacroResolverForUnarchiving:nil];
-    
-    // we set the macroResolver so we know the fields of this item may refer 
to it, so we can prevent scripting from adding this to the wrong document
-    [pubs setValue:macroResolver forKey:@"macroResolver"];
-    
     [self willChangeValueForKey:@"icon"];
     
-    [[self macroResolver] setMacroDefinitions:macros];
-    [self setPublications:pubs];
+    if ([[[notification userInfo] objectForKey:BDSKSharingClientFailedKey] 
boolValue]) {
+        // don't use setPublications: on authentication failure or cancel, as 
it will immediately get the publications again
+        [self notifyUpdate];
+    } else {
+        NSData *pubsArchive = [client archivedPublications];
+        NSData *macrosArchive = [client archivedMacros];
+        NSArray *pubs = nil;
+        NSDictionary *macros = nil;
+        
+        [NSString setMacroResolverForUnarchiving:[self macroResolver]];
+        if (pubsArchive)
+            pubs = [NSKeyedUnarchiver unarchiveObjectWithData:pubsArchive];
+        if (macrosArchive)
+            macros = [NSKeyedUnarchiver unarchiveObjectWithData:macrosArchive];
+        [NSString setMacroResolverForUnarchiving:nil];
+        
+        // we set the macroResolver so we know the fields of this item may 
refer to it, so we can prevent scripting from adding this to the wrong document
+        [pubs setValue:macroResolver forKey:@"macroResolver"];
+        
+        [[self macroResolver] setMacroDefinitions:macros];
+        [self setPublications:pubs];
+    }
     
     [self didChangeValueForKey:@"icon"];
 }

Modified: trunk/bibdesk/BDSKSharingClient.h
===================================================================
--- trunk/bibdesk/BDSKSharingClient.h   2022-08-27 06:30:18 UTC (rev 27843)
+++ trunk/bibdesk/BDSKSharingClient.h   2022-08-27 13:45:31 UTC (rev 27844)
@@ -38,6 +38,8 @@
 
 #import <Cocoa/Cocoa.h>
 
+extern NSString *BDSKSharingClientFailedKey;
+
 @class BDSKSharingClientServer;
 
 @interface BDSKSharingClient : NSObject {

Modified: trunk/bibdesk/BDSKSharingClient.m
===================================================================
--- trunk/bibdesk/BDSKSharingClient.m   2022-08-27 06:30:18 UTC (rev 27843)
+++ trunk/bibdesk/BDSKSharingClient.m   2022-08-27 13:45:31 UTC (rev 27844)
@@ -43,6 +43,8 @@
 #import "NSData_BDSKExtensions.h"
 #import "CFString_BDSKExtensions.h"
 
+NSString *BDSKSharingClientFailedKey = @"failed";
+
 static NSString *BDSKClientServiceNameForKeychain = @"BibDesk Sharing Access";
 
 typedef struct _BDSKSharingClientFlags {
@@ -159,7 +161,8 @@
     // we need to do this after setting the archivedPublications but before 
sending the notification
     [server setRetrieving:NO];
     
-    [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKSharingClientUpdatedNotification object:self];
+    NSDictionary *userInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:dictionary == nil], 
BDSKSharingClientFailedKey, nil];
+    [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKSharingClientUpdatedNotification object:self 
userInfo:userInfo];
 }
 
 - (BOOL)isRetrieving {
@@ -447,6 +450,10 @@
                 NSString *errorStr = [NSString stringWithFormat:@"Error 
reading shared data: %@", error];
                 @throw errorStr;
             }
+        } else {
+            OSMemoryBarrier();
+            if (flags.authenticationFailed == 0 && 
flags.canceledAuthentication == 0)
+                archive = [NSDictionary dictionary];
         }
         // use the main thread; this avoids an extra (un)archiving between 
threads and it ends up posting notifications for UI updates
         [[self serverOnMainThread] setArchivedPublicationsAndMacros:archive];

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