Manage the login in the OSX Fast User Switch mode
authorClaudio Bisegni <Claudio.Bisegni@lnf.infn.it>
Tue, 15 Sep 2009 07:29:21 +0000 (09:29 +0200)
committerDerrick Brashear <shadow|account-1000005@unknown>
Fri, 18 Sep 2009 12:20:32 +0000 (05:20 -0700)
AFSBackgrounder has been update to get notification for switch in/off in the "Fast User Switch" mode, and in switch in it try to get tokens.

Reviewed-on: http://gerrit.openafs.org/460
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/platform/DARWIN/AFSPreference/AFSBackgrounder/AFSBackgrounderDelegate.h
src/platform/DARWIN/AFSPreference/AFSBackgrounder/AFSBackgrounderDelegate.m

index aa2d852..ef5707e 100644 (file)
@@ -47,6 +47,7 @@
 - (void)releaseToken:(id)sender;
 - (void)updateAfsStatus:(NSTimer*)timer;
 - (void)klogUserEven:(NSNotification *)notification;
+- (void)switchHandler:(NSNotification*) notification;
 - (void)chageMenuVisibility:(NSNotification *)notification;
 - (NSImage*)getImageFromBundle:(NSString*)fileName fileExt:(NSString*)ext;
 - (NSImage*)imageToRender;
index 77251d7..e108254 100644 (file)
                                                                                                                   selector:@selector(afsVolumeMountChange:) 
                                                                                                                           name:NSWorkspaceDidUnmountNotification object:nil];
        
+       [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
+                                                                                                                  selector:@selector(switchHandler:)
+                                                                                                                          name:NSWorkspaceSessionDidBecomeActiveNotification
+                                                                                                                        object:nil];
+       
+    [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
+                                                                                                                  selector:@selector(switchHandler:)
+                                                                                                                          name:NSWorkspaceSessionDidResignActiveNotification
+                                                                                                                        object:nil];
+       
        //try to see if we need tho show the menu at startup
        
        [self setStatusItem:[showStatusMenu boolValue]];
        if(noTokenImage) [noTokenImage release];
        
        // Unregister for preference change
+       [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:NSWorkspaceSessionDidBecomeActiveNotification object:nil];
+       [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:NSWorkspaceSessionDidResignActiveNotification object:nil];
        [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:kAFSMenuExtraID object:kPrefChangeNotification];
        [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:kAFSMenuExtraID object:kMExtraAFSStateChange];
        [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:kAFSMenuExtraID object:kMExtraAFSMenuChangeState];
        if(afsMngr) [afsMngr release];
        return NSTerminateNow;
 }
+#pragma mark Notification Handler
 // -------------------------------------------------------------------------------
 //  -(void) readPreferenceFile
 // -------------------------------------------------------------------------------
 // -------------------------------------------------------------------------------
 //  - (void)chageMenuVisibility:(NSNotification *)notification
 // -------------------------------------------------------------------------------
-/**/
 - (void)chageMenuVisibility:(NSNotification *)notification {
        [self readPreferenceFile:nil];
        [self setStatusItem:[showStatusMenu boolValue]];
 }
 
 // -------------------------------------------------------------------------------
+// - (void) switchHandler:(NSNotification*) notification
+// -------------------------------------------------------------------------------
+- (void) switchHandler:(NSNotification*) notification
+{
+    if ([[notification name] isEqualToString:NSWorkspaceSessionDidResignActiveNotification])
+    {
+        // user has switched out
+    }
+    else
+    {
+               // user has switched in
+               NSLog(@"User has switch in again");
+               if([aklogTokenAtLogin boolValue] && afsState && !gotToken) {
+                       NSLog(@"Proceed to get token");
+                       //check if we must get the aklog at logint(first run of backgrounder
+                       [self getToken:nil];
+               }
+    }
+}
+// -------------------------------------------------------------------------------
+//  -(void) afsVolumeMountChange - Track for mount unmount afs volume
+// -------------------------------------------------------------------------------
+- (void) afsVolumeMountChange:(NSNotification *)notification{
+       [self updateAfsStatus:nil];
+}
+
+
+// -------------------------------------------------------------------------------
+//  -(void) klogUserEven
+// -------------------------------------------------------------------------------
+-(void) klogUserEven:(NSNotification *)notification
+{
+       if(credentialMenuController) {
+               [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:kAFSMenuExtraID object:kLogWindowClosed];
+               [credentialMenuController closeWindow];
+               [credentialMenuController release];
+               credentialMenuController = nil;
+       }
+       //Send notification to PreferencePane
+       [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAfsCommanderID object:kMenuExtraEventOccured];
+       
+       [self updateAfsStatus:nil];
+}
+#pragma mark Action
+// -------------------------------------------------------------------------------
 //  - (void)startStopAfs:(id)sender
 // -------------------------------------------------------------------------------
 - (void)startStopAfs:(id)sender
 
 
 // -------------------------------------------------------------------------------
-//  -(void) afsVolumeMountChange - Track for mount unmount afs volume
-// -------------------------------------------------------------------------------
-- (void) afsVolumeMountChange:(NSNotification *)notification{
-       [self updateAfsStatus:nil];
-}
-
-// -------------------------------------------------------------------------------
 //  -(void) updateAfsStatus
 // -------------------------------------------------------------------------------
 - (void)updateAfsStatus:(NSTimer*)timer
 }
 
 // -------------------------------------------------------------------------------
-//  -(void) klogUserEven
-// -------------------------------------------------------------------------------
--(void) klogUserEven:(NSNotification *)notification
-{
-       if(credentialMenuController) {
-               [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:kAFSMenuExtraID object:kLogWindowClosed];
-               [credentialMenuController closeWindow];
-               [credentialMenuController release];
-               credentialMenuController = nil;
-       }
-       //Send notification to PreferencePane
-       [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAfsCommanderID object:kMenuExtraEventOccured];
-       
-       [self updateAfsStatus:nil];
-}
-#pragma mark Operational Function
-// -------------------------------------------------------------------------------
 //  startTimer:
 // -------------------------------------------------------------------------------
 - (void)startTimer{