comparison mac/dw.m @ 2151:467401a1ca69

Mac: Start the move to the new APIs for launching applications in dw_exec(). The new APIs were introduced in Catalina (10.15), so we need to keep the old APIs for all older versions, so the warnings I was trying to eliminate remain. Also noticing that the console execution is still using xterm instead of Terminal.app, xterm existed in very old versions but Apple has since removed the X11.app and thus the xterm program. Will move to Terminal.app in a later commit.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 11 Sep 2020 02:56:41 +0000
parents be4547734f0b
children d299b5acc507
comparison
equal deleted inserted replaced
2150:be4547734f0b 2151:467401a1ca69
12413 * Parameters: 12413 * Parameters:
12414 * program: Program name with optional path. 12414 * program: Program name with optional path.
12415 * type: Either DW_EXEC_CON or DW_EXEC_GUI. 12415 * type: Either DW_EXEC_CON or DW_EXEC_GUI.
12416 * params: An array of pointers to string arguements. 12416 * params: An array of pointers to string arguements.
12417 * Returns: 12417 * Returns:
12418 * -1 on error. 12418 * DW_ERROR_UNKNOWN (-1) on error.
12419 */ 12419 */
12420 int dw_exec(const char *program, int type, char **params) 12420 int dw_exec(const char *program, int type, char **params)
12421 { 12421 {
12422 int ret = -1; 12422 int ret = DW_ERROR_UNKNOWN;
12423 12423
12424 if(type == DW_EXEC_GUI) 12424 if(type == DW_EXEC_GUI)
12425 { 12425 {
12426 NSString *nsprogram = [NSString stringWithUTF8String:program];
12427
12426 if(params && params[0] && params[1]) 12428 if(params && params[0] && params[1])
12427 { 12429 {
12428 [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithUTF8String:params[1]] 12430 NSString *file = [NSString stringWithUTF8String:params[1]];
12429 withApplication:[NSString stringWithUTF8String:program]]; 12431
12432 #ifdef BUILDING_FOR_CATALINA
12433 if(@available(macOS 10.15, *))
12434 {
12435 NSURL *url = [NSURL fileURLWithPath:nsprogram];
12436 NSURL *nsfile = [NSURL fileURLWithPath:file];
12437
12438 [[NSWorkspace sharedWorkspace] openURLs:[[NSArray alloc] initWithObjects:nsfile, nil]
12439 withApplicationAtURL:url
12440 configuration:[NSWorkspaceOpenConfiguration configuration]
12441 completionHandler:^(NSRunningApplication *app, NSError *error) {
12442 }];
12443 }
12444 else
12445 #endif
12446 [[NSWorkspace sharedWorkspace] openFile:file withApplication:nsprogram];
12430 } 12447 }
12431 else 12448 else
12432 { 12449 {
12433 [[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithUTF8String:program]]; 12450 #ifdef BUILDING_FOR_CATALINA
12434 } 12451 if(@available(macOS 10.15, *))
12435 return 0; 12452 {
12453 NSURL *url = [NSURL fileURLWithPath:nsprogram];
12454
12455 [[NSWorkspace sharedWorkspace] openApplicationAtURL:url
12456 configuration:[NSWorkspaceOpenConfiguration configuration]
12457 completionHandler:^(NSRunningApplication *app, NSError *error) {
12458 }];
12459 }
12460 else
12461 #endif
12462 [[NSWorkspace sharedWorkspace] launchApplication:nsprogram];
12463 }
12464 return DW_ERROR_NONE;
12436 } 12465 }
12437 12466
12438 if((ret = fork()) == 0) 12467 if((ret = fork()) == 0)
12439 { 12468 {
12440 int i; 12469 int i;