Pet*_*ven 3 vala xdgutils freedesktop.org
在 Vala 的默认应用程序中打开文件的最佳方式是什么?有点像如何xdg-open运作。
我在另一个应用程序中找到了一些现有代码,但后来我也找到了这个
GLib.AppInfo.launch_default_for_uri方法。
一个简单的例子:
var file = File.new_for_path (file_path);
if (file.query_exists ()) {
try {
AppInfo.launch_default_for_uri (file.get_uri (), null);
} catch (Error e) {
warning ("Unable to launch %s", file_path);
}
}
Run Code Online (Sandbox Code Playgroud)