From 89d1feb2e41ee2bcb8da1cc0cb12f1a32a41c742 Mon Sep 17 00:00:00 2001 From: Claudio Bisegni Date: Tue, 15 Sep 2009 09:29:21 +0200 Subject: [PATCH] Manage the login in the OSX Fast User Switch mode 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 Tested-by: Derrick Brashear (cherry picked from commit 1ea845ebc953bb49afc354afe036f7f01cd05db8) Change-Id: I274150b9c048f2e13c62f2fdf148059ffaf35113 Reviewed-on: http://gerrit.openafs.org/964 --- .../AFSBackgrounder/AFSBackgrounderDelegate.h | 1 + .../AFSBackgrounder/AFSBackgrounderDelegate.m | 83 +++++++++++++------ 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/src/platform/DARWIN/AFSPreference/AFSBackgrounder/AFSBackgrounderDelegate.h b/src/platform/DARWIN/AFSPreference/AFSBackgrounder/AFSBackgrounderDelegate.h index aa2d85275..ef5707e20 100644 --- a/src/platform/DARWIN/AFSPreference/AFSBackgrounder/AFSBackgrounderDelegate.h +++ b/src/platform/DARWIN/AFSPreference/AFSBackgrounder/AFSBackgrounderDelegate.h @@ -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; diff --git a/src/platform/DARWIN/AFSPreference/AFSBackgrounder/AFSBackgrounderDelegate.m b/src/platform/DARWIN/AFSPreference/AFSBackgrounder/AFSBackgrounderDelegate.m index 77251d799..e10825476 100644 --- a/src/platform/DARWIN/AFSPreference/AFSBackgrounder/AFSBackgrounderDelegate.m +++ b/src/platform/DARWIN/AFSPreference/AFSBackgrounder/AFSBackgrounderDelegate.m @@ -70,6 +70,16 @@ 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]]; @@ -92,6 +102,8 @@ 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]; @@ -106,6 +118,7 @@ if(afsMngr) [afsMngr release]; return NSTerminateNow; } +#pragma mark Notification Handler // ------------------------------------------------------------------------------- // -(void) readPreferenceFile // ------------------------------------------------------------------------------- @@ -141,12 +154,56 @@ // ------------------------------------------------------------------------------- // - (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 // ------------------------------------------------------------------------------- @@ -247,13 +304,6 @@ } -// ------------------------------------------------------------------------------- -// -(void) afsVolumeMountChange - Track for mount unmount afs volume -// ------------------------------------------------------------------------------- -- (void) afsVolumeMountChange:(NSNotification *)notification{ - [self updateAfsStatus:nil]; -} - // ------------------------------------------------------------------------------- // -(void) updateAfsStatus // ------------------------------------------------------------------------------- @@ -275,23 +325,6 @@ [tokensLock unlock]; } -// ------------------------------------------------------------------------------- -// -(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: // ------------------------------------------------------------------------------- -- 2.39.5