-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.js
126 lines (98 loc) · 3.19 KB
/
prefs.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict';
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
//gsettings
const GS_SCHEMA = "org.gnome.shell.extensions.wg-indicator";
const GS_KEY_TIMEOUT = "refresh-delay";
const GS_KEY_ICONPATH = "theme";
//Get shell version
var Config = imports.misc.config;
var [major] = Config.PACKAGE_VERSION.split('.');
var shellVersion = Number.parseInt(major);
const THEMES = {
"Colored": "color",
"Black": "black",
"White": "white"
}
function init() {
}
function buildPrefsWidget() {
this.settings = ExtensionUtils.getSettings(
GS_SCHEMA
);
let prefsWidget = new Gtk.Grid({
"margin-start": 18,
"margin-end": 18,
"margin-top": 18,
"margin-bottom": 18,
column_spacing: 12,
row_spacing: 12,
visible: true
});
//Refresh Rate chooser
let refreshLabel = new Gtk.Label({
label: "Refresh delay:",
halign: Gtk.Align.START,
visible: true
});
let refreshField = new Gtk.Entry({
text: this.settings.get_int(GS_KEY_TIMEOUT).toString(),
halign: Gtk.Align.START,
visible: true
});
refreshField.connect('changed', function(inputField) {
settings.set_int(GS_KEY_TIMEOUT, parseInt(inputField.get_text()));
});
prefsWidget.attach(refreshLabel, 0, 1, 1, 1);
prefsWidget.attach_next_to(refreshField, refreshLabel, Gtk.PositionType.RIGHT, 1, 1);
//Theme chooser
let themeLabel = new Gtk.Label({
label: 'Icon theme:',
halign: Gtk.Align.START,
visible: true
});
let themeChooser = new Gtk.ComboBoxText({
halign: Gtk.Align.START,
visible: true,
});
for (let themeName in THEMES){
themeChooser.append(THEMES[themeName], themeName);
}
themeChooser.set_active_id(this.settings.get_string(GS_KEY_ICONPATH));
prefsWidget.attach(themeLabel, 0, 2, 1, 1);
prefsWidget.attach_next_to(themeChooser, themeLabel, Gtk.PositionType.RIGHT, 1, 1);
//Set theme
var settings = this.settings;
themeChooser.connect('changed', function(themeWidget) {
settings.set_string(GS_KEY_ICONPATH, themeWidget.get_active_id());
});
//Github link
let githubLabel = new Gtk.Label({
label: "\n\n<b>Check out the source code on GitHub:</b>",
halign: Gtk.Align.START,
use_markup: true,
visible: true
});
let githubButton = new Gtk.LinkButton({
halign: Gtk.Align.START,
visible: true
});
githubButton.image = Gtk.Image.new_from_file(Me.dir.get_path() + "/.github/github.png");
githubButton.set_uri("https://github.com/sync1211/wg-indicator/");
prefsWidget.attach(githubLabel, 0, 3, 1, 1);
prefsWidget.attach(githubButton, 0, 6, 1, 1);
//Set window size:
prefsWidget.connect('realize', () => {
if (shellVersion < 40){
let window = prefsWidget.get_toplevel();
window.resize(200, 200);
} else {
let window = prefsWidget.get_root();
window.default_width = 200;
window.default_height = 200;
}
});
return prefsWidget;
}