【问题标题】:Is there a way to trigger a pop-up notification from Vala MSYS2 on Windows 10?有没有办法在 Windows 10 上触发 Vala MSYS2 的弹出通知?
【发布时间】:2019-01-04 12:56:46
【问题描述】:

我不喜欢 Windows,我只是想看看 Vala 是如何跨平台的。

当使用libnoyify我明白了

    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

在这样的代码中

    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;
}

那么有没有办法从 Vala 触发弹出通知?

我找到的只是this,但我认为它不适合 Windows 10,它似乎在 2011 年就停止了。

【问题讨论】:

    标签: windows popup vala notify msys2


    【解决方案1】:

    为了了解发生了什么,我将其分解为 Vala、GTK+、系统通知和 D-Bus。

    看起来您已经编译了程序并在 Windows 上运行了它。所以 Vala 和 C 编译器已经完成了他们的工作并生成了一个在 Windows 上运行的二进制文件。 Vala 经常与 GTK+ 图形工具包一起使用,而 GTK+ 使用不同的GDK backends 来处理诸如创建窗口和处理输入之类的事情。 GTK+ 还使用不同的Cairo backends 来跨平台渲染小部件。 GDK 和 Cairo 在 Windows 上使用 Windows API,在 macOS 上使用 Quartz API 等等。

    系统范围的通知似乎不像 GDK 和 Cairo 那样跨平台。 Unix 的通用标准是Freedesktop.org notification specification。本规范使用D-Bus 与系统范围的通知实现进行进程间通信。在 Linux 和其他类 Unix 平台上,这工作得很好。要求是 D-Bus 正在运行,并且有一个 org.freedesktop.Notifications 的实现。

    在 Windows 上,我不确定 D-Bus 是否有效。 Windows 可能有 TCP 实现,但在 Unix 上使用 Unix 套接字。如果 D-Bus 可以在 Windows 上运行,那么还需要实现 org.freedesktop.Notifications,将 D-Bus 消息转换为 Windows API 以获取通知。所以这可能是可能的,但我找不到实现。

    更新

    正如@AlexB GIO 的GNotification 所指出的,提供跨平台系统通知。这包括org.freedesktop.NotificationsFlatpakmacOSWindows。不幸的是,目前 Windows 实现是just a place holder。有一个issue to fix this

    【讨论】:

    • DBus 在 Windows 上工作(通过 MSYS2),理论上可以在 Windows API 和 org.freedesktop.Notifications 之间建立一座桥梁,但如果你想要跨平台通知,请在 GIO (GLib) 中使用 GNotification 它支持ofN、Flatpak、Windows 和我认为是 macOS
    • 回答。你能给我一个例子吗?我没有在 valadoc 中找到 GNotification 并在这里品尝(stackoverflow.com/questions/33723549/…)我得到了错误。 gavr@archlabs ~> vala console.vala console.vala:4.24-4.35: error: The name Notification' does not exist in the context of GLib'.
    • @gavr 你需要用--pkg gio-2.0编译
    • @AlThomas pastebin.com/mw4mHMRj 什么都没发生 g_application_send_notification: 断言 'G_IS_APPLICATION (application)' 失败
    • @gavr,阅读我的更新,然后如果你想继续尝试你需要使用 GApplication,所以创建 class MyApplication:Application {...} 覆盖 startup 方法和空的 activate 方法。例如valadoc.org/gio-2.0/GLib.Application.htmlstackoverflow.com/questions/49987610/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    • 2017-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 2010-10-12
    相关资源
    最近更新 更多