我不喜欢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 , macOS和 Windows .不幸的是,目前 Windows 实现是 just a place holder .有一个 issue to fix this .
关于windows - 有没有办法在 Windows 10 上触发来自 Vala MSYS2 的弹出通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54039413/