windows - 有没有办法在 Windows 10 上触发来自 Vala MSYS2 的弹出通知?

标签 windows popup vala notify msys2

我不喜欢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 年停止了。

最佳答案

为了了解发生了什么,我将把它分解为 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.Notifications , Flatpak , macOSWindows .不幸的是,目前 Windows 实现是 just a place holder .有一个 issue to fix this .

关于windows - 有没有办法在 Windows 10 上触发来自 Vala MSYS2 的弹出通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54039413/

相关文章:

c++ - 调用SDL_CreateTextureFromSurface时SDL崩溃

javascript - window.location.href 在弹出窗口中不起作用

permissions - iOS 6 移除通讯录权限入口

c++ - Qt中的弹出菜单事件控件

label - Vala - 如何以编程方式设置 Gtk4.Label 的颜色?

python - 如何将 .pcm 文件转换为 .wav 文件(脚本)

windows - 如何更改 Windows 控制台窗口的宽度?

gtk - 使用 glib.string.escape() 时如何转义特殊字符

windows - Git,切换分支时出现错误 : "Deletion of directory ' <dirname >' failed. Should I try again?" Started after I set custom folder icon

visual-studio-code - 在 Linux 上的 VSCode 中调试 Vala