2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-11-25 21:54:44 +00:00
|
|
|
/* exported collectFromDatadirs, recursivelyDeleteDir,
|
2020-04-23 18:46:44 +00:00
|
|
|
recursivelyMoveDir, loadInterfaceXML, loadSubInterfaceXML */
|
2011-09-28 13:16:26 +00:00
|
|
|
|
2019-02-09 03:21:36 +00:00
|
|
|
const { Gio, GLib } = imports.gi;
|
2018-09-06 00:04:47 +00:00
|
|
|
const Config = imports.misc.config;
|
2010-09-30 21:08:22 +00:00
|
|
|
|
2013-11-04 15:07:44 +00:00
|
|
|
function collectFromDatadirs(subdir, includeUserDir, processFile) {
|
2012-11-30 15:36:12 +00:00
|
|
|
let dataDirs = GLib.get_system_data_dirs();
|
2013-11-04 15:07:44 +00:00
|
|
|
if (includeUserDir)
|
2012-11-30 15:36:12 +00:00
|
|
|
dataDirs.unshift(GLib.get_user_data_dir());
|
|
|
|
|
|
|
|
for (let i = 0; i < dataDirs.length; i++) {
|
|
|
|
let path = GLib.build_filenamev([dataDirs[i], 'gnome-shell', subdir]);
|
|
|
|
let dir = Gio.File.new_for_path(path);
|
|
|
|
|
2013-11-04 15:07:44 +00:00
|
|
|
let fileEnum;
|
|
|
|
try {
|
|
|
|
fileEnum = dir.enumerate_children('standard::name,standard::type',
|
|
|
|
Gio.FileQueryInfoFlags.NONE, null);
|
|
|
|
} catch (e) {
|
|
|
|
fileEnum = null;
|
|
|
|
}
|
|
|
|
if (fileEnum != null) {
|
|
|
|
let info;
|
|
|
|
while ((info = fileEnum.next_file(null)))
|
|
|
|
processFile(fileEnum.get_child(info), info);
|
|
|
|
}
|
2012-11-30 15:36:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-27 00:47:44 +00:00
|
|
|
function recursivelyDeleteDir(dir, deleteParent) {
|
2011-09-10 21:10:50 +00:00
|
|
|
let children = dir.enumerate_children('standard::name,standard::type',
|
|
|
|
Gio.FileQueryInfoFlags.NONE, null);
|
|
|
|
|
2019-01-31 14:04:56 +00:00
|
|
|
let info;
|
2011-09-10 21:10:50 +00:00
|
|
|
while ((info = children.next_file(null)) != null) {
|
|
|
|
let type = info.get_file_type();
|
|
|
|
let child = dir.get_child(info.get_name());
|
|
|
|
if (type == Gio.FileType.REGULAR)
|
2019-11-25 21:54:44 +00:00
|
|
|
child.delete(null);
|
2011-12-01 02:46:52 +00:00
|
|
|
else if (type == Gio.FileType.DIRECTORY)
|
2012-06-27 00:47:44 +00:00
|
|
|
recursivelyDeleteDir(child, true);
|
2011-09-10 21:10:50 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 00:47:44 +00:00
|
|
|
if (deleteParent)
|
2019-11-25 21:54:44 +00:00
|
|
|
dir.delete(null);
|
2012-06-27 00:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function recursivelyMoveDir(srcDir, destDir) {
|
|
|
|
let children = srcDir.enumerate_children('standard::name,standard::type',
|
|
|
|
Gio.FileQueryInfoFlags.NONE, null);
|
|
|
|
|
|
|
|
if (!destDir.query_exists(null))
|
|
|
|
destDir.make_directory_with_parents(null);
|
|
|
|
|
2019-01-31 14:04:56 +00:00
|
|
|
let info;
|
2012-06-27 00:47:44 +00:00
|
|
|
while ((info = children.next_file(null)) != null) {
|
|
|
|
let type = info.get_file_type();
|
|
|
|
let srcChild = srcDir.get_child(info.get_name());
|
|
|
|
let destChild = destDir.get_child(info.get_name());
|
|
|
|
if (type == Gio.FileType.REGULAR)
|
|
|
|
srcChild.move(destChild, Gio.FileCopyFlags.NONE, null, null);
|
|
|
|
else if (type == Gio.FileType.DIRECTORY)
|
|
|
|
recursivelyMoveDir(srcChild, destChild);
|
|
|
|
}
|
2011-09-10 21:10:50 +00:00
|
|
|
}
|
2018-09-06 00:04:47 +00:00
|
|
|
|
|
|
|
let _ifaceResource = null;
|
2020-04-23 18:46:44 +00:00
|
|
|
function ensureIfaceResource() {
|
|
|
|
if (_ifaceResource)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// don't use global.datadir so the method is usable from tests/tools
|
|
|
|
let dir = GLib.getenv('GNOME_SHELL_DATADIR') || Config.PKGDATADIR;
|
|
|
|
let path = `${dir}/gnome-shell-dbus-interfaces.gresource`;
|
|
|
|
_ifaceResource = Gio.Resource.load(path);
|
|
|
|
_ifaceResource._register();
|
|
|
|
}
|
|
|
|
|
2018-09-06 00:04:47 +00:00
|
|
|
function loadInterfaceXML(iface) {
|
2020-04-23 18:46:44 +00:00
|
|
|
ensureIfaceResource();
|
2018-09-06 00:04:47 +00:00
|
|
|
|
2019-10-29 18:21:21 +00:00
|
|
|
let uri = `resource:///org/gnome/shell/dbus-interfaces/${iface}.xml`;
|
2018-09-06 00:04:47 +00:00
|
|
|
let f = Gio.File.new_for_uri(uri);
|
|
|
|
|
|
|
|
try {
|
2019-01-31 14:08:00 +00:00
|
|
|
let [ok_, bytes] = f.load_contents(null);
|
2021-08-12 14:38:57 +00:00
|
|
|
return new TextDecoder().decode(bytes);
|
2018-09-06 00:04:47 +00:00
|
|
|
} catch (e) {
|
2019-01-30 00:18:24 +00:00
|
|
|
log(`Failed to load D-Bus interface ${iface}`);
|
2018-09-06 00:04:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-07 18:28:48 +00:00
|
|
|
return null;
|
2018-09-06 00:04:47 +00:00
|
|
|
}
|
2020-04-23 18:46:44 +00:00
|
|
|
|
|
|
|
function loadSubInterfaceXML(iface, ifaceFile) {
|
|
|
|
let xml = loadInterfaceXML(ifaceFile);
|
|
|
|
if (!xml)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
let ifaceStartTag = `<interface name="${iface}">`;
|
|
|
|
let ifaceStopTag = '</interface>';
|
|
|
|
let ifaceStartIndex = xml.indexOf(ifaceStartTag);
|
|
|
|
let ifaceEndIndex = xml.indexOf(ifaceStopTag, ifaceStartIndex + 1) + ifaceStopTag.length;
|
|
|
|
|
|
|
|
let xmlHeader = '<!DOCTYPE node PUBLIC\n' +
|
|
|
|
'\'-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\'\n' +
|
|
|
|
'\'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\'>\n' +
|
|
|
|
'<node>\n';
|
|
|
|
let xmlFooter = '</node>';
|
|
|
|
|
|
|
|
return (
|
|
|
|
xmlHeader +
|
|
|
|
xml.substr(ifaceStartIndex, ifaceEndIndex - ifaceStartIndex) +
|
|
|
|
xmlFooter);
|
|
|
|
}
|