1

我在 gnome shell 上遇到了 d-bus 的问题,我正在尝试使用 javascript 通过消息 dbus 管理截屏,这是一个代码:`

this.gdbusConnection = Gio.bus_get_sync(Gio.BusType.SESSION, null);

this.gdbusProxy = new Gio.DBusProxy({g_connection: this.gdbusConnection,
    g_flags: Gio.DBusProxyFlags.NONE ,
    g_interface_name: "org.gnome.Shell.Screencast",
    g_name: "org.gnome.Shell.Screencast", 
    g_object_path: "/org/gnome/Shell/Screencast"});

this.gdbusProxy.call("org.gnome.Shell.Screencast.Screencast", null, Gio.DBusCallFlags.NONE, -1, null, this._doExtensionPreferences, null);`

当我执行这段代码时,我在 dbus 监视器中看到了这个:

    ~$ dbus-monitor "interface=org.gnome.Shell.Screencast"
signal sender=org.freedesktop.DBus -> dest=:1.103 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
   string ":1.103"
method call sender=:1.19 -> dest=org.gnome.Shell.Screencast serial=495 path=/org/gnome/Shell/Screencast; interface=org.gnome.Shell.Screencast; member=Screencast
method call sender=:1.19 -> dest=org.gnome.Shell.Screencast serial=500 path=/org/gnome/Shell/Screencast; interface=org.gnome.Shell.Screencast; member=StopScreencast

我认为问题在于发送者,因为如果我在 dbus 监视器中以传统方式启动 sceencast,则调用相同的功能但发送者不同,您有什么建议吗?

    method call sender=:1.6 -> dest=:1.19 serial=228 path=/org/gnome/Shell/Screencast; interface=org.gnome.Shell.Screencast; member=Screencast
   string "Screencast da %d %t.webm"
   array [
   ]
method call sender=:1.6 -> dest=:1.19 serial=229 path=/org/gnome/Shell/Screencast; interface=org.gnome.Shell.Screencast; member=StopScreencast

编辑:这是正确的代码。

const MyProxy = Gio.DBusProxy.makeProxyWrapper(LibRecorder.ScreencastIface);
this.instance = new MyProxy(Gio.DBus.session, 'org.gnome.Shell.Screencast','/org/gnome/Shel/Screencast'
    , Lang.bind(this, function(proxy, error) {
        if (error) {
            log(error.message);
            return;
        } else 
            Lib.TalkativeLog('ESC > d-bus proy connected');
}));

this.instance.ScreencastRemote("test_proxy_ %d_ %t.webm", null, Lang.bind(this, function(result, error) {
    if (error) {
        log(error.message);
        return;
    } else 
        Lib.TalkativeLog('ESC > screencast execute - '+result[0]+' - '+result[1]);
}));
4

0 回答 0