changeset 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
files mac/dw.m
diffstat 1 files changed, 36 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Thu Sep 10 23:58:33 2020 +0000
+++ b/mac/dw.m	Fri Sep 11 02:56:41 2020 +0000
@@ -12415,24 +12415,53 @@
  *       type: Either DW_EXEC_CON or DW_EXEC_GUI.
  *       params: An array of pointers to string arguements.
  * Returns:
- *       -1 on error.
+ *       DW_ERROR_UNKNOWN (-1) on error.
  */
 int dw_exec(const char *program, int type, char **params)
 {
-    int ret = -1;
+    int ret = DW_ERROR_UNKNOWN;
 
     if(type == DW_EXEC_GUI)
     {
+        NSString *nsprogram = [NSString stringWithUTF8String:program];
+        
         if(params && params[0] && params[1])
         {
-            [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithUTF8String:params[1]]
-                                    withApplication:[NSString stringWithUTF8String:program]];
+            NSString *file = [NSString stringWithUTF8String:params[1]];
+            
+#ifdef BUILDING_FOR_CATALINA
+            if(@available(macOS 10.15, *))
+            {
+                NSURL *url = [NSURL fileURLWithPath:nsprogram];
+                NSURL *nsfile = [NSURL fileURLWithPath:file];
+                
+                [[NSWorkspace sharedWorkspace] openURLs:[[NSArray alloc] initWithObjects:nsfile, nil]
+                                    withApplicationAtURL:url
+                                           configuration:[NSWorkspaceOpenConfiguration configuration]
+                                       completionHandler:^(NSRunningApplication *app, NSError *error) {
+                }];
+            }
+            else
+#endif
+                [[NSWorkspace sharedWorkspace] openFile:file withApplication:nsprogram];
         }
         else
         {
-            [[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithUTF8String:program]];
-        }
-        return 0;
+#ifdef BUILDING_FOR_CATALINA
+            if(@available(macOS 10.15, *))
+            {
+                NSURL *url = [NSURL fileURLWithPath:nsprogram];
+
+                [[NSWorkspace sharedWorkspace] openApplicationAtURL:url
+                                                      configuration:[NSWorkspaceOpenConfiguration configuration]
+                                                  completionHandler:^(NSRunningApplication *app, NSError *error) {
+                }];
+            }
+            else
+#endif
+                [[NSWorkspace sharedWorkspace] launchApplication:nsprogram];
+        }
+        return DW_ERROR_NONE;
     }
 
     if((ret = fork()) == 0)