From b01da20a2bca6a7950fedea0d87d6975bbf1ee9c Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Feb 09 2019 05:47:54 +0000 Subject: cleanup: Drop convenience library Its methods are now provided by gnome-shell itself and can be used as an easy drop-in replacement. https://pagure.io/background-logo-extension/pull-request/12 --- diff --git a/convenience.js b/convenience.js deleted file mode 100644 index e000f3f..0000000 --- a/convenience.js +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */ -/* - Copyright (c) 2011-2012, Giovanni Campagna - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the GNOME nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -const Gettext = imports.gettext; -const Gio = imports.gi.Gio; - -const Config = imports.misc.config; -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']; - - // 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); -} - -/** - * 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']; - - 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, true); - 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 }); -} diff --git a/extension.js b/extension.js index e99c21e..e61b882 100644 --- a/extension.js +++ b/extension.js @@ -17,21 +17,18 @@ const { Clutter, Gio, St } = imports.gi; const Background = imports.ui.background; +const ExtensionUtils = imports.misc.extensionUtils; const Layout = imports.ui.layout; const Main = imports.ui.main; const Tweener = imports.ui.tweener; -const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); -const Convenience = Me.imports.convenience; - class BackgroundLogo { constructor(bgManager) { this._bgManager = bgManager; this._logoFile = null; - this._settings = Convenience.getSettings(); + this._settings = ExtensionUtils.getSettings(); this._settings.connect('changed::logo-file', this._updateLogo.bind(this)); diff --git a/meson.build b/meson.build index 464c65e..c7d18b7 100644 --- a/meson.build +++ b/meson.build @@ -7,7 +7,7 @@ sources = [ 'extension.js', 'prefs.js' ] -extra_sources = ['COPYING', 'convenience.js'] +extra_sources = ['COPYING'] schemas = ['org.fedorahosted.background-logo-extension'] diff --git a/prefs.js b/prefs.js index 4470e75..6c018c0 100644 --- a/prefs.js +++ b/prefs.js @@ -1,8 +1,6 @@ const { Gdk, GdkPixbuf, Gio, GnomeDesktop, GObject, Gtk } = imports.gi; const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); -const Convenience = Me.imports.convenience; const BACKGROUND_SCHEMA = 'org.gnome.desktop.background'; @@ -20,7 +18,7 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { this.connect('screen-changed', this._onScreenChanged.bind(this)); - this._settings = Convenience.getSettings(); + this._settings = ExtensionUtils.getSettings(); this._settings.connect('changed', (settings, key) => { if (key == 'logo-file' || key == 'logo-size')