forked from sakithb/media-controls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbus.js
65 lines (61 loc) · 2.2 KB
/
dbus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"use strict";
const { Gio, GLib } = imports.gi;
const ifacesXml = `
<node>
<interface name="org.mpris.MediaPlayer2.Player">
<method name="Next" />
<method name="Previous" />
<method name="PlayPause" />
<method name="Play" />
<method name="Pause" />
<property name="PlaybackStatus" type="s" access="read" />
<property name="Metadata" type="a{sv}" access="read" />
<property name="LoopStatus" type="s" access="readwrite" />
<property name="Shuffle" type="b" access="readwrite" />
<property name="CanControl" type="b" access="read" />
</interface>
<interface name="org.mpris.MediaPlayer2">
<method name="Raise" />
<method name="Quit" />
<property name="Identity" type="s" access="read" />
<property name="DesktopEntry" type="s" access="read" />
</interface>
<interface name="org.freedesktop.DBus">
<method name='ListNames'>
<arg type='as' direction='out' />
</method>
<signal name='NameOwnerChanged'>
<arg type='s'/>
<arg type='s'/>
<arg type='s'/>
</signal>
</interface>
</node>
`;
const nodeInfo = Gio.DBusNodeInfo.new_for_xml(ifacesXml);
const createProxy = (ifaceName, busName, objectPath, flags = Gio.DBusProxyFlags.NONE) => {
return new Promise((resolve, reject) => {
let ifaceInfo = nodeInfo.interfaces.find((iface) => iface.name == ifaceName);
if (ifaceInfo) {
Gio.DBusProxy.new(
Gio.DBus.session,
flags,
ifaceInfo,
busName,
objectPath,
ifaceName,
null,
(source, result) => {
try {
let proxy = Gio.DBusProxy.new_finish(result);
resolve(proxy);
} catch (error) {
reject(error);
}
}
);
} else {
reject(new Error("Interface not found"));
}
});
};