From cd7b4de52957ba05a81b920fb9f02bf362d64182 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 17 Apr 2010 02:36:31 +1200 Subject: [PATCH] Launch the game with argv *and* a dock icon --- packaging/osx/launcher/Controller.m | 33 ++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/packaging/osx/launcher/Controller.m b/packaging/osx/launcher/Controller.m index 0a21d98244..6fb0841c5e 100644 --- a/packaging/osx/launcher/Controller.m +++ b/packaging/osx/launcher/Controller.m @@ -36,23 +36,32 @@ NSString *modString = [[mods objectAtIndex:[modsList selectedRow]] objectForKey:@"Mods"]; [settings setValue:modString forSetting:@"InitialMods"]; [settings save]; - - // Launch the game - NSMutableArray *args = [NSMutableArray arrayWithObjects:@"settings=../../../launcher.ini",nil]; + + // Neither NSTask or NSWorkspace do what we want on pre-10.6 (we want *both* Info.plist and argument support) + // so use the LaunchServices api directly NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"OpenRA.app/Contents/MacOS/OpenRA"]; + NSArray *args = [NSArray arrayWithObjects:@"settings=../../../launcher.ini",nil]; + + FSRef appRef; + CFURLGetFSRef((CFURLRef)[NSURL URLWithString:path], &appRef); - NSTask *task = [[NSTask alloc] init]; - [task setLaunchPath:path]; - [task setArguments:args]; - [task launch]; + // Set the launch parameters + LSApplicationParameters params; + params.version = 0; + params.flags = kLSLaunchDefaults; + params.application = &appRef; + params.asyncLaunchRefCon = NULL; + params.environment = NULL; // CFDictionaryRef of environment variables; could be useful + params.argv = (CFArrayRef)args; + params.initialEvent = NULL; - // Bring the game to the front ProcessSerialNumber psn; - if (noErr == GetProcessForPID([task processIdentifier], &psn)) { - SetFrontProcess(&psn); - } - [task release]; + OSStatus err = LSOpenApplication(¶ms, &psn); + // Bring the game window to the front + if (err == noErr) + SetFrontProcess(&psn); + // Close the launcher [NSApp terminate: nil]; }