Search code examples
windowspopupvalanotifymsys2

Is there a way to trigger a pop-up notification from Vala MSYS2 on Windows 10?


I don't like Windows, I just want to check how cross-platform Vala is.

When using libnoyify I see

    gavr@DESKTOP-B57MHT8 MINGW64 ~
$ ./notify.exe

** (notify.exe:6680): ERROR **: 15:50:47.138: notify.vala:13: Error: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications is unknown

in code like that

    public static int main (string[] args) {
        string summary = "Short summary";
        string body = "A long description";
        string icon = "dialog-information";

        Notify.init ("My test app");

        try {
            Notify.Notification notification = new Notify.Notification (summary, body, icon);
            notification.show ();
        } catch (Error e) {
            error ("Error

: %s", e.message);
    }
    return 0;
}

So is there a way to trigger a pop-up notification from Vala?

All I found is this but I do not think it is suitable for Windows 10, it seems it stopped in 2011.


Solution

  • To understand what is going on I'll break it down into Vala, GTK+, system notifications and D-Bus.

    It looks like you've compiled your program and run it on Windows. So Vala and the C compiler have done their things and produced a binary that runs on Windows. Vala is often used with the GTK+ graphical toolkit and GTK+ uses different GDK backends for things like creating windows and handling input. GTK+ also uses different Cairo backends for rendering widgets across platforms. GDK and Cairo uses the Windows API on Windows, Quartz API on macOS and so on.

    System wide notifications don't appear to be as cross platform as GDK and Cairo. The common standard for Unix is the Freedesktop.org notification specification. This specification makes use of D-Bus for inter-process communication with a system wide notification implementation. On Linux and other Unix-like platforms this works pretty well. The requirements are D-Bus is running and there is an implementation of org.freedesktop.Notifications.

    On Windows I'm not sure if D-Bus works. There might be a TCP implementation for Windows, but Unix sockets are used on Unix. If D-Bus can be run on Windows then there would also need to be an implementation of org.freedesktop.Notifications that translates the D-Bus messages to the Windows API for notifications. So it might be possible, but I can't find an implementation.

    Update

    As pointed out by @AlexB GIO's GNotification provides cross platform system notifications. This includes org.freedesktop.Notifications, Flatpak, macOS and Windows. Unfortunately at the current time the Windows implementation is just a place holder. There is an issue to fix this.