我不喜欢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,但我不认为它适用于Windows10,它似乎在2011年停止了。
发布于 2019-01-04 21:34:27
为了理解到底发生了什么,我将其分解为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。
https://stackoverflow.com/questions/54039413
复制相似问题