Displaying dialog at shutdown
Displaying dialog at shutdown
- Subject: Displaying dialog at shutdown
- From: email@hidden
- Date: Wed, 02 Jun 2010 16:13:46 +0000
I have a very simple application that runs as an
LSUIElement/BackgroundOnly. Its only purpose is to display a message and
play a short sound (3 seconds) to the user whenever it quits, which, since
its a background only app, is only at shutdown/restart. I can use an
AppleScript to force the app to quit and when doing that, I see the dialog
every time, but if I actually restart the computer, I only see the dialog,
maybe 1 out of 5 times. I use a timer to dismiss the dialog after 5 seconds
and it seems that it is more likely to appear if the timer has a longer
duration, say 15 seconds. My code is below. The window is an NSWindow
instance that's been wired in IB.
//
// TurnOffMouseAppDelegate.m
// TurnOffMouse
//
#import "TurnOffMouseAppDelegate.h"
@implementation TurnOffMouseAppDelegate
@synthesize window;
@synthesize windowController;
@synthesize timer;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
self.windowController = [[NSWindowController alloc]
initWithWindow:self.window];
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication
*)sender{
[self playShutdownMessage:nil];
[self.windowController showWindow:nil];
self.timer = [NSTimer timerWithTimeInterval:5.0 target:self
selector:@selector(closeWindow:) userInfo:nil
repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSModalPanelRunLoopMode];
return NSTerminateLater;
}
-(void)sound:(NSSound *)sound didFinishPlaying:(BOOL)finishedPlaying{
NSLog(@"Sound finished");
}
-(void)closeWindow:(id)sender{
[self.windowController close];
[NSApp replyToApplicationShouldTerminate:YES];
}
-(IBAction)playShutdownMessage:(id)sender{
BOOL playing;
NSLog(@"Playing sound");
NSSound * shutdown = [NSSound soundNamed:@"Shutdown Voice"];
[shutdown setDelegate:self];
if(![shutdown isPlaying])
playing = [shutdown play];
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden