-
Notifications
You must be signed in to change notification settings - Fork 16
/
prefs.js
249 lines (208 loc) · 7.01 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
'use strict';
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Config = imports.misc.config;
const [major] = Config.PACKAGE_VERSION.split('.');
const shellVersion = Number.parseInt(major);
function init() {
}
function buildPrefsWidget() {
let gschema = Gio.SettingsSchemaSource.new_from_directory(
Me.dir.get_child('schemas').get_path(),
Gio.SettingsSchemaSource.get_default(),
false
);
let settings = new Gio.Settings({
settings_schema: gschema.lookup('org.gnome.shell.extensions.spotifylabel', true)
});
let prefsWidget;
if (shellVersion < 40) {
prefsWidget = new Gtk.Grid({
margin: 18,
column_spacing: 12,
row_spacing: 12,
visible: true,
column_homogeneous: true,
});
} else {
prefsWidget = new Gtk.Grid({
margin_top: 10,
margin_bottom: 10,
margin_start: 10,
margin_end: 10,
column_spacing: 12,
row_spacing: 12,
visible: true,
column_homogeneous: true,
});
}
let index = 0;
let title = new Gtk.Label({
label: '<b>' + Me.metadata.name + ' Extension Preferences</b>',
halign: Gtk.Align.START,
use_markup: true,
visible: true
});
prefsWidget.attach(title, 0, index, 1, 1);
/* left-padding */
let leftPaddingLabel = new Gtk.Label({
label: 'Left padding:',
halign: Gtk.Align.START,
visible: true
});
let leftPaddingEntry = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 100,
step_increment: 1
}),
visible: true
});
index++;
prefsWidget.attach(leftPaddingLabel, 0, index, 1, 1);
prefsWidget.attach(leftPaddingEntry, 1, index, 1, 1);
/* right-padding */
let rightPaddingLabel = new Gtk.Label({
label: 'Right padding:',
halign: Gtk.Align.START,
visible: true
});
let rightPaddingEntry = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 100,
step_increment: 1
}),
visible: true
});
index++;
prefsWidget.attach(rightPaddingLabel, 0, index, 1, 1);
prefsWidget.attach(rightPaddingEntry, 1, index, 1, 1);
/* max-string-length */
let maxStringLengthLabel = new Gtk.Label({
label: 'Max string length (Each artist and title):',
halign: Gtk.Align.START,
visible: true
});
let maxStringLengthEntry = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 100,
step_increment: 1
}),
visible: true
});
index++;
prefsWidget.attach(maxStringLengthLabel, 0, index, 1, 1);
prefsWidget.attach(maxStringLengthEntry, 1, index, 1, 1);
/* refresh-rate */
let refreshRateLabel = new Gtk.Label({
label: 'Refresh rate (seconds):',
halign: Gtk.Align.START,
visible: true
});
let refreshRateEntry = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 60,
step_increment: 1
}),
visible: true
});
index++;
prefsWidget.attach(refreshRateLabel, 0, index, 1, 1);
prefsWidget.attach(refreshRateEntry, 1, index, 1, 1);
/* friendly-greeting */
let friendlyGreetingLabel = new Gtk.Label({
label: 'Friendly greeting:',
halign: Gtk.Align.START,
visible: true
});
let friendlyGreetingSwitch = new Gtk.Switch({
valign: Gtk.Align.END,
halign: Gtk.Align.END,
visible: true
});
index++;
prefsWidget.attach(friendlyGreetingLabel, 0, index, 1, 1);
prefsWidget.attach(friendlyGreetingSwitch, 1, index, 1, 1);
/* artist-first */
let artistFirstLabel = new Gtk.Label({
label: 'Artist first:',
halign: Gtk.Align.START,
visible: true
});
let artistFirstSwitch = new Gtk.Switch({
valign: Gtk.Align.END,
halign: Gtk.Align.END,
visible: true
});
index++;
prefsWidget.attach(artistFirstLabel, 0, index, 1, 1);
prefsWidget.attach(artistFirstSwitch, 1, index, 1, 1);
/* extension-place */
let extensionPlaceLabel = new Gtk.Label({
label: 'Extension place:',
halign: Gtk.Align.START,
visible: true
});
let options = ['left', 'center', 'right'];
let extensionPlaceComboBox = new Gtk.ComboBoxText({
halign: Gtk.Align.END,
visible: true
});
for (let i = 0; i < options.length; i++) {
extensionPlaceComboBox.append(options[i], options[i]);
}
extensionPlaceComboBox.set_active(options.indexOf(settings.get_string('extension-place')));
index++;
prefsWidget.attach(extensionPlaceLabel, 0, index, 1, 1);
prefsWidget.attach(extensionPlaceComboBox, 1, index, 1, 1);
/* extension-index */
let extensionIndexLabel = new Gtk.Label({
label: 'Extension index:',
halign: Gtk.Align.START,
visible: true
});
let extensionIndexEntry = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 20,
step_increment: 1
}),
visible: true
});
index++;
prefsWidget.attach(extensionIndexLabel, 0, index, 1, 1);
prefsWidget.attach(extensionIndexEntry, 1, index, 1, 1);
/* toggle-window */
let toggleWindowLabel = new Gtk.Label({
label: 'Click to toggle Spotify window/work window:',
halign: Gtk.Align.START,
visible: true
});
let toggleWindowSwitch = new Gtk.Switch({
valign: Gtk.Align.END,
halign: Gtk.Align.END,
visible: true
});
index++;
prefsWidget.attach(toggleWindowLabel, 0, index, 1, 1);
prefsWidget.attach(toggleWindowSwitch, 1, index, 1, 1);
//settings.bind('command', commandEntry, 'text', Gio.SettingsBindFlags.DEFAULT);
settings.bind('left-padding', leftPaddingEntry, 'value', Gio.SettingsBindFlags.DEFAULT);
settings.bind('right-padding', rightPaddingEntry, 'value', Gio.SettingsBindFlags.DEFAULT);
settings.bind('max-string-length', maxStringLengthEntry, 'value', Gio.SettingsBindFlags.DEFAULT);
settings.bind('refresh-rate', refreshRateEntry, 'value', Gio.SettingsBindFlags.DEFAULT);
settings.bind('friendly-greeting', friendlyGreetingSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('artist-first', artistFirstSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('toggle-window', toggleWindowSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
extensionPlaceComboBox.connect('changed', Lang.bind(this, function(widget) {
settings.set_string('extension-place', options[widget.get_active()]);
}));
settings.bind('extension-index', extensionIndexEntry, 'value', Gio.SettingsBindFlags.DEFAULT);
return prefsWidget;
}