-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdbus.js
61 lines (53 loc) · 1.67 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
import Gio from "gi://Gio";
async function _getNetworkProxyAsync() {
const NetworkProxyXml = `
<node>
<interface name="org.freedesktop.NetworkManager">
<property name="PrimaryConnection" type="o" access="read"/>
</interface>
</node>`;
const NetworkProxy = Gio.DBusProxy.makeProxyWrapper(NetworkProxyXml);
const networkProxyAsync = await new Promise((resolve, reject) => {
NetworkProxy(
Gio.DBus.system,
"org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
(proxy, error) => {
if (error === null) resolve(proxy);
else reject(error);
},
null,
Gio.DBusProxyFlags.NONE
);
});
return networkProxyAsync;
}
async function _getNetworkIdProxyAsync(objectPath) {
const NetworkIdProxyXml = `
<node>
<interface name="org.freedesktop.NetworkManager.Connection.Active">
<property name="Id" type="s" access="read"/>
</interface>
</node>`;
const NetworkIdProxy = Gio.DBusProxy.makeProxyWrapper(NetworkIdProxyXml);
const networkIdProxyAsync = await new Promise((resolve, reject) => {
NetworkIdProxy(
Gio.DBus.system,
"org.freedesktop.NetworkManager",
objectPath,
(proxy, error) => {
if (error === null) resolve(proxy);
else reject(error);
},
null,
Gio.DBusProxyFlags.NONE
);
});
return networkIdProxyAsync;
}
export async function getNetworkIdAsync() {
const networkProxyAsync = await _getNetworkProxyAsync();
const primaryConnection = networkProxyAsync.PrimaryConnection;
const networkIdProxyAsync = await _getNetworkIdProxyAsync(primaryConnection);
return networkIdProxyAsync.Id;
}