diff --git a/ChangeLog b/ChangeLog index 4ccbeff15..bf709cc68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Sat Jan 9 6:10:00 1999 Richard Frith-Macdonald + + * Source/NSApplication.m: ([-run]) reorganize so that the app can be + terminated before entry to the run loop (in finishLaunching) and to + make the event loop slightly more efficient. + * Source/GSServicesManager.m: ([-registerAsServiceProvider:]) added + checks to raise alert panel to let the application continue when it + conflicts with an already running application or when the DO system + is not working. + Fri Jan 8 14:25:00 1999 Richard Frith-Macdonald * Images/GNUmakefile: Added common_WMClose.tiff and diff --git a/Source/GSServicesManager.m b/Source/GSServicesManager.m index da4ad2445..f82d2776b 100644 --- a/Source/GSServicesManager.m +++ b/Source/GSServicesManager.m @@ -132,6 +132,9 @@ NSRegisterServicesProvider(id provider, NSString *name) name: NSConnectionDidDieNotification object: listenerConnection]; } + else + [NSException raise: NSGenericException + format: @"unable to register %@", name]; } ASSIGN(servicesProvider, provider); } @@ -738,15 +741,65 @@ static NSString *disabledName = @".GNUstepDisabled"; */ - (void) registerAsServiceProvider { - NSString *appName; + NSString *appName; + BOOL registered; appName = [[[NSProcessInfo processInfo] processName] lastPathComponent]; NS_DURING - NSRegisterServicesProvider(self, appName); + { + NSRegisterServicesProvider(self, appName); + registered = YES; + } NS_HANDLER - NSLog(@"Warning: Could not access services due to exception: %@\n", - [localException reason]); + registered = NO; NS_ENDHANDLER + + if (registered == NO) + { + int result = NSRunAlertPanel(appName, + @"Application may already be running with this name", + @"Continue", @"Abort", @"Rename"); + + if (result == NSAlertDefaultReturn || result == NSAlertOtherReturn) + { + if (result == NSAlertOtherReturn) + appName = [NSString stringWithFormat: @"%@_%d", + appName, (int)getpid()]; + [[NSPortNameServer defaultPortNameServer] removePortForName: appName]; + + NS_DURING + { + NSRegisterServicesProvider(self, appName); + registered = YES; + } + NS_HANDLER + { + registered = NO; + NSLog(@"Warning: Could not register application due to " + @"exception: %@\n", [localException reason]); + } + NS_ENDHANDLER + + /* + * Something is seriously wrong - we can't talk to the + * nameserver, so all interaction with the workspace manager + * and/or other applications will fail. + * Give the user a chance to keep on going anyway. + */ + if (registered == NO) + { + result = NSRunAlertPanel(appName, + @"Unable to register application with ANY name", + @"Abort", @"Continue", nil); + + if (result == NSAlertDefaultReturn) + registered = YES; + } + } + + if (registered == NO) + [[NSApplication sharedApplication] terminate: self]; + } } /* diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 84b4b7fc2..dda288ba3 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -272,38 +272,47 @@ NSString* mainModelFile; // - (void) run { -NSEvent *e; -NSAutoreleasePool* pool; + NSEvent *e; + Class arpClass = [NSAutoreleasePool class]; /* Cache the class */ + NSAutoreleasePool* pool; - NSDebugLog(@"NSApplication -run\n"); + NSDebugLog(@"NSApplication -run\n"); - [self finishLaunching]; + /* + * Set this flag here in case the application is actually terminated + * inside -finishLaunching. + */ + app_should_quit = NO; - app_should_quit = NO; - app_is_running = YES; + [self finishLaunching]; - do { - pool = [NSAutoreleasePool new]; + app_is_running = YES; - e = [self nextEventMatchingMask:NSAnyEventMask + while (app_should_quit == NO) + { + pool = [arpClass new]; + + e = [self nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES]; - if (e) - [self sendEvent: e]; + if (e) + [self sendEvent: e]; - [listener updateServicesMenu]; // update (en/disable) the - // services menu's items - [main_menu update]; + // update (en/disable) the + // services menu's items + [listener updateServicesMenu]; + [main_menu update]; - if (windows_need_update) // send an update message - [self updateWindows]; // to all visible windows + // send an update message + // to all visible windows + if (windows_need_update) + [self updateWindows]; - [pool release]; - } - while (!app_should_quit); + [pool release]; + } - NSDebugLog(@"NSApplication end of run loop\n"); + NSDebugLog(@"NSApplication end of run loop\n"); } - (BOOL) isRunning @@ -1621,7 +1630,7 @@ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; // - (void) terminate: (id)sender { - if ([self applicationShouldTerminate:self]) + if ([self applicationShouldTerminate: self]) { // app should end run loop app_should_quit = YES; [event_queue addObject: null_event]; // add dummy event to queue