-
Notifications
You must be signed in to change notification settings - Fork 0
/
thinkpad_thermal_status_icon.js
121 lines (100 loc) · 2.96 KB
/
thinkpad_thermal_status_icon.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
const St = imports.gi.St;
const Gio = imports.gi.Gio;
const Shell = imports.gi.Shell;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const Main = imports.ui.main;
const Gtk = imports.gi.Gtk;
const Clutter = imports.gi.Clutter;
const GObject = imports.gi.GObject;
const Gettext = imports.gettext;
const _ = Gettext.gettext;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const { LayoutMenuItem } = Me.imports.layout_menu_item.exports;
const ThinkPadThermalStatusIcon = GObject.registerClass(
class _ThinkPadThermalStatusIcon extends PanelMenu.Button {
_init() {
super._init(0.0);
this._box = new St.BoxLayout();
this._cpu_icon = this._get_icon('cpu');
this._fan_icon = this._get_icon('fan');
this._cpu_value = new St.Label({
text: "0",
style_class: "tpt-status-cpu"
});
this._fan_value = new St.Label({
text: "0",
style_class: "tpt-status-fan"
});
this._cpu_unit = new St.Label({
text: this._get_unit("cpu"),
style_class: "tpt-unit-cpu"
});
this._fan_unit = new St.Label({
text: this._get_unit("fan"),
style_class: "tpt-unit-fan"
});
this._box.add_actor(this._cpu_icon);
this._box.add_actor(this._cpu_value);
this._box.add_actor(this._cpu_unit);
this._box.add_actor(this._fan_icon);
this._box.add_actor(this._fan_value);
this._box.add_actor(this._fan_unit);
this.add_actor(this._box);
this._layouts = new Array();
}
create_menu(name, sensors, values, units) {
this._menu = new LayoutMenuItem(name);
this.menu.addMenuItem(this._menu);
for (let i = 0; i < sensors.length; ++i) {
let layout = new LayoutMenuItem(sensors[i], values[i], units[i]);
this._layouts.push(layout);
this.menu.addMenuItem(layout);
}
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
}
update_values(values) {
for (let i = 0; i < values.length; ++i) {
this._layouts[i].update_values(values[i]);
}
}
_get_icon(name) {
let iconname = "";
switch (name) {
case "cpu":
iconname = "cpu-symbolic";
break;
case "fan":
iconname = "fan-symbolic";
break;
default:
iconname = "temperature-symbolic";
}
const gicon = Gio.icon_new_for_string(Me.path + `/icons/${iconname}.svg`);
return new St.Icon({
gicon,
icon_size: 16
});
}
_get_unit(name) {
let unit = "";
switch (name) {
case "cpu":
unit = " \u00b0C";
break;
case "fan":
unit = " RPM";
break;
default:
unit = " \u00b0C";
}
return unit;
}
_set_values(cpu, fan) {
this._cpu_value.set_text((cpu).toString());
this._fan_value.set_text(fan);
}
});
var exports = {
ThinkPadThermalStatusIcon
}