-
Notifications
You must be signed in to change notification settings - Fork 8
/
prefs.js
151 lines (120 loc) · 3.78 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
'use strict';
const { Gio, Gtk } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
function init() {
}
function fillPreferencesWindow(window) {
// Gnome 42+: GTK5 & libadwaita
const Adw = imports.gi.Adw;
const settings = ExtensionUtils.getSettings(SETTINGS_ID);
const page = new Adw.PreferencesPage();
const group = new Adw.PreferencesGroup();
page.add(group);
// history depth
const avg_row = new Adw.ActionRow({ title: LBL_AVG });
group.add(avg_row);
const avg_spin = makeAvgOfSpin(settings);
avg_row.add_suffix(avg_spin);
avg_row.activatable_widget = avg_spin;
// measure period
const period_row = new Adw.ActionRow({ title: LBL_PERIOD });
group.add(period_row);
const period_spin = makePeriodSpin(settings);
period_row.add_suffix(period_spin);
period_row.activatable_widget = period_spin;
// show lap mode for ThinkPads from T490 era (gen 8 intel cpu) onwwards
const lap_mode_row = new Adw.ActionRow({ title: LBL_LAP_MODE });
group.add(lap_mode_row);
const lap_mode_switch = makeLapModeSwitch(settings);
lap_mode_row.add_suffix(lap_mode_switch);
lap_mode_row.activatable_widget = lap_mode_switch;
// done
window.add(page);
}
function buildPrefsWidget() {
// Gnome 41-: GTK4 bare
const settings = ExtensionUtils.getSettings(SETTINGS_ID);
// history
const avg_lbl = new Gtk.Label({label: LBL_AVG});
const avg_spin = makeAvgOfSpin(settings);
const avg_box = new Gtk.Box();
avg_box.set_spacing(10);
avg_box.set_orientation(Gtk.Orientation.HORIZONTAL);
avg_box.prepend(avg_lbl);
avg_box.append(avg_spin);
// period
const period_lbl = new Gtk.Label({label: LBL_PERIOD});
const period_spin = makePeriodSpin(settings);
const period_box = new Gtk.Box();
period_box.set_spacing(10);
period_box.set_orientation(Gtk.Orientation.HORIZONTAL);
period_box.prepend(period_lbl);
period_box.append(period_spin);
// main
const main_box = new Gtk.Box();
main_box.set_spacing(25);
main_box.set_orientation(Gtk.Orientation.VERTICAL);
main_box.append(avg_box);
main_box.append(period_box);
// done
return main_box;
}
/** Common
*/
const SETTINGS_ID = 'org.gnome.shell.extensions.tp_wattmeter';
const LBL_AVG = 'Show average of this many measurements';
const LBL_PERIOD = 'Period between measurements in seconds';
const LBL_LAP_MODE = 'Show status of lap mode thermal throttling';
function makeAvgOfSpin(settings) {
const avg_spin = new Gtk.SpinButton({
climb_rate: 1,
digits: 0,
adjustment: new Gtk.Adjustment({
value: settings.get_int('avg-of'),
lower: 1,
upper: 25,
step_increment: 1,
}),
});
settings.bind(
'avg-of',
avg_spin,
'value',
Gio.SettingsBindFlags.DEFAULT
);
return avg_spin;
}
function makeLapModeSwitch(settings) {
const lap_mode_switch = new Gtk.Switch({
active: settings.get_boolean('lap-mode'),
halign: Gtk.Align.END,
valign: Gtk.Align.CENTER,
});
settings.bind(
'lap-mode',
lap_mode_switch,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return lap_mode_switch;
}
function makePeriodSpin(settings) {
const period_spin = new Gtk.SpinButton({
climb_rate: 1,
digits: 1,
adjustment: new Gtk.Adjustment({
value: settings.get_double('period-sec'),
lower: 0.1,
upper: 10.0,
step_increment: 0.5,
}),
});
settings.bind(
'period-sec',
period_spin,
'value',
Gio.SettingsBindFlags.DEFAULT
);
return period_spin;
}