-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdbusUtils.js
367 lines (333 loc) · 12.9 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/* LICENSE INFORMATION
*
* Desktop Icons: Neo - A desktop icons extension for GNOME with numerous features,
* customizations, and optimizations.
*
* Copyright 2021 Abdurahman Elmawi ([email protected])
*
* This project is based on Desktop Icons NG (https://gitlab.com/rastersoft/desktop-icons-ng),
* a desktop icons extension for GNOME licensed under the GPL v3.
*
* This project is free and open source software as described in the GPL v3.
*
* This project (Desktop Icons: Neo) is licensed under the GPL v3. To view the details of this license,
* visit https://www.gnu.org/licenses/gpl-3.0.html for the necessary information
* regarding this project's license.
*/
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
var NautilusFileOperations2Proxy;
var FreeDesktopFileManagerProxy;
var GnomeNautilusPreviewProxy;
var SwitcherooControlProxyClass;
var SwitcherooControlProxy;
var discreteGpuAvailable;
var GnomeArchiveManagerProxy;
var GtkVfsMetadataProxy;
const NautilusFileOperations2Interface = `<node>
<interface name='org.gnome.Nautilus.FileOperations2'>
<method name='CopyURIs'>
<arg type='as' name='sources' direction='in'/>
<arg type='s' name='destination' direction='in'/>
<arg type='a{sv}' name='platform_data' direction='in'/>
</method>
<method name='MoveURIs'>
<arg type='as' name='sources' direction='in'/>
<arg type='s' name='destination' direction='in'/>
<arg type='a{sv}' name='platform_data' direction='in'/>
</method>
<method name='EmptyTrash'>
<arg type="b" name="ask_confirmation" direction='in'/>
<arg type='a{sv}' name='platform_data' direction='in'/>
</method>
<method name='TrashURIs'>
<arg type='as' name='uris' direction='in'/>
<arg type='a{sv}' name='platform_data' direction='in'/>
</method>
<method name='DeleteURIs'>
<arg type='as' name='uris' direction='in'/>
<arg type='a{sv}' name='platform_data' direction='in'/>
</method>
<method name='CreateFolder'>
<arg type='s' name='parent_uri' direction='in'/>
<arg type='s' name='new_folder_name' direction='in'/>
<arg type='a{sv}' name='platform_data' direction='in'/>
</method>
<method name='RenameURI'>
<arg type='s' name='uri' direction='in'/>
<arg type='s' name='new_name' direction='in'/>
<arg type='a{sv}' name='platform_data' direction='in'/>
</method>
<method name='Undo'>
<arg type='a{sv}' name='platform_data' direction='in'/>
</method>
<method name='Redo'>
<arg type='a{sv}' name='platform_data' direction='in'/>
</method>
<property name="UndoStatus" type="i" access="read"/>
</interface>
</node>`;
const NautilusFileOperations2ProxyInterface = Gio.DBusProxy.makeProxyWrapper(NautilusFileOperations2Interface);
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);
const GnomeNautilusPreviewInterface = `<node>
<interface name='org.gnome.NautilusPreviewer'>
<method name='ShowFile'>
<arg name='FileUri' type='s' direction='in'/>
<arg name='ParentXid' type='i' direction='in'/>
<arg name='CloseIfShown' type='b' direction='in'/>
</method>
</interface>
</node>`;
const GnomeNautilusPreviewProxyInterface = Gio.DBusProxy.makeProxyWrapper(GnomeNautilusPreviewInterface);
const SwitcherooControlInterface = `<node>
<interface name="net.hadess.SwitcherooControl">
<property name="HasDualGpu" type="b" access="read"/>
<property name="NumGPUs" type="u" access="read"/>
<property name="GPUs" type="aa{sv}" access="read"/>
</interface>
</node>`;
const SWITCHEROO_CONTROL_BUS_NAME = 'net.hadess.SwitcherooControl';
function _switcherooProxyAppeared() {
SwitcherooControlProxyClass = Gio.DBusProxy.makeProxyWrapper(SwitcherooControlInterface);
SwitcherooControlProxy = new SwitcherooControlProxyClass(Gio.DBus.system,
SWITCHEROO_CONTROL_BUS_NAME,
'/net/hadess/SwitcherooControl',
(proxy, error) => {
if (error) {
discreteGpuAvailable = false;
log(error.message);
return;
}
discreteGpuAvailable = SwitcherooControlProxy.HasDualGpu;
});
}
const GnomeArchiveManagerInterface = `<node>
<!-- org.gnome.ArchiveManager1:
@short_description: Create and extract compressed archives
This D-Bus interface is used to create and extract compressed archives.
-->
<interface name="org.gnome.ArchiveManager1">
<!--
GetSupportedTypes:
@action: Can be one of the following values:
*) create: create an archive that can contain many files.
*) create_single_file: create an archive that can contain a single file.
*) extract: extract the content of an archive.
@types: The supported archive types described as an array of hash tables,
where each hash table has the following keys:
*) mime-type: the mime type relative to the archive type.
*) default-extension: the extension to use for newly created archives.
*) description: a human readable description of the archive type.
Returns the supported archive types for a specific action.
-->
<method name="GetSupportedTypes">
<arg name="action" type="s" direction="in"/>
<arg name="types" type="aa{ss}" direction="out"/>
</method>
<!--
AddToArchive:
@archive: The archive URI.
@files: The files to add to the archive, as an array of URIs.
@use_progress_dialog: Whether to show the progress dialog.
Adds the specified files to an archive. If the archive already
exists the archive is updated.
-->
<method name="AddToArchive">
<arg name="archive" type="s" direction="in"/>
<arg name="files" type="as" direction="in"/>
<arg name="use_progress_dialog" type="b" direction="in"/>
</method>
<!--
Compress:
@files: The files to add to the archive, as an array of URIs.
@destination: An optional destination, if not specified the folder of
the first file in @files is used.
@use_progress_dialog: Whether to show the progress dialog.
Compresses a series of files in an archive. The user is asked to
enter an archive name, archive type and other options. In this case
it's used the same dialog used by the "Compress..." command from the
Nautilus context menu.
If the user chooses an existing archive, the archive is updated.
-->
<method name='Compress'>
<arg name="files" type="as" direction="in"/>
<arg name="destination" type="s" direction="in"/>
<arg name="use_progress_dialog" type="b" direction="in"/>
</method>
<!--
Extract:
@archive: The archive to extract.
@destination: The location where to extract the archive.
@use_progress_dialog: Whether to show the progress dialog.
Extract an archive in a specified location.
-->
<method name="Extract">
<arg name="archive" type="s" direction="in"/>
<arg name="destination" type="s" direction="in"/>
<arg name="use_progress_dialog" type="b" direction="in"/>
</method>
<!--
ExtractHere:
@archive: The archive to extract.
@use_progress_dialog: Whether to show the progress dialog.
Extract an archive in the archive's folder.
-->
<method name="ExtractHere">
<arg name="archive" type="s" direction="in"/>
<arg name="use_progress_dialog" type="b" direction="in"/>
</method>
<!--
Progress:
@fraction: number from 0.0 to 100.0 that indicates the percentage of
completion of the operation.
@details: text message that describes the current operation.
-->
<signal name="Progress">
<arg name="fraction" type="d"/>
<arg name="details" type="s"/>
</signal>
</interface>
</node>`
const GnomeArchiveManagerProxyInterface = Gio.DBusProxy.makeProxyWrapper(GnomeArchiveManagerInterface);
const GtkVfsMetadataInterface = `<node>
<interface name='org.gtk.vfs.Metadata'>
<method name="Set">
<arg type='ay' name='treefile' direction='in'/>
<arg type='ay' name='path' direction='in'/>
<arg type='a{sv}' name='data' direction='in'/>
</method>
<method name="Remove">
<arg type='ay' name='treefile' direction='in'/>
<arg type='ay' name='path' direction='in'/>
</method>
<method name="Move">
<arg type='ay' name='treefile' direction='in'/>
<arg type='ay' name='path' direction='in'/>
<arg type='ay' name='dest_path' direction='in'/>
</method>
<method name="GetTreeFromDevice">
<arg type='u' name='major' direction='in'/>
<arg type='u' name='minor' direction='in'/>
<arg type='s' name='tree' direction='out'/>
</method>
<signal name="AttributeChanged">
<arg type='s' name='tree_path'/>
<arg type='s' name='file_path'/>
</signal>
</interface>
</node>`
const GtkVfsMetadataProxyInterface = Gio.DBusProxy.makeProxyWrapper(GtkVfsMetadataInterface);
function init() {
NautilusFileOperations2Proxy = new NautilusFileOperations2ProxyInterface(
Gio.DBus.session,
'org.gnome.Nautilus',
'/org/gnome/Nautilus/FileOperations2',
(proxy, error) => {
if (error) {
log('Error connecting to Nautilus');
}
}
);
NautilusFileOperations2Proxy.platformData = params => {
const inShell = typeof global !== 'undefined';
const defaultParams = {
timestamp: inShell ? global.get_current_time() :
imports.gi.Gtk.get_current_event_time(),
parentWindow: inShell ? null :
imports.gi.Gtk.get_current_event().get_window(),
windowPosition: 'center',
};
const { parentWindow, timestamp, windowPosition } = {
...defaultParams,
...params,
};
//Get rid of ?? that would error out old GNOME versions
let { parentHandle } = { parentHandle: '' };
if(params !== null && params !== undefined){
parentHandle = params;
}
if (!parentHandle && parentWindow) {
try {
imports.gi.versions.GdkX11 = '3.0';
const { GdkX11 } = imports.gi;
const topLevel = parentWindow.get_effective_toplevel();
if (topLevel.constructor.$gtype === GdkX11.X11Window.$gtype) {
const xid = GdkX11.X11Window.prototype.get_xid.call(topLevel);
parentHandle = `x11:${xid}`;
} /* else if (topLevel instanceof GdkWayland.Toplevel) {
FIXME: Need Gtk4 to use GdkWayland
const handle = GdkWayland.Toplevel.prototype.export_handle.call(topLevel);
parentHandle = `wayland:${handle}`;
} */
} catch (e) {
logError(e, 'Impossible to determine the parent window');
}
}
return {
'parent-handle': new GLib.Variant('s', parentHandle),
'timestamp': new GLib.Variant('u', timestamp),
'window-position': new GLib.Variant('s', windowPosition),
};
}
FreeDesktopFileManagerProxy = new FreeDesktopFileManagerProxyInterface(
Gio.DBus.session,
'org.freedesktop.FileManager1',
'/org/freedesktop/FileManager1',
(proxy, error) => {
if (error) {
log('Error connecting to Nautilus');
}
}
);
GnomeNautilusPreviewProxy = new GnomeNautilusPreviewProxyInterface(
Gio.DBus.session,
'org.gnome.NautilusPreviewer',
'/org/gnome/NautilusPreviewer',
(proxy, error) => {
if (error) {
log('Error connecting to Nautilus Previewer');
}
}
);
SwitcherooControlProxy = null;
discreteGpuAvailable = false;
Gio.DBus.system.watch_name(SWITCHEROO_CONTROL_BUS_NAME,
Gio.BusNameWatcherFlags.NONE,
_switcherooProxyAppeared,
() => {
SwitcherooControlProxy = null;
discreteGpuAvailable = false;
});
GnomeArchiveManagerProxy = new GnomeArchiveManagerProxyInterface(
Gio.DBus.session,
'org.gnome.ArchiveManager1',
'/org/gnome/ArchiveManager1',
(proxy, error) => {
if (error) {
log('Error connecting to ArchiveManager');
}
}
);
GtkVfsMetadataProxy = new GtkVfsMetadataProxyInterface(
Gio.DBus.session,
'org.gtk.vfs.Metadata',
'/org/gtk/vfs/metadata',
(proxy, error) => {
if (error) {
log('Error connecting to Gio VFS metadata');
}
}
);
}