forked from prateekmedia/netspeedsimplified
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.js
357 lines (301 loc) · 13.7 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
const Gtk = imports.gi.Gtk,
Gdk = imports.gi.Gdk
const Config = imports.misc.config
const ShellVersion = parseFloat(Config.PACKAGE_VERSION)
const Me = imports.misc.extensionUtils.getCurrentExtension(),
Convenience = Me.imports.convenience,
schema = "org.gnome.shell.extensions.netspeedsimplified"
function init() {}
function buildPrefsWidget() {
let prefs = new Prefs(schema)
return prefs.buildPrefsWidget()
}
function Prefs(schema) {
this.init(schema)
}
Prefs.prototype = {
settings: null,
init: function(schema) {
let settings = new Convenience.getSettings(schema)
this.settings = settings
},
buildPrefsWidget: function() {
let thset = this.settings
let isGnome40 = ShellVersion >= 40
function addIt(element, child) {
if (isGnome40) element.append(child)
else element.add(child)
}
function newGtkBox() {
return new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
margin_top: 10,
margin_bottom: 10
})
}
function vBoxSpinBtn(getDouble, whichHbox, getLbl = "", getTooTip = "", lwer, uper, stpInc = 1, digs = 0, nume = true, pgeInc = 1, pgeSiz = 0, clmrate = 1) {
let boolComp = (thset.get_double(getDouble) === thset.get_default_value(getDouble).unpack())
getLbl = boolComp ? getLbl :
`<i>${getLbl}</i>`
let whichLbl = new Gtk.Label({
label: getLbl,
use_markup: true,
xalign: 0,
tooltip_text: getTooTip
})
let whichSpinBtn = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: lwer,
upper: uper,
step_increment: stpInc,
page_increment: pgeInc,
page_size: pgeSiz
}),
climb_rate: clmrate,
digits: digs,
numeric: nume,
})
whichSpinBtn.set_value(thset.get_double(getDouble))
whichSpinBtn.connect('value-changed', () => {
this.rTValue = parseFloat(whichSpinBtn.get_value().toFixed(1))
if (thset.get_double(getDouble) !== this.rTValue) {
thset.set_double(getDouble, this.rTValue)
thset.set_boolean('restartextension', true)
}
})
whichLbl.set_hexpand(true)
addIt(whichHbox, whichLbl)
addIt(whichHbox, whichSpinBtn)
addIt(vbox, whichHbox)
}
function vBoxAddSeleCt(getInt, whichHbox, getLbl, aRray = [], getTooTip = "") {
let boolComp = (thset.get_int(getInt) == thset.get_default_value(getInt).unpack())
getLbl = boolComp ? getLbl :
`<i>${getLbl}</i>`
let tootext = boolComp ? "" : "The Value is Changed"
let whichLbl = new Gtk.Label({
label: getLbl,
use_markup: true,
xalign: 0,
tooltip_text: getTooTip
})
let whichVlue = new Gtk.ComboBoxText({
halign: Gtk.Align.END,
tooltip_text: tootext
})
for (i in aRray) {
whichVlue.append_text(aRray[i])
}
whichVlue.set_active(Math.round(thset.get_int(getInt)))
whichVlue.connect('changed', (widget) => {
let valueMode = widget.get_active()
thset.set_int(getInt, valueMode)
thset.set_boolean('restartextension', true)
})
whichLbl.set_hexpand(true)
addIt(whichHbox, whichLbl)
addIt(whichHbox, whichVlue)
addIt(vbox, whichHbox)
}
function vBoxAddTgglBtn(whichHbox, getLbl, getBool, getTooTip = "", func) {
let boolComp = true
if (func == undefined) {
boolComp = (thset.get_boolean(getBool) == thset.get_default_value(getBool).unpack())
getLbl = boolComp ? getLbl :
`<i>${getLbl}</i>`
}
let tootext = boolComp ? "" : "The Value is Changed"
let whichLbl = new Gtk.Label({
label: getLbl,
use_markup: true,
xalign: 0,
tooltip_text: getTooTip
})
let whichVlue = new Gtk.Switch({
active: getBool ? thset.get_boolean(getBool) : false,
tooltip_text: tootext
})
whichVlue.connect('notify::active', (widget) => {
if (func != undefined) func(widget.active)
else {
thset.set_boolean(getBool, widget.active)
thset.set_boolean('restartextension', true)
}
})
whichLbl.set_hexpand(true)
addIt(whichHbox, whichLbl)
addIt(whichHbox, whichVlue)
addIt(vbox, whichHbox)
}
function vBoxAddColorButton(whichHbox, getLbl, getColor, getToolTip = "") {
//Deterime whether the option value is changed from default value
let boolComp = (thset.get_string(getColor) == thset.get_default_value(getColor).unpack())
getLbl = boolComp ? getLbl : `<i>${getLbl}</i>`
let tootext = boolComp ? "" : "The Value is Changed"
//Create the option name
let whichLbl = new Gtk.Label({
label: getLbl,
use_markup: true,
xalign: 0,
tooltip_text: getToolTip
})
//Create RGBA
let rgba = new Gdk.RGBA()
rgba.parse(thset.get_string(getColor))
//Create ColorButton
let colorButton = new Gtk.ColorButton({
tooltip_text: tootext
})
colorButton.set_rgba(rgba)
colorButton.connect('color-set', (widget) => { //On the event of modification
rgba = widget.get_rgba()
thset.set_string(getColor, rgba.to_string())
thset.set_boolean('restartextension', true)
})
whichLbl.set_hexpand(true)
addIt(whichHbox, whichLbl)
addIt(whichHbox, colorButton)
addIt(vbox, whichHbox)
}
function vBoxAddEntry(whichHbox, getLbl, getString, getTooTip = "", func) {
let boolComp = (thset.get_string(getString) == thset.get_default_value(getString).unpack())
getLbl = boolComp ? getLbl :
`<i>${getLbl}</i>`
let tootext = boolComp ? "" : "The Value is Changed"
let whichLbl = new Gtk.Label({
label: getLbl,
use_markup: true,
xalign: 0,
tooltip_text: getTooTip
})
let whichVlue = new Gtk.Entry({
text: thset.get_string(getString),
tooltip_text: tootext,
placeholder_text: "Press Enter to apply"
})
whichVlue.connect('activate', (widget) => {
thset.set_string(getString, widget.get_text())
if (func != undefined) {
func(widget.active)
} else {
thset.set_boolean('restartextension', true)
}
})
whichLbl.set_hexpand(true)
addIt(whichHbox, whichLbl)
addIt(whichHbox, whichVlue)
addIt(vbox, whichHbox)
}
let frame = new Gtk.ScrolledWindow()
let label = new Gtk.Label({
label: "<b>General Settings</b>",
use_markup: true,
xalign: 0,
margin_top: 15
})
let vbox = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
margin_start: 25,
margin_end: 25
})
let resetBtn = new Gtk.Button({
label: "Restore Defaults",
margin_bottom: 15
})
resetBtn.connect("clicked", () => {
let strArray = ["customfont", "uscolor", "dscolor", "tscolor", "tdcolor"]
let intArray = ["wpos", "wposext", "mode", "fontmode", "chooseiconset", "textalign"]
let doubleArray = ["refreshtime", "minwidth"]
let boolArray = ["isvertical", "togglebool", "reverseindicators", "lockmouseactions", "hideindicator", "shortenunits", "iconstoright"]
for (i in strArray) {
thset.set_string(strArray[i], thset.get_default_value(strArray[i]).unpack())
}
for (j in intArray) {
thset.set_int(intArray[j], thset.get_default_value(intArray[j]).unpack())
}
for (k in doubleArray) {
thset.set_double(doubleArray[k], thset.get_default_value(doubleArray[k]).unpack())
}
for (l in boolArray) {
thset.set_boolean(boolArray[l], thset.get_default_value(boolArray[l]).unpack())
}
thset.set_boolean('restartextension', true)
frame.destroy()
})
addIt(vbox, label)
//For Position
let hboxWPos = newGtkBox()
vBoxAddSeleCt("wpos", hboxWPos, "Position on the Panel", ["Right", "Left", "Center"], "Choose where to Place the extension on the Panel")
//For Position Extras
let hboxWPosExt = newGtkBox()
vBoxAddSeleCt("wposext", hboxWPosExt, "Position(Advanced)", ["Prefer Right Side", "Prefer Left Side"], "Choose further where to Place the extension")
//Refresh time
let hboxRTime = newGtkBox()
vBoxSpinBtn("refreshtime", hboxRTime, "Refresh Time", "Change Refresh time value from anywhere b/w 1 to 10", 1.0, 10.0, .1, 1)
//For Modes
let hboxMode = newGtkBox()
vBoxAddSeleCt("mode", hboxMode, "Mode", ["Mode 1", "Mode 2", "Mode 3", "Mode 4", "Mode 5"], "Choose which mode to load")
//For FontModes
let hboxFontMode = newGtkBox()
vBoxAddSeleCt("fontmode", hboxFontMode, "Font Mode", ["Default", "Smallest", "Smaller", "Small", "Large"], "Choose which font to display")
//For Vertical Alignment
let hboxVertical = newGtkBox()
vBoxAddTgglBtn(hboxVertical, "Vertical Align", "isvertical", "Changing it will toggle Vertical Alignment")
//For Default sigma View
let hboxToggleBool = newGtkBox()
vBoxAddTgglBtn(hboxToggleBool, "Show Total Download speed", "togglebool", "Enabling it will show sigma by default")
//For Toggling Old Icons
let hboxIconset = newGtkBox()
vBoxAddSeleCt("chooseiconset", hboxIconset, "Choose Icons Set", [" ⬇, ⬆", " 🡳, 🡱", " ↓, ↑"], "Choose which icon set to display")
//Text align for net speed
let hboxText = newGtkBox()
vBoxAddSeleCt("textalign", hboxText, "Text Align", ["Left", "Right", "Center"], "Align Text of net speed")
//Toggle icon to right
let hboxIconsRight = newGtkBox()
vBoxAddTgglBtn(hboxIconsRight, "Move icons to the right", "iconstoright", "Move icons to the right")
//For Limiting upper limit of speed
let hboxLimitUnit = newGtkBox()
vBoxAddSeleCt("limitunit", hboxLimitUnit, "Limit Unit", ["(None)", 'K', 'M', 'G', 'T', 'P', 'E', 'Z'], "Choose unit limitation set to display")
//For Hide When Disconnected
let hboxHideInd = newGtkBox()
vBoxAddTgglBtn(hboxHideInd, "Hide When Disconnected", "hideindicator", "Enabling it will Hide Indicator when disconnected")
//For Shorten Units
let hboxShUni = newGtkBox()
vBoxAddTgglBtn(hboxShUni, "Shorten Units", "shortenunits", "Enabling it will result in shorten units like K instead of KB")
//For Reversing the download and upload indicators
let hboxRevInd = newGtkBox()
vBoxAddTgglBtn(hboxRevInd, "Show Upload First", "reverseindicators", "Enabling it will reverse the upload and download speed indicators")
//For Lock Mouse Actions
let hboxLckMuseAct = newGtkBox()
vBoxAddTgglBtn(hboxLckMuseAct, "Lock Mouse Actions", "lockmouseactions", "Enabling it will Lock Mouse Actions")
//Minimum Width
let hboxMinWidth = newGtkBox()
vBoxSpinBtn("minwidth", hboxMinWidth, "Minimum Width", "Change Minimum Width value from anywhere b/w 3em to 10em", 3.0, 10.0, .5, 1)
//For Custom Font name
let hboxCustFont = newGtkBox()
vBoxAddEntry(hboxCustFont, "Custom Font Name", "customfont", "Enter the font name you want, you can also write style here for all elements except indicators")
//For Custom Font name
let hboxSysColr = newGtkBox()
vBoxAddTgglBtn(hboxSysColr, "Use System Color Scheme", "systemcolr", "Enabling it will allow changing font color dynamically based on panel color")
//Upload Speed Color
let usColorButton = newGtkBox()
vBoxAddColorButton(usColorButton, "Upload Speed Color", "uscolor", "Select the upload speed color")
//Download Speed Color
let dsColorButton = newGtkBox()
vBoxAddColorButton(dsColorButton, "Download Speed Color", "dscolor", "Select the download speed color")
//Total Speed Color
let tsColorButton = newGtkBox()
vBoxAddColorButton(tsColorButton, "Total Speed Color", "tscolor", "Select the total speed color")
//Total Download Color
let tdColorButton = newGtkBox()
vBoxAddColorButton(tdColorButton, "Total Download Color", "tdcolor", "Select the total download color")
addIt(vbox, resetBtn)
if (isGnome40) frame.child = vbox
else {
frame.add(vbox)
frame.show_all()
frame.connect('destroy', Gtk.main_quit)
}
return frame
}
}