-
Notifications
You must be signed in to change notification settings - Fork 4
/
prefs.js
107 lines (97 loc) · 3.37 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
import Gtk from 'gi://Gtk';
import Gio from 'gi://Gio';
import Adw from 'gi://Adw';
import {
ExtensionPreferences,
gettext as _,
} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
export default class MyExtensionPreferences extends ExtensionPreferences {
fillPreferencesWindow(window) {
// Attach settings to window
window._settings = this.getSettings(
'org.gnome.shell.extensions.battery_usage_wattmeter'
);
// Create a preferences page
const generalPage = new Adw.PreferencesPage({
title: _('General'),
icon_name: 'dialog-information-symbolic',
});
window.add(generalPage);
// Create a preferences group titled 'Behavior'
const behaviorGroup = new Adw.PreferencesGroup({
title: _('Behavior'),
description: _('Configure extension behavior'),
});
generalPage.add(behaviorGroup);
// Create a SpinRow for the 'interval' setting
const intervalRow = new Adw.SpinRow({
title: _('Sync Interval'),
subtitle: _('Seconds'),
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 120,
step_increment: 1,
value: 4,
}),
});
behaviorGroup.add(intervalRow);
window._settings.bind(
'interval',
intervalRow,
'value',
Gio.SettingsBindFlags.DEFAULT
);
// Create a StringList and populate it with battery options
const batteryStringList = new Gtk.StringList();
batteryStringList.splice(0, 0, ['Automatic', 'BAT0', 'BAT1', 'BAT2']);
// Create a ComboRow for the 'battery' setting
const batteryRow = new Adw.ComboRow({
title: _('Battery Selection'),
model: batteryStringList,
});
behaviorGroup.add(batteryRow);
window._settings.bind(
'battery',
batteryRow,
'selected',
Gio.SettingsBindFlags.DEFAULT
);
const hideNARow = new Adw.SwitchRow({
title: _('Hide N/A Status'),
subtitle: _(
'Hide the N/A status when battery is neither charging nor discharging'
),
});
behaviorGroup.add(hideNARow);
window._settings.bind(
'hide-na',
hideNARow,
'active',
Gio.SettingsBindFlags.DEFAULT
);
// Add new SwitchRow for 'show-minus-sign'
const showMinusSignRow = new Adw.SwitchRow({
title: _('Show Minus Sign for Discharge'),
subtitle: _('Display a minus sign when discharging'),
});
behaviorGroup.add(showMinusSignRow);
window._settings.bind(
'show-minus-sign',
showMinusSignRow,
'active',
Gio.SettingsBindFlags.DEFAULT
);
// Add new SwitchRow for 'pad-single-digit'
const padSingleDigitRow = new Adw.SwitchRow({
title: _('Pad Single-Digit Power Draw'),
subtitle: _('Pad single-digit power draw with leading zero'),
});
behaviorGroup.add(padSingleDigitRow);
window._settings.bind(
'pad-single-digit',
padSingleDigitRow,
'active',
Gio.SettingsBindFlags.DEFAULT
);
}
}