convenience: update for the new extension API
Extension helper and metadata are now different objects, so the first needs be retrieved from ExtensionUtils. Also, reduce the number of required arguments (by using the new metadata keys) and make generic enough for usage by other extensions. Includes documentation.
This commit is contained in:
+37
-9
@@ -1,17 +1,45 @@
|
||||
/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||
|
||||
const Gettext = imports.gettext;
|
||||
const Gio = imports.gi.Gio;
|
||||
|
||||
function initTranslations(metadata) {
|
||||
let localeDir = metadata.dir.get_child('locale').get_path();
|
||||
Gettext.bindtextdomain('gnome-shell-extensions', localeDir);
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
|
||||
/**
|
||||
* initTranslations:
|
||||
* @domain: (optional): the gettext domain to use
|
||||
*
|
||||
* Initialize Gettext to load translations from extensionsdir/locale.
|
||||
* If @domain is not provided, it will be taken from metadata['gettext-domain']
|
||||
*/
|
||||
function initTranslations(domain) {
|
||||
let extension = ExtensionUtils.getCurrentExtension();
|
||||
|
||||
domain = domain || extension.metadata['gettext-domain'];
|
||||
|
||||
let localeDir = extension.dir.get_child('locale').get_path();
|
||||
Gettext.bindtextdomain(domain, localeDir);
|
||||
}
|
||||
|
||||
function getSettings(metadata, extension_id) {
|
||||
let schemaDir = metadata.dir.get_child('schemas').get_path();
|
||||
/**
|
||||
* getSettings:
|
||||
* @schema: (optional): the GSettings schema id
|
||||
*
|
||||
* Builds and return a GSettings schema for @schema, using schema files
|
||||
* in extensionsdir/schemas. If @schema is not provided, it is taken from
|
||||
* metadata['settings-schema'].
|
||||
*/
|
||||
function getSettings(schema) {
|
||||
let extension = ExtensionUtils.getCurrentExtension();
|
||||
|
||||
schema = schema || extension.metadata['settings-schema'];
|
||||
|
||||
let schemaDir = extension.dir.get_child('schemas').get_path();
|
||||
let schemaSource = Gio.SettingsSchemaSource.new_from_directory(schemaDir,
|
||||
Gio.SettingsSchemaSource.get_default(),
|
||||
false);
|
||||
let schema = schemaSource.lookup('org.gnome.shell.extensions.' + extension_id, false);
|
||||
return new Gio.Settings({ settings_schema: schema });
|
||||
Gio.SettingsSchemaSource.get_default(),
|
||||
false);
|
||||
let schemaObj = schemaSource.lookup(schema, false);
|
||||
|
||||
return new Gio.Settings({ settings_schema: schemaObj });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user