From bc77e32b006ee12f143bb60e137e1324db95f82d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Rochet?= Date: Wed, 3 Nov 2021 18:50:24 +0100 Subject: [PATCH] Remove utils.js and use ExtensionUtils instead --- extension.js | 6 +++--- prefs.js | 8 +++---- utils.js | 60 ---------------------------------------------------- 3 files changed, 7 insertions(+), 67 deletions(-) delete mode 100644 utils.js diff --git a/extension.js b/extension.js index 582da4b..cce46d2 100644 --- a/extension.js +++ b/extension.js @@ -5,7 +5,7 @@ const Tweener = imports.tweener.tweener; const Gio = imports.gi.Gio const Pango = imports.gi.Pango; const extension = imports.misc.extensionUtils.getCurrentExtension(); -const Utils = extension.imports.utils; +const ExtensionUtils = imports.misc.extensionUtils; const Format = imports.format; const Gettext = imports.gettext.domain('applications-overview-tooltip'); const _ = Gettext.gettext; @@ -41,7 +41,7 @@ function init() { // Translation init String.prototype.format = Format.format; - Utils.initTranslations("applications-overview-tooltip"); + ExtensionUtils.initTranslations("applications-overview-tooltip"); } @@ -49,7 +49,7 @@ function init() { function enable() { // Settings access - _settings = Utils.getSettings(); + _settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.applications-overview-tooltip'); _applySettings(); _tooltips = new Array(); diff --git a/prefs.js b/prefs.js index 86cfede..ceff0c5 100644 --- a/prefs.js +++ b/prefs.js @@ -7,8 +7,8 @@ const GObject = imports.gi.GObject; const Gtk = imports.gi.Gtk; const Gio = imports.gi.Gio; const Lang = imports.lang; -const Me = imports.misc.extensionUtils.getCurrentExtension(); -const Utils = Me.imports.utils; +const ExtensionUtils = imports.misc.extensionUtils; +const Me = ExtensionUtils.getCurrentExtension(); const Gettext = imports.gettext.domain('applications-overview-tooltip'); const _ = Gettext.gettext; @@ -16,8 +16,8 @@ const _ = Gettext.gettext; let settings; function init() { - settings = Utils.getSettings(Me); - Utils.initTranslations("applications-overview-tooltip"); + settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.applications-overview-tooltip'); + ExtensionUtils.initTranslations("applications-overview-tooltip"); } function buildPrefsWidget(){ diff --git a/utils.js b/utils.js deleted file mode 100644 index 8ac1589..0000000 --- a/utils.js +++ /dev/null @@ -1,60 +0,0 @@ -const Gettext = imports.gettext; - -const Gio = imports.gi.Gio; - -const Config = imports.misc.config; -const ExtensionUtils = imports.misc.extensionUtils; - - -function getSettings() { - let extension = ExtensionUtils.getCurrentExtension(); - let schema = 'org.gnome.shell.extensions.applications-overview-tooltip'; - - 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}); -} - -/** - * 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); -}