-
Notifications
You must be signed in to change notification settings - Fork 3
/
configuration.js
69 lines (56 loc) · 2.1 KB
/
configuration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const Gio = imports.gi.Gio;
function getSettings(schemaDir) {
if (!Gio.File.new_for_path(schemaDir).query_exists(null)) {
throw new Error("DND schema dir " + schemaDir + " not found.");
}
let GioSSS = Gio.SettingsSchemaSource;
// - g_settings_schema_source_new_from_directory(const gchar *directory, GSettingsSchemaSource *parent, gboolean trusted)
// - requires "gschemas.compiled" in directory
// - is a special file format, with first bytes "GVariant"
// - glib-compile-schemas uses gvdb_table_write_contents() to create gschemas.compiled, gio/glib-compile-schemas.c;
// too complex to make it yourself, let's store it in repository
let schemaSrc = GioSSS.new_from_directory(
schemaDir,
GioSSS.get_default(),
false,
);
let schema = "[email protected]";
// g_settings_schema_source_lookup(GSettingsSchemaSource *source, const gchar *schema_id, gboolean recursive)
let schemaObj = schemaSrc.lookup(schema, true);
if (!schemaObj) throw new Error("Schema " + schema + " not found.");
// g_settings_new_full (GSettingsSchema *schema, GSettingsBackend *backend, const gchar *path)
return new Gio.Settings({ settings_schema: schemaObj });
}
function main() {
let schemaDir = "./schemas";
imports.searchPath.unshift(".");
const execCmd = imports.pactl.execCmd;
execCmd("glib-compile-schemas " + schemaDir);
let settings = getSettings(schemaDir);
// dconf-editor
let muteAudio = settings.get_boolean("mute-audio");
log(muteAudio);
// /org/gnome/shell/extensions/[email protected]/
log(settings.path);
log(settings.schema);
// DConfSettingsBackend
log(settings.backend);
settings.connect("changed::mute-audio", function() {
log("ups!");
});
const GLib = imports.gi.GLib;
const Mainloop = imports.mainloop;
Mainloop.timeout_add(2 * 1000, function() {
settings.set_boolean("mute-audio", !muteAudio);
Mainloop.quit();
return GLib.SOURCE_REMOVE;
});
Mainloop.run();
}
if (
new Error().stack.split(/\r\n|\r|\n/g).filter(line => line.length > 0)
.length == 1
) {
main();
}