Review actions – Use initTranslations() and getSettings() from ExtensionUtils

This commit is contained in:
Neil Bird 2022-05-17 17:11:41 +01:00
parent 95fe445880
commit 924d6e200f
3 changed files with 4 additions and 52 deletions

View file

@ -8,51 +8,3 @@ var URL_SETTING = 'url';
var API_KEY_SETTING = 'api-key';
var UPDATE_RATE_SETTING = 'update-rate';
var DISABLE_TIME_SETTING = 'disable-time';
// Access to settings
function getSettings(extension)
{
let 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 });
}
// Initialize Gettext to load translations from extensionsdir/locale.
function initTranslations(extension)
{
let 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);
}

View file

@ -24,7 +24,7 @@ class PiHole extends panelMenu.Button
{
// Core setup
super._init( null, IndicatorName );
Common.initTranslations( PiHoleExtMetadata );
ExtensionUtils.initTranslations();
this.Name = IndicatorName;
// Debug
@ -60,7 +60,7 @@ class PiHole extends panelMenu.Button
this.SettingChangedHandlerIds= null;
// Settings
this.Settings = Common.getSettings( PiHoleExtMetadata );
this.Settings = ExtensionUtils.getSettings();
this.Url = this.Settings.get_string( Common.URL_SETTING );
this.ApiKey = this.Settings.get_string( Common.API_KEY_SETTING );
this.UpdateTime = this.Settings.get_uint( Common.UPDATE_RATE_SETTING );

View file

@ -13,7 +13,7 @@ const Common = Metadata.imports.common;
// Prep
function init()
{
Common.initTranslations(Metadata);
ExtensionUtils.initTranslations();
}
@ -21,7 +21,7 @@ function init()
function buildPrefsWidget()
{
// Create
let settings = Common.getSettings(Metadata);
let settings = ExtensionUtils.getSettings();
let prefs = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
margin_top: 8,