From a4fac964dced50d0fd80b977e773bb150f5cdd9b Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Fri, 10 Feb 2012 17:15:31 +0000 Subject: convenience: allow system-wide installation again Check if necessary files are installed in the extension folder (as done by "make zip-file"), and if not, fallback to the standard paths. --- diff --git a/lib/convenience.js b/lib/convenience.js index 6421ef5..74c02fb 100644 --- a/lib/convenience.js +++ b/lib/convenience.js @@ -3,6 +3,7 @@ const Gettext = imports.gettext; const Gio = imports.gi.Gio; +const Config = imports.misc.config; const ExtensionUtils = imports.misc.extensionUtils; /** @@ -17,8 +18,15 @@ function initTranslations(domain) { domain = domain || extension.metadata['gettext-domain']; - let localeDir = extension.dir.get_child('locale').get_path(); - Gettext.bindtextdomain(domain, localeDir); + // check if this extension was built with "make zip-file", and thus + // has the locale files in a subfolder + // otherwise assume that extension has been installed in the + // same prefix as gnome-shell + let localeDir = extension.dir.get_child('locale'); + if (localeDir.query_exists(null)) + Gettext.bindtextdomain(domain, localeDir.get_path()); + else + Gettext.bindtextdomain(domain, Config.LOCALEDIR); } /** @@ -34,11 +42,26 @@ function getSettings(schema) { 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); + const GioSSS = Gio.SettingsSchemaSource; + + // check if this extension was built with "make zip-file", and thus + // has the schema files in a subfolder + // otherwise assume that extension has been installed in the + // same prefix as gnome-shell (and therefore schemas are available + // in the standard folders) + let schemaDir = extension.dir.get_child('schemas'); + let schemaSource; + if (schemaDir.query_exists(null)) + schemaSource = GioSSS.new_from_directory(schemaDir.get_path(), + GioSSS.get_default(), + false); + else + schemaSource = GioSSS.get_default(); + let schemaObj = schemaSource.lookup(schema, false); + if (!schemaObj) + throw new Error('Schema ' + schema + ' could not be found for extension ' + + extension.metadata.uuid + '. Please check your installation.'); return new Gio.Settings({ settings_schema: schemaObj }); } -- cgit v0.9.0.2