extension.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. import Clutter from 'gi://Clutter';
  2. import Gio from 'gi://Gio';
  3. import GLib from 'gi://GLib';
  4. import GObject from 'gi://GObject';
  5. import St from 'gi://St'
  6. import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
  7. import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
  8. import * as Main from 'resource:///org/gnome/shell/ui/main.js';
  9. import * as Util from 'resource:///org/gnome/shell/misc/util.js';
  10. import * as Sensors from './sensors.js';
  11. import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
  12. import * as MessageTray from 'resource:///org/gnome/shell/ui/messageTray.js';
  13. import * as Values from './values.js';
  14. import * as Config from 'resource:///org/gnome/shell/misc/config.js';
  15. import * as MenuItem from './menuItem.js';
  16. let vitalsMenu;
  17. var VitalsMenuButton = GObject.registerClass({
  18. GTypeName: 'VitalsMenuButton',
  19. }, class VitalsMenuButton extends PanelMenu.Button {
  20. _init(extensionObject) {
  21. super._init(Clutter.ActorAlign.FILL);
  22. this._extensionObject = extensionObject;
  23. this._settings = extensionObject.getSettings();
  24. this._sensorIcons = {
  25. 'temperature' : { 'icon': 'temperature-symbolic.svg' },
  26. 'voltage' : { 'icon': 'voltage-symbolic.svg' },
  27. 'fan' : { 'icon': 'fan-symbolic.svg' },
  28. 'memory' : { 'icon': 'memory-symbolic.svg' },
  29. 'processor' : { 'icon': 'cpu-symbolic.svg' },
  30. 'system' : { 'icon': 'system-symbolic.svg' },
  31. 'network' : { 'icon': 'network-symbolic.svg',
  32. 'icon-rx': 'network-download-symbolic.svg',
  33. 'icon-tx': 'network-upload-symbolic.svg' },
  34. 'storage' : { 'icon': 'storage-symbolic.svg' },
  35. 'battery' : { 'icon': 'battery-symbolic.svg' },
  36. 'gpu' : { 'icon': 'gpu-symbolic.svg' }
  37. }
  38. // list with the prefixes for the according themes, the index of each
  39. // item must match the index on the combo box
  40. this._sensorsIconPathPrefix = ['/icons/original/', '/icons/gnome/'];
  41. this._warnings = [];
  42. this._sensorMenuItems = {};
  43. this._hotLabels = {};
  44. this._hotIcons = {};
  45. this._groups = {};
  46. this._widths = {};
  47. this._numGpus = 1;
  48. this._newGpuDetected = false;
  49. this._newGpuDetectedCount = 0;
  50. this._last_query = new Date().getTime();
  51. this._sensors = new Sensors.Sensors(this._settings, this._sensorIcons);
  52. this._values = new Values.Values(this._settings, this._sensorIcons);
  53. this._menuLayout = new St.BoxLayout({
  54. vertical: false,
  55. clip_to_allocation: true,
  56. x_align: Clutter.ActorAlign.START,
  57. y_align: Clutter.ActorAlign.CENTER,
  58. reactive: true,
  59. x_expand: true
  60. });
  61. this._drawMenu();
  62. this.add_child(this._menuLayout);
  63. this._settingChangedSignals = [];
  64. this._refreshTimeoutId = null;
  65. this._addSettingChangedSignal('update-time', this._updateTimeChanged.bind(this));
  66. this._addSettingChangedSignal('position-in-panel', this._positionInPanelChanged.bind(this));
  67. this._addSettingChangedSignal('menu-centered', this._positionInPanelChanged.bind(this));
  68. this._addSettingChangedSignal('icon-style', this._iconStyleChanged.bind(this));
  69. let settings = [ 'use-higher-precision', 'alphabetize', 'hide-zeros', 'fixed-widths', 'hide-icons', 'unit', 'memory-measurement', 'include-public-ip', 'network-speed-format', 'storage-measurement', 'include-static-info', 'include-static-gpu-info' ];
  70. for (let setting of Object.values(settings))
  71. this._addSettingChangedSignal(setting, this._redrawMenu.bind(this));
  72. // add signals for show- preference based categories
  73. for (let sensor in this._sensorIcons)
  74. this._addSettingChangedSignal('show-' + sensor, this._showHideSensorsChanged.bind(this));
  75. this._initializeMenu();
  76. // start off with fresh sensors
  77. this._querySensors();
  78. // start monitoring sensors
  79. this._initializeTimer();
  80. }
  81. _initializeMenu() {
  82. // display sensor categories
  83. for (let sensor in this._sensorIcons) {
  84. // groups associated sensors under accordion menu
  85. if (sensor in this._groups) continue;
  86. //handle gpus separately.
  87. if (sensor === 'gpu') continue;
  88. this._initializeMenuGroup(sensor, sensor);
  89. }
  90. for (let i = 1; i <= this._numGpus; i++)
  91. this._initializeMenuGroup('gpu#' + i, 'gpu', (this._numGpus > 1 ? ' ' + i : ''));
  92. // add separator
  93. this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
  94. let item = new PopupMenu.PopupBaseMenuItem({
  95. reactive: false,
  96. style_class: 'vitals-menu-button-container'
  97. });
  98. let customButtonBox = new St.BoxLayout({
  99. style_class: 'vitals-button-box',
  100. vertical: false,
  101. clip_to_allocation: true,
  102. x_align: Clutter.ActorAlign.CENTER,
  103. y_align: Clutter.ActorAlign.CENTER,
  104. reactive: true,
  105. x_expand: true
  106. });
  107. // custom round refresh button
  108. let refreshButton = this._createRoundButton('view-refresh-symbolic', _('Refresh'));
  109. refreshButton.connect('clicked', (self) => {
  110. // force refresh by clearing history
  111. this._sensors.resetHistory();
  112. this._values.resetHistory(this._numGpus);
  113. // make sure timer fires at next full interval
  114. this._updateTimeChanged();
  115. // refresh sensors now
  116. this._querySensors();
  117. });
  118. customButtonBox.add_child(refreshButton);
  119. // custom round monitor button
  120. let monitorButton = this._createRoundButton('org.gnome.SystemMonitor-symbolic', _('System Monitor'));
  121. monitorButton.connect('clicked', (self) => {
  122. this.menu._getTopMenu().close();
  123. Util.spawn(this._settings.get_string('monitor-cmd').split(" "));
  124. });
  125. customButtonBox.add_child(monitorButton);
  126. // custom round preferences button
  127. let prefsButton = this._createRoundButton('preferences-system-symbolic', _('Preferences'));
  128. prefsButton.connect('clicked', (self) => {
  129. this.menu._getTopMenu().close();
  130. this._extensionObject.openPreferences();
  131. });
  132. customButtonBox.add_child(prefsButton);
  133. // now add the buttons to the top bar
  134. item.actor.add_child(customButtonBox);
  135. // add buttons
  136. this.menu.addMenuItem(item);
  137. // query sensors on menu open
  138. this._menuStateChangeId = this.menu.connect('open-state-changed', (self, isMenuOpen) => {
  139. if (isMenuOpen) {
  140. // make sure timer fires at next full interval
  141. this._updateTimeChanged();
  142. // refresh sensors now
  143. this._querySensors();
  144. }
  145. });
  146. }
  147. _initializeMenuGroup(groupName, optionName, menuSuffix = '', position = -1) {
  148. this._groups[groupName] = new PopupMenu.PopupSubMenuMenuItem(_(this._ucFirst(groupName) + menuSuffix), true);
  149. this._groups[groupName].icon.gicon = Gio.icon_new_for_string(this._sensorIconPath(groupName));
  150. // hide menu items that user has requested to not include
  151. if (!this._settings.get_boolean('show-' + optionName))
  152. this._groups[groupName].actor.hide();
  153. if (!this._groups[groupName].status) {
  154. this._groups[groupName].status = this._defaultLabel();
  155. this._groups[groupName].actor.insert_child_at_index(this._groups[groupName].status, 4);
  156. this._groups[groupName].status.text = _('No Data');
  157. }
  158. if(position == -1) this.menu.addMenuItem(this._groups[groupName]);
  159. else this.menu.addMenuItem(this._groups[groupName], position);
  160. }
  161. _createRoundButton(iconName) {
  162. let button = new St.Button({
  163. style_class: 'message-list-clear-button button vitals-button-action'
  164. });
  165. button.child = new St.Icon({
  166. icon_name: iconName
  167. });
  168. return button;
  169. }
  170. _removeMissingHotSensors(hotSensors) {
  171. for (let i = hotSensors.length - 1; i >= 0; i--) {
  172. let sensor = hotSensors[i];
  173. // make sure default icon (if any) stays visible
  174. if (sensor == '_default_icon_') continue;
  175. // removes sensors that are no longer available
  176. if (!this._sensorMenuItems[sensor]) {
  177. hotSensors.splice(i, 1);
  178. this._removeHotLabel(sensor);
  179. this._removeHotIcon(sensor);
  180. }
  181. }
  182. return hotSensors;
  183. }
  184. _saveHotSensors(hotSensors) {
  185. // removes any sensors that may not currently be available
  186. hotSensors = this._removeMissingHotSensors(hotSensors);
  187. this._settings.set_strv('hot-sensors', hotSensors.filter(
  188. function(item, pos) {
  189. return hotSensors.indexOf(item) == pos;
  190. }
  191. ));
  192. }
  193. _initializeTimer() {
  194. // used to query sensors and update display
  195. let update_time = this._settings.get_int('update-time');
  196. this._refreshTimeoutId = GLib.timeout_add_seconds(
  197. GLib.PRIORITY_DEFAULT,
  198. update_time,
  199. (self) => {
  200. // only update menu if we have hot sensors
  201. if (Object.values(this._hotLabels).length > 0)
  202. this._querySensors();
  203. // keep the timer running
  204. return GLib.SOURCE_CONTINUE;
  205. }
  206. );
  207. }
  208. _createHotItem(key, value) {
  209. let icon = this._defaultIcon(key);
  210. this._hotIcons[key] = icon;
  211. this._menuLayout.add_child(icon)
  212. // don't add a label when no sensors are in the panel
  213. if (key == '_default_icon_') return;
  214. let label = new St.Label({
  215. style_class: 'vitals-panel-label',
  216. text: (value)?value:'\u2026', // ...
  217. y_expand: true,
  218. y_align: Clutter.ActorAlign.CENTER
  219. });
  220. // attempt to prevent ellipsizes
  221. label.get_clutter_text().ellipsize = 0;
  222. // keep track of label for removal later
  223. this._hotLabels[key] = label;
  224. // prevent "called on the widget" "which is not in the stage" errors by adding before width below
  225. this._menuLayout.add_child(label);
  226. // support for fixed widths #55, save label (text) width
  227. this._widths[key] = label.width;
  228. }
  229. _showHideSensorsChanged(self, sensor) {
  230. this._sensors.resetHistory();
  231. const sensorName = sensor.substr(5);
  232. if(sensorName === 'gpu') {
  233. for(let i = 1; i <= this._numGpus; i++)
  234. this._groups[sensorName + '#' + i].visible = this._settings.get_boolean(sensor);
  235. } else
  236. this._groups[sensorName].visible = this._settings.get_boolean(sensor);
  237. }
  238. _positionInPanelChanged() {
  239. this.container.get_parent().remove_child(this.container);
  240. let position = this._positionInPanel();
  241. // allows easily addressable boxes
  242. let boxes = {
  243. left: Main.panel._leftBox,
  244. center: Main.panel._centerBox,
  245. right: Main.panel._rightBox
  246. };
  247. // update position when changed from preferences
  248. boxes[position[0]].insert_child_at_index(this.container, position[1]);
  249. }
  250. _redrawDetailsMenuIcons() {
  251. // updates the icons on the 'details' menu, the one
  252. // you have to click to appear
  253. this._sensors.resetHistory();
  254. for (const sensor in this._sensorIcons) {
  255. if (sensor == "gpu") continue;
  256. this._groups[sensor].icon.gicon = Gio.icon_new_for_string(this._sensorIconPath(sensor));
  257. }
  258. // gpu's are indexed differently, handle them here
  259. const gpuKeys = Object.keys(this._groups).filter(key => key.startsWith("gpu#"));
  260. gpuKeys.forEach((gpuKey) => {
  261. this._groups[gpuKey].icon.gicon = Gio.icon_new_for_string(this._sensorIconPath("gpu"));
  262. });
  263. }
  264. _iconStyleChanged() {
  265. this._redrawDetailsMenuIcons();
  266. this._redrawMenu();
  267. }
  268. _removeHotLabel(key) {
  269. if (key in this._hotLabels) {
  270. let label = this._hotLabels[key];
  271. delete this._hotLabels[key];
  272. // make sure set_label is not called on non existent actor
  273. label.destroy();
  274. }
  275. }
  276. _removeHotLabels() {
  277. for (let key in this._hotLabels)
  278. this._removeHotLabel(key);
  279. }
  280. _removeHotIcon(key) {
  281. if (key in this._hotIcons) {
  282. this._hotIcons[key].destroy();
  283. delete this._hotIcons[key];
  284. }
  285. }
  286. _removeHotIcons() {
  287. for (let key in this._hotIcons)
  288. this._removeHotIcon(key);
  289. }
  290. _redrawMenu() {
  291. this._removeHotIcons();
  292. this._removeHotLabels();
  293. for (let key in this._sensorMenuItems) {
  294. if (key.includes('-group')) continue;
  295. this._sensorMenuItems[key].destroy();
  296. delete this._sensorMenuItems[key];
  297. }
  298. this._drawMenu();
  299. this._sensors.resetHistory();
  300. this._values.resetHistory(this._numGpus);
  301. this._querySensors();
  302. }
  303. _drawMenu() {
  304. // grab list of selected menubar icons
  305. let hotSensors = this._settings.get_strv('hot-sensors');
  306. for (let key of Object.values(hotSensors)) {
  307. // fixes issue #225 which started when _max_ was moved to the end
  308. if (key == '__max_network-download__') key = '__network-rx_max__';
  309. if (key == '__max_network-upload__') key = '__network-tx_max__';
  310. this._createHotItem(key);
  311. }
  312. }
  313. _destroyTimer() {
  314. // invalidate and reinitialize timer
  315. if (this._refreshTimeoutId != null) {
  316. GLib.Source.remove(this._refreshTimeoutId);
  317. this._refreshTimeoutId = null;
  318. }
  319. }
  320. _updateTimeChanged() {
  321. this._destroyTimer();
  322. this._initializeTimer();
  323. }
  324. _addSettingChangedSignal(key, callback) {
  325. this._settingChangedSignals.push(this._settings.connect('changed::' + key, callback));
  326. }
  327. _updateDisplay(label, value, type, key) {
  328. // update sensor value in menubar
  329. if (this._hotLabels[key]) {
  330. this._hotLabels[key].set_text(value);
  331. // support for fixed widths #55
  332. if (this._settings.get_boolean('fixed-widths')) {
  333. // grab text box width and see if new text is wider than old text
  334. let width2 = this._hotLabels[key].get_clutter_text().width;
  335. if (width2 > this._widths[key]) {
  336. this._hotLabels[key].set_width(width2);
  337. this._widths[key] = width2;
  338. }
  339. }
  340. }
  341. // have we added this sensor before?
  342. let item = this._sensorMenuItems[key];
  343. if (item) {
  344. // update sensor value in the group
  345. item.value = value;
  346. } else if (type.includes('-group')) {
  347. // update text next to group header
  348. let group = type.split('-')[0];
  349. if (this._groups[group]) {
  350. this._groups[group].status.text = value;
  351. this._sensorMenuItems[type] = this._groups[group];
  352. }
  353. } else {
  354. // add item to group for the first time
  355. let sensor = { 'label': label, 'value': value, 'type': type }
  356. this._appendMenuItem(sensor, key);
  357. }
  358. }
  359. _appendMenuItem(sensor, key) {
  360. let split = sensor.type.split('-');
  361. let type = split[0];
  362. let icon = (split.length == 2)?'icon-' + split[1]:'icon';
  363. let gicon = Gio.icon_new_for_string(this._sensorIconPath(type, icon));
  364. let item = new MenuItem.MenuItem(gicon, key, sensor.label, sensor.value, this._hotLabels[key]);
  365. item.connect('toggle', (self) => {
  366. let hotSensors = this._settings.get_strv('hot-sensors');
  367. if (self.checked) {
  368. // add selected sensor to panel
  369. hotSensors.push(self.key);
  370. this._createHotItem(self.key, self.value);
  371. } else {
  372. // remove selected sensor from panel
  373. hotSensors.splice(hotSensors.indexOf(self.key), 1);
  374. this._removeHotLabel(self.key);
  375. this._removeHotIcon(self.key);
  376. }
  377. if (hotSensors.length <= 0) {
  378. // add generic icon to panel when no sensors are selected
  379. hotSensors.push('_default_icon_');
  380. this._createHotItem('_default_icon_');
  381. } else {
  382. let defIconPos = hotSensors.indexOf('_default_icon_');
  383. if (defIconPos >= 0) {
  384. // remove generic icon from panel when sensors are selected
  385. hotSensors.splice(defIconPos, 1);
  386. this._removeHotIcon('_default_icon_');
  387. }
  388. }
  389. // this code is called asynchronously - make sure to save it for next round
  390. this._saveHotSensors(hotSensors);
  391. });
  392. this._sensorMenuItems[key] = item;
  393. let i = Object.keys(this._sensorMenuItems[key]).length;
  394. // alphabetize the sensors for these categories
  395. if (this._settings.get_boolean('alphabetize')) {
  396. let menuItems = this._groups[type].menu._getMenuItems();
  397. for (i = 0; i < menuItems.length; i++)
  398. // use natural sort order for system load, etc
  399. if (menuItems[i].label.localeCompare(item.label, undefined, { numeric: true, sensitivity: 'base' }) > 0)
  400. break;
  401. }
  402. this._groups[type].menu.addMenuItem(item, i);
  403. }
  404. _defaultLabel() {
  405. return new St.Label({
  406. y_expand: true,
  407. y_align: Clutter.ActorAlign.CENTER
  408. });
  409. }
  410. _defaultIcon(key) {
  411. let split = key.replaceAll('_', ' ').trim().split(' ')[0].split('-');
  412. let type = split[0];
  413. let icon = new St.Icon({
  414. style_class: 'system-status-icon vitals-panel-icon-' + type,
  415. reactive: true
  416. });
  417. // second condition prevents crash due to issue #225, which started when _max_ was moved to the end
  418. // don't use the default system icon if the type is a gpu; use the universal gpu icon instead
  419. if (type == 'default' || (!(type in this._sensorIcons) && !type.startsWith('gpu'))) {
  420. icon.gicon = Gio.icon_new_for_string(this._sensorIconPath('system'));
  421. } else if (!this._settings.get_boolean('hide-icons')) { // support for hide icons #80
  422. let iconObj = (split.length == 2)?'icon-' + split[1]:'icon';
  423. icon.gicon = Gio.icon_new_for_string(this._sensorIconPath(type, iconObj));
  424. }
  425. return icon;
  426. }
  427. _sensorIconPath(sensor, icon = 'icon') {
  428. // If the sensor is a numbered gpu, use the gpu icon. Otherwise use whatever icon associated with the sensor name.
  429. let sensorKey = sensor;
  430. if(sensor.startsWith('gpu')) sensorKey = 'gpu';
  431. const iconPathPrefixIndex = this._settings.get_int('icon-style');
  432. return this._extensionObject.path + this._sensorsIconPathPrefix[iconPathPrefixIndex] + this._sensorIcons[sensorKey][icon];
  433. }
  434. _ucFirst(string) {
  435. if(string.startsWith('gpu')) return 'Graphics';
  436. return string.charAt(0).toUpperCase() + string.slice(1);
  437. }
  438. _positionInPanel() {
  439. let alignment = '';
  440. let gravity = 0;
  441. let arrow_pos = 0;
  442. switch (this._settings.get_int('position-in-panel')) {
  443. case 0: // left
  444. alignment = 'left';
  445. gravity = -1;
  446. arrow_pos = 1;
  447. break;
  448. case 1: // center
  449. alignment = 'center';
  450. gravity = -1;
  451. arrow_pos = 0.5;
  452. break;
  453. case 2: // right
  454. alignment = 'right';
  455. gravity = 0;
  456. arrow_pos = 0;
  457. break;
  458. case 3: // far left
  459. alignment = 'left';
  460. gravity = 0;
  461. arrow_pos = 1;
  462. break;
  463. case 4: // far right
  464. alignment = 'right';
  465. gravity = -1;
  466. arrow_pos = 0;
  467. break;
  468. }
  469. let centered = this._settings.get_boolean('menu-centered')
  470. if (centered) arrow_pos = 0.5;
  471. // set arrow position when initializing and moving vitals
  472. this.menu._arrowAlignment = arrow_pos;
  473. return [alignment, gravity];
  474. }
  475. _querySensors() {
  476. // figure out last run time
  477. let now = new Date().getTime();
  478. let dwell = (now - this._last_query) / 1000;
  479. this._last_query = now;
  480. this._sensors.query((label, value, type, format) => {
  481. const typeKey = type.replace('-group', '');
  482. let key = '_' + typeKey + '_' + label.replace(' ', '_').toLowerCase() + '_';
  483. // if a sensor is disabled, gray it out
  484. if (key in this._sensorMenuItems) {
  485. this._sensorMenuItems[key].setSensitive((value!='disabled'));
  486. // don't continue below, last known value is shown
  487. if (value == 'disabled') return;
  488. }
  489. // add/initialize any gpu groups that we haven't added yet
  490. if(typeKey.startsWith('gpu') && typeKey !== 'gpu#1') {
  491. const split = typeKey.split('#');
  492. if(split.length == 2 && this._numGpus < parseInt(split[1])) {
  493. // occasionally two lines from nvidia-smi will be read at once
  494. // so we only actually update the number of gpus if we have recieved multiple lines at least 3 times in a row
  495. // i.e. we make sure that mutiple queries have detected a new gpu back-to-back
  496. if(this._newGpuDetectedCount < 2) {
  497. this._newGpuDetected = true;
  498. return;
  499. }
  500. this._numGpus = parseInt(split[1]);
  501. this._newGpuDetectedCount = 0;
  502. this._newGpuDetected = false;
  503. // change label for gpu 1 from "Graphics" to "Graphics 1" since we have multiple gpus now
  504. this._groups['gpu#1'].label.text = this._ucFirst('gpu#1') + ' 1';
  505. for(let i = 2; i <= this._numGpus; i++)
  506. if(!('gpu#' + i in this._groups))
  507. this._initializeMenuGroup('gpu#' + i, 'gpu', ' ' + i, Object.keys(this._groups).length);
  508. }
  509. }
  510. let items = this._values.returnIfDifferent(dwell, label, value, type, format, key);
  511. for (let item of Object.values(items))
  512. this._updateDisplay(_(item[0]), item[1], item[2], item[3]);
  513. }, dwell);
  514. //if a new gpu has been detected during the last query, then increment the amount of times we've detected a new gpu
  515. if(this._newGpuDetected) this._newGpuDetectedCount++;
  516. else this._newGpuDetectedCount = 0;
  517. this._newGpuDetected = false;
  518. if (this._warnings.length > 0) {
  519. this._notify('Vitals', this._warnings.join("\n"), 'folder-symbolic');
  520. this._warnings = [];
  521. }
  522. }
  523. _notify(msg, details, icon) {
  524. let source = new MessageTray.Source('MyApp Information', icon);
  525. Main.messageTray.add(source);
  526. let notification = new MessageTray.Notification(source, msg, details);
  527. notification.setTransient(true);
  528. source.notify(notification);
  529. }
  530. destroy() {
  531. this._destroyTimer();
  532. this._sensors.destroy();
  533. for (let signal of Object.values(this._settingChangedSignals))
  534. this._settings.disconnect(signal);
  535. super.destroy();
  536. }
  537. });
  538. export default class VitalsExtension extends Extension {
  539. enable() {
  540. vitalsMenu = new VitalsMenuButton(this);
  541. let position = vitalsMenu._positionInPanel();
  542. Main.panel.addToStatusArea('vitalsMenu', vitalsMenu, position[1], position[0]);
  543. }
  544. disable() {
  545. vitalsMenu.destroy();
  546. vitalsMenu = null;
  547. }
  548. }