Add skeleton prefs

This commit is contained in:
Neil Bird 2021-02-22 17:25:42 +00:00
parent 808581a92f
commit f9046a4b38
4 changed files with 101 additions and 0 deletions

View file

@ -0,0 +1,43 @@
// common
// defaults
var DEFAULT_URL = 'http://pi.hole/admin';
var DEFAULT_UPDATE_RATE = 20;
var DEFAULT_DISABLE_TIME = 20;
// settings labels
var URL_SETTING = 'url';
var UPDATE_RATE_SETTING = 'update-rate';
var API_KEY_SETTING = 'api-key';
// 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 });
}

View file

@ -0,0 +1,30 @@
// Prefs widget
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const ExtensionUtils = imports.misc.extensionUtils;
const Metadata = ExtensionUtils.getCurrentExtension();
const Common = Metadata.imports.common;
// Settings instance
let settings;
// Prep
function init()
{
settings = Common.getSettings(Metadata);
}
// Open
function buildPrefsWidget()
{
let prefs = new Gtk.Box({orientation: Gtk.Orientation.VERTICAL, border_width: 8, margin: 16});
prefs.set_spacing(4);
return prefs;
}

Binary file not shown.

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="gnome-shell-extension-fnxweb-pi-hole">
<schema path="/org/gnome/shell/extensions/fnxweb-pi-hole/" id="org.gnome.shell.extensions.fnxweb-pi-hole">
<key type="s" name="url">
<default>'http://pi.hole/admin'</default>
<summary>URL of pi-hole</summary>
<description>URL of the local pi-hole admin page where the api.php can be found.</description>
</key>
<key type="s" name="api-key">
<default>''</default>
<summary>API key for the local pi-hole</summary>
<description>
The API key needed to access the local pi-hole (from http://pi.hole/admin/settings.php?tab=api and
show-api-token).
</description>
</key>
<key type="i" name="update-rate">
<default>20</default>
<summary>Update rate (in seconds)</summary>
<description>The rate in seconds at which the widget will update under nornmal circumstances.</description>
</key>
<key type="i" name="disable-time">
<default>20</default>
<summary>Period (in seconds) to pause pi-hole for.</summary>
<description>The number of seconds to pause pi-hole for when the Pause option is selected.</description>
</key>
</schema>
</schemalist>