changeset 2070:370baf78abdc

Mac: Added dw_app_id_set() and updates to generate the APP ID automatically.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 15 May 2020 01:19:55 +0000
parents b4b49d29b940
children c2f13c5eefac
files dw.h mac/dw.m
diffstat 2 files changed, 37 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Thu May 14 23:40:34 2020 +0000
+++ b/dw.h	Fri May 15 01:19:55 2020 +0000
@@ -1525,6 +1525,9 @@
 #define UINT_TYPEDEFED 1
 #define INT_TYPEDEFED 1
 
+/* Use the dbsoft.org application domain by default if not specified */
+#define DW_APP_DOMAIN_DEFAULT "org.dbsoft.dwindows"
+
 /* Support for API deprecation in supported compilers */
 #if defined(__has_feature) && !defined(__has_extension)
 #define __has_extension __has_feature
--- a/mac/dw.m	Thu May 14 23:40:34 2020 +0000
+++ b/mac/dw.m	Fri May 15 01:19:55 2020 +0000
@@ -443,6 +443,7 @@
 pthread_key_t _dw_bg_color_key;
 int DWOSMajor, DWOSMinor, DWOSBuild;
 static char _dw_bundle_path[PATH_MAX+1] = { 0 };
+static char _dw_app_id[101]= {0};
 
 /* Create a default colors for a thread */
 void _init_colors(void)
@@ -3940,6 +3941,27 @@
 }
 
 /*
+ * Sets the application ID used by this Dynamic Windows application instance.
+ * Parameters:
+ *         appid: A string typically in the form: com.company.division.application
+ *         appguid: A globally unique identifier required on Windows or NULL.
+ * Returns:
+ *         DW_ERROR_NONE after successfully setting the application ID.
+ *         DW_ERROR_UNKNOWN if unsupported on this system.
+ *         DW_ERROR_GENERAL if the application ID is not allowed.
+ * Remarks:
+ *          This must be called before dw_init().  If dw_init() is called first
+ *          it will create a unique ID in the form: org.dbsoft.dwindows.application
+ *          or if the application name cannot be detected: org.dbsoft.dwindows.pid.#
+ *          The GUID is only required on Windows, NULL can be passed on other platforms.
+ */
+int dw_app_id_set(const char *appid, const char *appguid)
+{
+    strncpy(_dw_app_id, appid, 100);
+    return DW_ERROR_NONE;
+}
+
+/*
  * Displays a debug message on the console...
  * Parameters:
  *           format: printf style format string.
@@ -11994,7 +12016,13 @@
     {
         char *pathcopy = strdup(argv[0]);
         char *app = strstr(pathcopy, ".app/");
-
+        char *binname = strrchr(pathcopy, '/');
+        
+        if(binname && (binname++) && _dw_app_id[0])
+        {
+            /* If we have a binary name, use that for the Application ID instead. */
+            snprintf(_dw_app_id, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname);
+        }
         if(app)
         {
             char pathbuf[PATH_MAX+1] = { 0 };
@@ -12077,6 +12105,11 @@
     [thread start];
     [thread release];
     [NSTextField setCellClass:[DWTextFieldCell class]];
+    if(!_dw_app_id[0])
+    {
+        /* Generate an Application ID based on the PID if all else fails. */
+        snprintf(_dw_app_id, 100, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid());
+    }
     return 0;
 }