-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbusUtils.js
103 lines (96 loc) · 3.74 KB
/
dbusUtils.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
var NautilusFileOperationsProxy;
var FreeDesktopFileManagerProxy;
const NautilusFileOperationsInterface = `<node>
<interface name='org.gnome.Nautilus.FileOperations'>
<method name='CopyURIs'>
<arg name='URIs' type='as' direction='in'/>
<arg name='Destination' type='s' direction='in'/>
</method>
<method name='MoveURIs'>
<arg name='URIs' type='as' direction='in'/>
<arg name='Destination' type='s' direction='in'/>
</method>
<method name='EmptyTrash'>
</method>
<method name='TrashFiles'>
<arg name='URIs' type='as' direction='in'/>
</method>
<method name='CreateFolder'>
<arg name='URI' type='s' direction='in'/>
</method>
<method name='RenameFile'>
<arg name='URI' type='s' direction='in'/>
<arg name='NewName' type='s' direction='in'/>
</method>
<method name='Undo'>
</method>
<method name='Redo'>
</method>
<property name='UndoStatus' type='i' access='read'/>
</interface>
</node>`;
const NautilusFileOperationsProxyInterface = Gio.DBusProxy.makeProxyWrapper(NautilusFileOperationsInterface);
const FreeDesktopFileManagerInterface = `<node>
<interface name='org.freedesktop.FileManager1'>
<method name='ShowItems'>
<arg name='URIs' type='as' direction='in'/>
<arg name='StartupId' type='s' direction='in'/>
</method>
<method name='ShowItemProperties'>
<arg name='URIs' type='as' direction='in'/>
<arg name='StartupId' type='s' direction='in'/>
</method>
</interface>
</node>`;
const FreeDesktopFileManagerProxyInterface = Gio.DBusProxy.makeProxyWrapper(FreeDesktopFileManagerInterface);
function init() {
NautilusFileOperationsProxy = new NautilusFileOperationsProxyInterface(
Gio.DBus.session,
'org.gnome.Nautilus',
'/org/gnome/Nautilus',
(proxy, error) => {
if (error) {
log('Error connecting to Nautilus');
}
}
);
FreeDesktopFileManagerProxy = new FreeDesktopFileManagerProxyInterface(
Gio.DBus.session,
'org.freedesktop.FileManager1',
'/org/freedesktop/FileManager1',
(proxy, error) => {
if (error) {
log('Error connecting to Nautilus');
}
}
);
}
function openFileWithOtherApplication(filePath) {
let fdList = new Gio.UnixFDList();
let channel = GLib.IOChannel.new_file(filePath, "r");
fdList.append(channel.unix_get_fd());
channel.set_close_on_unref(true);
let builder = GLib.VariantBuilder.new(GLib.VariantType.new("a{sv}"));
let options = builder.end();
let parameters = GLib.Variant.new_tuple([GLib.Variant.new_string("0"),
GLib.Variant.new_handle(0),
options]);
Gio.bus_get(Gio.BusType.SESSION, null,
(source, result) => {
let dbus_connection = Gio.bus_get_finish(result);
dbus_connection.call_with_unix_fd_list("org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.OpenURI",
"OpenFile",
parameters,
GLib.VariantType.new("o"),
Gio.DBusCallFlags.NONE,
-1,
fdList,
null,
null);
}
);
}