2
votes

I use the newest GTK+ installed with MSYS2 and whenever I attempt to use g_application_send_notification() it always results in the following assert:

(Notification Project.exe:27780): GLib-GObject-CRITICAL **: g_object_new:
assertion 'G_TYPE_IS_OBJECT (object_type)' failed

Why I think it is a bug - because I tried many code samples beside mines (they are all quite like mines anyway), of people who got it working (including notifaction by Lars Uebernickel) and it all makes the same lament. Assert, followed by crash. Now I really don't know what this means, as it is probably within gtk internals, but I really hope some of you might have a clue or experience with this.

  • install (GNU coreutils) 8.25
  • GIO version 2.52.3
  • mingw32/mingw-w64-i686-gtk-engine-unico 1.0.2-2 [installed]
  • mingw32/mingw-w64-i686-gtk3 3.22.16-1 [installed]
  • mingw32/mingw-w64-i686-gtkmm3 3.22.0-1 [installed]
  • mingw32/mingw-w64-i686-spice-gtk 0.33-1 [installed]
  • mingw32/mingw-w64-i686-webkitgtk3 2.4.11-4 [installed]
  • mingw64/mingw-w64-x86_64-gtk-engine-unico 1.0.2-2 [installed]
  • mingw64/mingw-w64-x86_64-gtk3 3.22.16-1 [installed]
  • mingw64/mingw-w64-x86_64-gtkmm3 3.22.0-1 [installed]
  • mingw64/mingw-w64-x86_64-spice-gtk 0.33-1 [installed]
  • mingw64/mingw-w64-x86_64-webkitgtk3 2.4.11-4 [installed]

An example of code that generates this assert:

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gtk/gtk.h>

#define ICON_PATH "/path/trash_16x16.gif"

int main (int argc, char *argv[])
{
    GApplication *app;

    app = g_application_new ("org.one", G_APPLICATION_FLAGS_NONE);
    if(!app)
    {
        g_print ("Error app\n");
    }
    else
    {
        if(g_application_register (app, NULL, NULL))
        {
            GNotification *notification;
            GFile *file;
            GIcon *icon;
            notification = g_notification_new ("one");
            g_notification_set_body (notification, "Hello world");
            file = g_file_new_for_path (ICON_PATH);
            icon = g_file_icon_new (file);
            g_notification_set_icon (notification, G_ICON (icon));
            g_application_send_notification (app, NULL, notification);
            g_object_unref (icon);
            g_object_unref (file);
            g_object_unref (notification);
            g_object_unref (app);
            g_print ("yes\n");
        }
        else
        {
            g_print ("no\n");
        }
    }
    return 0;
}

Is that anything I can do to bypass this problem, or perhaps even solve it?

1
First of all SO is not a GTK bug tracker, so why posting here? If you want us to reassure you, you should post an MCVE.Eugene Sh.
@EugeneSh Sorry if I misunderstand, but what is MCVE? Also isn't it for programming-related problems. This is programming-related problem.Imobilis
Your question would be better with your call to g_application_send_notification included in the question. But I think it's probable it doesn't matter much, so :I am not downvotingSam Hartman
stackoverflow.com/help/mcve And yes, it is for programming related questions. But I don't see a question here.Eugene Sh.
@JoséFonte Thank you :) If I find a solution. I will post it.Imobilis

1 Answers

0
votes

There are no notification backends that work on W32, confirmed. Contributors do wanted, once, to create such, but the API (W32 toast notifications) that is needed is COM-only, and MinGW-w64 doesn't have the necessary headers for it, yet. enter image description here


Looking at the glib gio source code and GNotificationBackend interface specifically, we can see that it is simple.

Now, you could just do it in GTK...OR we could do it the right way (TM) and implement a D-Bus server for it. The good thing about a notification server is that notifications can persist even after an application is terminated. Also, GTK already has backends for talking to a notification server, so you'd only need to enable these backends on W32 (at a glance, the code doesn't use anything that doesn't work on W32 already). Also, that way the server would transparently use Shell_NotifyIcon (on Windows 7 and earlier) or toast notifications (on Windows 8 and later; if you ever get an opportunity to implement these).

Another option if you want to maintain cross-platformability is to create Shell_NotifyIcon implementation in a DLL and if windows is detected use Shell_NotifyIcon if not, GNotification as you would.