[libnotify] notify: Support passing a NULL application name to notify_init()



commit cc30d8b8ddf73cfb60f7ba5c4bea34ff732b7889
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue May 17 03:39:06 2022 +0200

    notify: Support passing a NULL application name to notify_init()
    
    We can find its name in some scenarios, so make it clearer from in the API.
    
    Also, ensure that notify_set_app_name() is not used with a NULL App
    name.

 libnotify/notify.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/libnotify/notify.c b/libnotify/notify.c
index ffe8d62..601f8bd 100644
--- a/libnotify/notify.c
+++ b/libnotify/notify.c
@@ -121,6 +121,18 @@ _notify_update_spec_version (GError **error)
        return TRUE;
 }
 
+static gboolean
+set_app_name (const char *app_name)
+{
+        g_return_val_if_fail (app_name != NULL, FALSE);
+        g_return_val_if_fail (*app_name != '\0', FALSE);
+
+        g_free (_app_name);
+        _app_name = g_strdup (app_name);
+
+        return TRUE;
+}
+
 
 /**
  * notify_set_app_name:
@@ -132,24 +144,24 @@ _notify_update_spec_version (GError **error)
 void
 notify_set_app_name (const char *app_name)
 {
-        g_free (_app_name);
-        _app_name = g_strdup (app_name);
+        set_app_name (app_name);
 }
 
 /**
  * notify_init:
- * @app_name: The name of the application initializing libnotify.
+ * @app_name: (nullable): The name of the application initializing libnotify.
  *
  * Initialized libnotify. This must be called before any other functions.
  *
+ * Starting from 0.8, if the provided @app_name is %NULL, libnotify will
+ * try to figure it out from the running application.
+ * Before it was not allowed, and was causing libnotify not to be initialized.
+ *
  * Returns: %TRUE if successful, or %FALSE on error.
  */
 gboolean
 notify_init (const char *app_name)
 {
-        g_return_val_if_fail (app_name != NULL, FALSE);
-        g_return_val_if_fail (*app_name != '\0', FALSE);
-
         if (_initted)
                 return TRUE;
 
@@ -168,7 +180,9 @@ notify_init (const char *app_name)
 #endif
         }
 
-        notify_set_app_name (app_name);
+        if (!set_app_name (app_name)) {
+                return FALSE;
+        }
 
 #ifndef GLIB_VERSION_2_36
         g_type_init ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]