Re: NSWorkspaceWillPowerOffNotification events
Re: NSWorkspaceWillPowerOffNotification events
- Subject: Re: NSWorkspaceWillPowerOffNotification events
- From: "sunil prajapati" <email@hidden>
- Date: Tue, 14 Aug 2007 18:13:02 +0530
thanks for reply.
still I m not able to capture the log out event while making NSUIElement value 1 in my info.plist.
I used three methods to get the system log out events both are giving the same problem when i make NSUIElement 1
and both are working fine when i make NSUIElement 0 in info.plist file.
Method 1. [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
selector:@selector( workspaceWillPowerOff: )
name:NSWorkspaceWillPowerOffNot
ification object:[NSWorkspace sharedWorkspace]];
-(void)workspaceWillPowerOff:(NSNotification *)aNotification
{
NSLog(@"Workspace");
NSWorkspace *myWorkspace;
myWorkspace = (NSWorkspace *)[aNotification object];
NSRunAlertPanel(@"MyDocument",@"inside my document's workspaceWillPowerOff",@"Cancel",@"OK",nil);
}
Method 2.
void* EventLoop1( void* arg);
static OSErr QuitAppleEventHandler(const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon);
pthread_t eventTrap;
Boolean gQuitFlag; /* global */
int main(int argc, char *argv[])
{
Initialize();
RunApplicationEventLoop();
}
void Initialize() /* Initialize the cursor and set up AppleEvent quit handler */
{
OSErr err;
err = AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP((AEEventHandlerProcPtr)QuitAppleEventHandler), 1, false );
if (err != noErr)
ExitToShell();
pthread_create(&eventTrap, NULL, &EventLoop1, NULL); //fleetwood
if (NULL == eventTrap)
{
printf("error in creating thread\n");
}
}
static OSErr QuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon )
{
return userCanceledErr;
}
void* EventLoop1( void* arg)
{
void EventLoop();
return 0;
}
void EventLoop()
{
Boolean gotEvent;
EventRecord event;
gQuitFlag = false;
do
{
gotEvent = WaitNextEvent(everyEvent, &event, kSleepTime, nil);
if (gotEvent)
DoEvent(&event);
} while (!gQuitFlag);
ExitToShell();
}
void DoEvent(EventRecord *event)
{
switch (event->what)
{
case kHighLevelEvent:
AEProcessAppleEvent( event );
break;
}
}
Method 3.int main()
{
signal(SIGTERM, catch_term);
printf("The program is started:\n");
for ( ;; )
pause();
return 0;
}
void catch_term(int sig_num)
{
char buff[50]="I was able to catch the SIGKILL signal\n";
FILE *fp;
fp = fopen("/Users/sunilmbook/Desktop/file.txt","w+");
fputs(buff,fp);
fclose(fp);
signal(SIGTERM,SIG_DFL);//SIG_DFL
fflush(stdout);
}
Still I m totally helpless after doing these three method of finding logout events.
Is there any setting to be done in info.plist file?
I get the problem only when i set LSUIElement 1 in my
info.plist otherwise all my three methods works fine and trap the log out event.
Thanks,
Sunil.
On 8/13/07, Quinn <
email@hidden> wrote:At 19:56 +0530 11/8/07, sunil prajapati wrote:
>This works fine when i show my application in Dock,I able to capture
>the System Logout event.
>
>But when I do not show my application in Dock by setting
>LSUIElement=1 then I unable to capture the System Logout event.
I believe that this relates to the way that you're quit. When you're
quit by loginwindow, it includes an extra parameter in the Apple
event to indicate why it's quitting you. If that parameter says that
you're quitting because of a shut down, AppKit generates this
notification internally.
I'm not sure why you're not getting the notification in the
LSUIElement case, and it's sufficiently far outside of my expertise
that I'm reluctant to speculate. Perhaps you could ask the good
folks on the cocoa-dev mailing list.
<http://lists.apple.com/mailman/listinfo/cocoa-dev>
Share and Enjoy
--
Quinn "The Eskimo!" <
http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
Do not post admin requests to the list. They will be ignored.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden