-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommon.js
58 lines (44 loc) · 1.7 KB
/
common.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
const Gio = imports.gi.Gio;
const PopupMenu = imports.ui.popupMenu;
const Gettext = imports.gettext;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const optionsUtils = Me.imports.optionsUtils;
const Domain = Gettext.domain(Me.metadata.uuid);
const { gettext, ngettext } = Domain;
const _ = gettext;
function getIcon() {
return Gio.icon_new_for_string(Me.dir.get_path() + "/icons/controls-big-symbolic.svg");
}
function addOptionsToMenu(menu) {
const settings = ExtensionUtils.getSettings();
const options = optionsUtils.getOptions();
const translatedOptions = optionsUtils.getTranslatedOptions();
// Create a switch item for each option
for (let i = 0; i < options.length; i++) {
// Convert option title to schema key, i.e. "Camera Lock" becomes "camera-lock-option"
const optionKey = options[i].toLowerCase().replace(" ", "-") + "-option";
const optionSwitch = new PopupMenu.PopupSwitchMenuItem(translatedOptions[i], optionsUtils.getOptionValue(i) === "1");
menu.addMenuItem(optionSwitch);
settings.bind(
optionKey,
optionSwitch,
"visible",
Gio.SettingsBindFlags.DEFAULT
);
optionSwitch.connect("toggled", () => {
optionsUtils.getOptionValue(i);
optionsUtils.setOptionValue(i, optionSwitch.state ? 1 : 0);
});
}
// Setting button
menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
const settingsButton = new PopupMenu.PopupMenuItem(_("Extension Settings"));
settingsButton.connect("activate", () => ExtensionUtils.openPrefs());
menu.addMenuItem(settingsButton);
settings.bind(
"settings-button",
settingsButton,
"visible",
Gio.SettingsBindFlags.DEFAULT);
}