windows - 有没有办法在 Windows 10 上触发 Vala 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 的弹出通知呢?
我发现的只是这个,但我认为它不适合 Windows 10,它似乎在 2011 年就停止了。
解决方案
为了理解发生了什么,我将其分解为 Vala、GTK+、系统通知和 D-Bus。
看起来您已经编译了程序并在 Windows 上运行它。所以 Vala 和 C 编译器已经完成了他们的工作并生成了一个在 Windows 上运行的二进制文件。Vala 经常与 GTK+ 图形工具包一起使用,而 GTK+ 使用不同的GDK 后端来处理诸如创建窗口和处理输入之类的事情。GTK+ 还使用不同的Cairo 后端来跨平台渲染小部件。GDK 和 Cairo 在 Windows 上使用 Windows API,在 macOS 上使用 Quartz API 等等。
系统范围的通知似乎不像 GDK 和 Cairo 那样跨平台。Unix 的通用标准是Freedesktop.org 通知规范。该规范使用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所指出的那样,它提供了跨平台系统通知。这包括Flatpakorg.freedesktop.Notifications
、macOS和Windows 。不幸的是,目前 Windows 实现只是一个占位符。有一个问题要解决这个问题。
推荐阅读
- android - Visual Studio 下的 Android Activity 在引用 .a 库时尝试构建时导致“未定义的引用”
- c - 我的 C 程序无法识别有效输入,认为这是因为换行问题
- ruby-on-rails - 这是在后端允许在 Rails 中使用参数的安全方法吗?
- python - *不*能够从文件中取回值
- svelte-3 - svelte 不断更新 store var 而不点击更新
- firefox - FireFox Video 发出警告,但视频确实有效?
- javascript - 有效地查找字符串中的 n 个最长单词
- scriptdom - 在动态 SQL 中,ScriptDom 正在查找 IF 语句,而不是 UPDATE 语句
- javascript - 为什么 Symbol.iterator 被设计为 Symbol 类型?
- git - 后续提交后将功能分支合并到主分支?