RandomWallpaperGnome3/randomwallpaper@iflow.space/settings.js

42 lines
921 B
JavaScript
Raw Permalink Normal View History

const Lang = imports.lang;
const Glib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const Self = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Self.imports.convenience;
var Settings = new Lang.Class({
2017-07-20 18:54:23 +00:00
Name: "Settings",
_settings: null,
2017-07-20 18:54:23 +00:00
/**
* Settings object.
*
* @param [schema]
* @private
*/
_init: function (schema) {
this._settings = Convenience.getSettings(schema);
},
2017-07-20 18:54:23 +00:00
observe: function (key, callback) {
return this._settings.connect('changed::' + key, callback);
},
disconnect: function (handler) {
return this._settings.disconnect(handler);
2017-07-20 18:54:23 +00:00
},
2017-07-20 18:54:23 +00:00
set: function (key, type, value) {
if (this._settings['set_' + type](key, value)) {
Gio.Settings.sync(); // wait for write
} else {
throw "Could not set " + key + " (type: " + type + ") with the value " + value;
}
},
2017-07-20 18:54:23 +00:00
get: function (key, type) {
return this._settings['get_' + type](key);
}
});