289 if (onMainThread) { 290 [st starter:args]; 291 } else { 292 [st performSelectorOnMainThread: @selector(starter:) withObject:args waitUntilDone:NO]; 293 } 294 295 if (!headless && !onMainThread) { 296 if (verbose) AWT_DEBUG_LOG(@"about to wait on AppKit startup mutex"); 297 298 // Wait here for AppKit to have started (or for AWT to have been loaded into 299 // an already running NSApplication). 300 pthread_mutex_lock(&sAppKitStarted_mutex); 301 while (sAppKitStarted == NO) { 302 pthread_cond_wait(&sAppKitStarted_cv, &sAppKitStarted_mutex); 303 } 304 pthread_mutex_unlock(&sAppKitStarted_mutex); 305 306 // AWT gets here AFTER +[AWTStarter appKitIsRunning:] is called. 307 if (verbose) AWT_DEBUG_LOG(@"got out of the AppKit startup mutex"); 308 } 309 } 310 311 - (void)starter:(NSArray*)args { 312 NSAutoreleasePool *pool = [NSAutoreleasePool new]; 313 314 BOOL onMainThread = [[args objectAtIndex:0] boolValue]; 315 BOOL swtMode = [[args objectAtIndex:1] boolValue]; 316 BOOL headless = [[args objectAtIndex:2] boolValue]; 317 BOOL swtModeForWebStart = [[args objectAtIndex:3] boolValue]; 318 BOOL verbose = [[args objectAtIndex:4] boolValue]; 319 320 BOOL wasOnMainThread = onMainThread; 321 322 setUpAWTAppKit(swtMode, headless); 323 324 // Headless mode trumps either ordinary AWT or SWT-in-AWT mode. Declare us a daemon and return. 325 if (headless) { 326 BOOL didBecomeDaemon = [AWTStarter markAppAsDaemon]; 327 return; 328 } 329 330 if (swtMode || swtModeForWebStart) { 331 if (verbose) NSLog(@"in SWT or SWT/WebStart mode"); 332 333 // The SWT should call NSApplicationLoad, but they don't know a priori that they will be using the AWT, so they don't. 334 NSApplicationLoad(); 335 } 336 337 // This will create a NSApplicationAWT for standalone AWT programs, unless there is 338 // already a NSApplication instance. If there is already a NSApplication instance, 339 // and -[NSApplication isRunning] returns YES, AWT is embedded inside another 340 // AppKit Application. 341 NSApplication *app = [NSApplicationAWT sharedApplication]; 342 343 // Don't set the delegate until the NSApplication has been created. 344 // ApplicationDelegate is the support code for com.apple.eawt. 345 OSXAPP_SetApplicationDelegate([ApplicationDelegate sharedDelegate]); 346 347 // AWT gets to this point BEFORE NSApplicationDidFinishLaunchingNotification is sent. 348 if (![app isRunning]) { 349 if (verbose) AWT_DEBUG_LOG(@"+[AWTStarter startAWT]: ![app isRunning]"); 350 351 // This is where the AWT AppKit thread parks itself to process events. 352 [NSApplicationAWT runAWTLoopWithApp: app]; 353 } else { 354 // We're either embedded, or showing a splash screen 355 if (![NSApp isKindOfClass:[NSApplicationAWT class]]) { 356 if (verbose) AWT_DEBUG_LOG(@"running embedded"); 357 358 // Since we're embedded, no need to be swamping the runloop with the observers. 359 CFRunLoopRef runLoop = [[NSRunLoop currentRunLoop] getCFRunLoop]; 360 CFRunLoopRemoveObserver(runLoop, busyObserver, kCFRunLoopDefaultMode); 361 CFRunLoopRemoveObserver(runLoop, notBusyObserver, kCFRunLoopDefaultMode); 362 363 busyObserver = NULL; 364 notBusyObserver = NULL; 365 } else { | 289 if (onMainThread) { 290 [st starter:args]; 291 } else { 292 [st performSelectorOnMainThread: @selector(starter:) withObject:args waitUntilDone:NO]; 293 } 294 295 if (!headless && !onMainThread) { 296 if (verbose) AWT_DEBUG_LOG(@"about to wait on AppKit startup mutex"); 297 298 // Wait here for AppKit to have started (or for AWT to have been loaded into 299 // an already running NSApplication). 300 pthread_mutex_lock(&sAppKitStarted_mutex); 301 while (sAppKitStarted == NO) { 302 pthread_cond_wait(&sAppKitStarted_cv, &sAppKitStarted_mutex); 303 } 304 pthread_mutex_unlock(&sAppKitStarted_mutex); 305 306 // AWT gets here AFTER +[AWTStarter appKitIsRunning:] is called. 307 if (verbose) AWT_DEBUG_LOG(@"got out of the AppKit startup mutex"); 308 } 309 310 // Don't set the delegate until the NSApplication has been created and 311 // its finishLaunching has initialized it. 312 // ApplicationDelegate is the support code for com.apple.eawt. 313 void (^setDelegateBlock)() = ^(){ 314 OSXAPP_SetApplicationDelegate([ApplicationDelegate sharedDelegate]); 315 }; 316 if (onMainThread) { 317 setDelegateBlock(); 318 } else { 319 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:setDelegateBlock]; 320 } 321 } 322 323 - (void)starter:(NSArray*)args { 324 NSAutoreleasePool *pool = [NSAutoreleasePool new]; 325 326 BOOL onMainThread = [[args objectAtIndex:0] boolValue]; 327 BOOL swtMode = [[args objectAtIndex:1] boolValue]; 328 BOOL headless = [[args objectAtIndex:2] boolValue]; 329 BOOL swtModeForWebStart = [[args objectAtIndex:3] boolValue]; 330 BOOL verbose = [[args objectAtIndex:4] boolValue]; 331 332 BOOL wasOnMainThread = onMainThread; 333 334 setUpAWTAppKit(swtMode, headless); 335 336 // Headless mode trumps either ordinary AWT or SWT-in-AWT mode. Declare us a daemon and return. 337 if (headless) { 338 BOOL didBecomeDaemon = [AWTStarter markAppAsDaemon]; 339 return; 340 } 341 342 if (swtMode || swtModeForWebStart) { 343 if (verbose) NSLog(@"in SWT or SWT/WebStart mode"); 344 345 // The SWT should call NSApplicationLoad, but they don't know a priori that they will be using the AWT, so they don't. 346 NSApplicationLoad(); 347 } 348 349 // This will create a NSApplicationAWT for standalone AWT programs, unless there is 350 // already a NSApplication instance. If there is already a NSApplication instance, 351 // and -[NSApplication isRunning] returns YES, AWT is embedded inside another 352 // AppKit Application. 353 NSApplication *app = [NSApplicationAWT sharedApplication]; 354 355 // AWT gets to this point BEFORE NSApplicationDidFinishLaunchingNotification is sent. 356 if (![app isRunning]) { 357 if (verbose) AWT_DEBUG_LOG(@"+[AWTStarter startAWT]: ![app isRunning]"); 358 359 // This is where the AWT AppKit thread parks itself to process events. 360 [NSApplicationAWT runAWTLoopWithApp: app]; 361 } else { 362 // We're either embedded, or showing a splash screen 363 if (![NSApp isKindOfClass:[NSApplicationAWT class]]) { 364 if (verbose) AWT_DEBUG_LOG(@"running embedded"); 365 366 // Since we're embedded, no need to be swamping the runloop with the observers. 367 CFRunLoopRef runLoop = [[NSRunLoop currentRunLoop] getCFRunLoop]; 368 CFRunLoopRemoveObserver(runLoop, busyObserver, kCFRunLoopDefaultMode); 369 CFRunLoopRemoveObserver(runLoop, notBusyObserver, kCFRunLoopDefaultMode); 370 371 busyObserver = NULL; 372 notBusyObserver = NULL; 373 } else { |