From 7e6b378a53f2b4eff1f479f0875185fe1eb73e96 Mon Sep 17 00:00:00 2001 From: Giuseppe Silvestro Date: Wed, 3 Jan 2024 17:07:20 +0100 Subject: [PATCH] New version (#81) * Port to GNOME 45 init, thanks @Sierra410 * Fix custom-program fix #80 #73 #70 --- README.md | 173 +- Resource_Monitor@Ory0n/extension.js | 5336 ++++++++++++++------------ Resource_Monitor@Ory0n/metadata.json | 22 +- Resource_Monitor@Ory0n/prefs.css | 4 +- Resource_Monitor@Ory0n/prefs.js | 2221 ++++++----- 5 files changed, 4329 insertions(+), 3427 deletions(-) diff --git a/README.md b/README.md index 1d773d2..e1f8005 100644 --- a/README.md +++ b/README.md @@ -1,119 +1,64 @@ [ego]: https://extensions.gnome.org/extension/1634/resource-monitor/ -# Resource_Monitor [Get it on GNOME Extensions][ego] -Resource_Monitor is a GNOME Shell extension that Monitor the use of system resources like cpu, ram, disk, network and display them in GNOME shell top bar. - -# Screenshots -![](/images/main.png) - -# GNOME Shell versions supported -**40, 41, 42, 43, 44** -- For older GNOME versions see the [gnome-3.28-3.38](../../tree/gnome-3.28-3.38) branch. - -# How-To Install -## Download -You can get this extension: - -- From [GNOME Extensions](https://extensions.gnome.org/extension/1634/resource-monitor/). -- Downloading the latest [Release](../../releases/latest) released on GitHub. -- Cloning the [master](../../tree/master) repository. -## Install -### Using the latest release -1. Unzip the file `Resource_Monitor@Ory0n.zip`. -2. Move `Resource_Monitor@Ory0n` folder to `~/.local/share/gnome-shell/extensions/Resource_Monitor@Ory0n`. -3. Activate the extensions with Gnome Extensions. - -For example... -``` -unzip Resource_Monitor@Ory0n.zip -d ~/.local/share/gnome-shell/extensions/Resource_Monitor@Ory0n - -gnome-extensions enable Resource_Monitor@Ory0n -``` - -### Cloning the master branch -1. Clone the master branch. -2. Open `Resource_Monitor` folder. -3. Move `Resource_Monitor@Ory0n` folder to `~/.local/share/gnome-shell/extensions/Resource_Monitor@Ory0n`. -4. Activate the extensions with Gnome Extensions. - -For example... -``` -git clone https://github.com/0ry0n/Resource_Monitor -cd Resource_Monitor -mv Resource_Monitor@Ory0n ~/.local/share/gnome-shell/extensions/Resource_Monitor@Ory0n - -gnome-extensions enable Resource_Monitor@Ory0n -``` - -# Preferences -![](/images/global.png) - -![](/images/cpu.png) - -![](/images/ram.png) - -![](/images/swap.png) - -![](/images/disk.png) - -![](/images/net.png) - -![](/images/thermal.png) - -![](/images/gpu.png) - -# About Units -Units are K,M,... (powers of 1024) or KB,MB,... (powers of 1000). - -# Bug Reporting -Use the GitHub [Issues](../../issues) tracker to report issues or ask for features. - -# Change Log -**version 19 (Mar 27, 2023)** -- Added support for gnome 44. -- Fixed Cpu Frequency Unit: thanks to @giacomo-boldini. -- Fixed Unit and scale factor. -- Added ability to hide GPU name. -- Added GPU icon. -- Added ability to choose the display position of items. -- Fixed incorrect classification of CPU thermal sensors. -- Added ability to show all disk devices for stats monitoring. -- Bug fixed. - -**version 18 (Oct 17, 2022)** -- Added support for gnome 43. -- Added GPU monitor (NVIDIA only). -- Added Load Average monitor. -- Added the ability to use fixed units of measure. -- Added the ability to use a custom application to launch when left-clicking the mouse. -- New preferences window. -- Bug fixed. - -**version 17 (May 9, 2022)** -- Added support for gnome 42. -- Added the ability to choose to monitor the used or free ram and swap and whether to use the percentage or the size. -- Added the ability to choose the application to start when left click. -- Bug fixed. - -**version 16 (Jan 1, 2022)** -- Added support for gnome 41. -- Added bps network unit. -- Added extension position. -- Added show or not Prefs when clicking on extension (right click). -- Added new better icons. -- Added cpu frequency: thanks to @xtenduke. -- Added automatic width when setting width to 0. -- Added the ability to choose to monitor used space or free space. -- Added the ability to monitor the temperatures of the selected devices. -- Bug fixed. - -**version 15 (Apr 15, 2021)** -- Added support for GNOME 40. -- New preferences window. -- Deprecated GTK elements removed from pref.js. - -# Authors +# Resource_Monitor GNOME Shell Extension [Get it on GNOME Extensions][ego] +[![License: GPL-3.0](https://img.shields.io/badge/License-GPL--3.0-blue.svg)](https://opensource.org/licenses/GPL-3.0) + +Resource_Monitor is a GNOME Shell extension designed to monitor system resources such as CPU, RAM, disk, and network usage, displaying them in the GNOME Shell top bar. + +| Main View | +| ------------------- | +| ![Main View](/images/main.png) | + +## GNOME Shell versions supported +**45** +- For older GNOME versions see the [gnome-3.28-3.38](../../tree/gnome-3.28-3.38) or [gnome-40-44](../../tree/gnome-40-44) branch. + +## How-To Install + +### From GNOME Extensions + +- Visit [GNOME Extensions](https://extensions.gnome.org/extension/1634/resource-monitor/) and install from there. + +### Using the Latest Release + +1. Download the latest [Release](../../releases/latest) from GitHub. +2. Unzip `Resource_Monitor@Ory0n.zip`. +3. Move the `Resource_Monitor@Ory0n` folder to `~/.local/share/gnome-shell/extensions/`. +4. Activate the extension using GNOME Extensions. + +## Preferences + +| Global Preferences | CPU Preferences | RAM Preferences | +| ------------------- | --------------- | --------------- | +| ![Global Preferences](/images/global.png) | ![CPU Preferences](/images/cpu.png) | ![RAM Preferences](/images/ram.png) | + +| SWAP Preferences | DISK Preferences | NET Preferences | +| ------------------- | ------------------- | ------------------- | +| ![SWAP Preferences](/images/swap.png) | ![DISK Preferences](/images/disk.png) | ![NET Preferences](/images/net.png) | + +| THERMAL Preferences | GPU Preferences | +| ------------------- | ------------------- | +| ![THERMAL Preferences](/images/thermal.png) | ![GPU Preferences](/images/gpu.png) | + +## About Units + +The units displayed in Resource_Monitor are in K, M, ... (powers of 1024), or KB, MB, ... (powers of 1000). + +## Bug Reporting + +To report issues or request features, please use the [GitHub Issues](../../issues) tracker. Include relevant details to help us understand and address the problem efficiently. + +## Change Log + +**Version 21 (Jan 2, 2024)** +- Added support for GNOME 45. +- Fixed left-click custom-program functionality. +- Other bug fixes. + +## Authors + - **Giuseppe Silvestro** - *Initial work* - [0ry0n](https://github.com/0ry0n) -# License +## License + This project is licensed under the GNU GPL-3.0 License - see the [LICENSE.md](/LICENSE) file for details. diff --git a/Resource_Monitor@Ory0n/extension.js b/Resource_Monitor@Ory0n/extension.js index db83273..ffd09da 100644 --- a/Resource_Monitor@Ory0n/extension.js +++ b/Resource_Monitor@Ory0n/extension.js @@ -1,6 +1,4 @@ /* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */ -/* exported init */ - /* * Resource_Monitor is Copyright © 2018-2023 Giuseppe Silvestro * @@ -20,2892 +18,3386 @@ * along with Resource_Monitor. If not, see . */ -'use strict'; - -const GETTEXT_DOMAIN = 'com-github-Ory0n-Resource_Monitor'; - -const { GObject, St, Gio, Clutter, GLib, Shell } = imports.gi; - -var NM; -try { - NM = imports.gi.NM; -} catch (error) { - log('[Resource_Monitor] NetworkManager not found (' + error + '): The \"Auto Hide\" feature has been disabled'); -} - -const ExtensionUtils = imports.misc.extensionUtils; -const Util = imports.misc.util; -const Main = imports.ui.main; -const PanelMenu = imports.ui.panelMenu; -const ByteArray = imports.byteArray; -const Gettext = imports.gettext; - -const Me = ExtensionUtils.getCurrentExtension(); -const IndicatorName = Me.metadata.name; - -const Domain = Gettext.domain(Me.metadata.uuid); - -const _ = Domain.gettext; -const ngettext = Domain.ngettext; +import GObject from "gi://GObject"; +import St from "gi://St"; +import Gio from "gi://Gio"; +import Clutter from "gi://Clutter"; +import GLib from "gi://GLib"; +import Shell from "gi://Shell"; +import NM from "gi://NM"; + +import * as Main from "resource:///org/gnome/shell/ui/main.js"; +import * as PanelMenu from "resource:///org/gnome/shell/ui/panelMenu.js"; +import * as Util from "resource:///org/gnome/shell/misc/util.js"; +import { + Extension, + gettext as _, +} from "resource:///org/gnome/shell/extensions/extension.js"; // Settings -const REFRESH_TIME = 'refreshtime'; -const EXTENSION_POSITION = 'extensionposition'; -const DECIMALS_STATUS = 'decimalsstatus'; -const LEFT_CLICK_STATUS = 'leftclickstatus'; -const RIGHT_CLICK_STATUS = 'rightclickstatus'; - -const ICONS_STATUS = 'iconsstatus'; -const ICONS_POSITION = 'iconsposition'; - -const ITEMS_POSITION = 'itemsposition'; - -const CPU_STATUS = 'cpustatus'; -const CPU_WIDTH = 'cpuwidth'; -const CPU_FREQUENCY_STATUS = 'cpufrequencystatus'; -const CPU_FREQUENCY_WIDTH = 'cpufrequencywidth'; -const CPU_FREQUENCY_UNIT_MEASURE = 'cpufrequencyunitmeasure'; -const CPU_LOADAVERAGE_STATUS = 'cpuloadaveragestatus'; -const CPU_LOADAVERAGE_WIDTH = 'cpuloadaveragewidth'; - -const RAM_STATUS = 'ramstatus'; -const RAM_WIDTH = 'ramwidth'; -const RAM_UNIT = 'ramunit'; -const RAM_UNIT_MEASURE = 'ramunitmeasure'; -const RAM_MONITOR = 'rammonitor'; - -const SWAP_STATUS = 'swapstatus'; -const SWAP_WIDTH = 'swapwidth'; -const SWAP_UNIT = 'swapunit'; -const SWAP_UNIT_MEASURE = 'swapunitmeasure'; -const SWAP_MONITOR = 'swapmonitor'; - -const DISK_STATS_STATUS = 'diskstatsstatus'; -const DISK_STATS_WIDTH = 'diskstatswidth'; -const DISK_STATS_MODE = 'diskstatsmode'; -const DISK_STATS_UNIT_MEASURE = 'diskstatsunitmeasure'; -const DISK_SPACE_STATUS = 'diskspacestatus'; -const DISK_SPACE_WIDTH = 'diskspacewidth'; -const DISK_SPACE_UNIT = 'diskspaceunit'; -const DISK_SPACE_UNIT_MEASURE = 'diskspaceunitmeasure'; -const DISK_SPACE_MONITOR = 'diskspacemonitor'; -const DISK_DEVICES_LIST = 'diskdeviceslist'; -const DISK_DEVICES_LIST_SEPARATOR = ' '; - -const NET_AUTO_HIDE_STATUS = 'netautohidestatus'; -const NET_UNIT = 'netunit'; -const NET_UNIT_MEASURE = 'netunitmeasure'; -const NET_ETH_STATUS = 'netethstatus'; -const NET_ETH_WIDTH = 'netethwidth'; -const NET_WLAN_STATUS = 'netwlanstatus'; -const NET_WLAN_WIDTH = 'netwlanwidth'; - -const THERMAL_TEMPERATURE_UNIT = 'thermaltemperatureunit'; -const THERMAL_CPU_TEMPERATURE_STATUS = 'thermalcputemperaturestatus'; -const THERMAL_CPU_TEMPERATURE_WIDTH = 'thermalcputemperaturewidth'; -const THERMAL_CPU_TEMPERATURE_DEVICES_LIST = 'thermalcputemperaturedeviceslist'; -const THERMAL_GPU_TEMPERATURE_STATUS = 'thermalgputemperaturestatus'; -const THERMAL_GPU_TEMPERATURE_WIDTH = 'thermalgputemperaturewidth'; -const THERMAL_GPU_TEMPERATURE_DEVICES_LIST = 'thermalgputemperaturedeviceslist'; -const THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR = '-'; - -const GPU_STATUS = 'gpustatus'; -const GPU_WIDTH = 'gpuwidth'; -const GPU_MEMORY_UNIT = 'gpumemoryunit'; -const GPU_MEMORY_UNIT_MEASURE = 'gpumemoryunitmeasure'; -const GPU_MEMORY_MONITOR = 'gpumemorymonitor'; -const GPU_DISPLAY_DEVICE_NAME = 'gpudisplaydevicename' -const GPU_DEVICES_LIST = 'gpudeviceslist'; -const GPU_DEVICES_LIST_SEPARATOR = ':'; +const REFRESH_TIME = "refreshtime"; +const EXTENSION_POSITION = "extensionposition"; +const DECIMALS_STATUS = "decimalsstatus"; +const LEFT_CLICK_STATUS = "leftclickstatus"; +const RIGHT_CLICK_STATUS = "rightclickstatus"; + +const ICONS_STATUS = "iconsstatus"; +const ICONS_POSITION = "iconsposition"; + +const ITEMS_POSITION = "itemsposition"; + +const CPU_STATUS = "cpustatus"; +const CPU_WIDTH = "cpuwidth"; +const CPU_FREQUENCY_STATUS = "cpufrequencystatus"; +const CPU_FREQUENCY_WIDTH = "cpufrequencywidth"; +const CPU_FREQUENCY_UNIT_MEASURE = "cpufrequencyunitmeasure"; +const CPU_LOADAVERAGE_STATUS = "cpuloadaveragestatus"; +const CPU_LOADAVERAGE_WIDTH = "cpuloadaveragewidth"; + +const RAM_STATUS = "ramstatus"; +const RAM_WIDTH = "ramwidth"; +const RAM_UNIT = "ramunit"; +const RAM_UNIT_MEASURE = "ramunitmeasure"; +const RAM_MONITOR = "rammonitor"; + +const SWAP_STATUS = "swapstatus"; +const SWAP_WIDTH = "swapwidth"; +const SWAP_UNIT = "swapunit"; +const SWAP_UNIT_MEASURE = "swapunitmeasure"; +const SWAP_MONITOR = "swapmonitor"; + +const DISK_STATS_STATUS = "diskstatsstatus"; +const DISK_STATS_WIDTH = "diskstatswidth"; +const DISK_STATS_MODE = "diskstatsmode"; +const DISK_STATS_UNIT_MEASURE = "diskstatsunitmeasure"; +const DISK_SPACE_STATUS = "diskspacestatus"; +const DISK_SPACE_WIDTH = "diskspacewidth"; +const DISK_SPACE_UNIT = "diskspaceunit"; +const DISK_SPACE_UNIT_MEASURE = "diskspaceunitmeasure"; +const DISK_SPACE_MONITOR = "diskspacemonitor"; +const DISK_DEVICES_LIST = "diskdeviceslist"; +const DISK_DEVICES_LIST_SEPARATOR = " "; + +const NET_AUTO_HIDE_STATUS = "netautohidestatus"; +const NET_UNIT = "netunit"; +const NET_UNIT_MEASURE = "netunitmeasure"; +const NET_ETH_STATUS = "netethstatus"; +const NET_ETH_WIDTH = "netethwidth"; +const NET_WLAN_STATUS = "netwlanstatus"; +const NET_WLAN_WIDTH = "netwlanwidth"; + +const THERMAL_TEMPERATURE_UNIT = "thermaltemperatureunit"; +const THERMAL_CPU_TEMPERATURE_STATUS = "thermalcputemperaturestatus"; +const THERMAL_CPU_TEMPERATURE_WIDTH = "thermalcputemperaturewidth"; +const THERMAL_CPU_TEMPERATURE_DEVICES_LIST = "thermalcputemperaturedeviceslist"; +const THERMAL_GPU_TEMPERATURE_STATUS = "thermalgputemperaturestatus"; +const THERMAL_GPU_TEMPERATURE_WIDTH = "thermalgputemperaturewidth"; +const THERMAL_GPU_TEMPERATURE_DEVICES_LIST = "thermalgputemperaturedeviceslist"; +const THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR = "-"; + +const GPU_STATUS = "gpustatus"; +const GPU_WIDTH = "gpuwidth"; +const GPU_MEMORY_UNIT = "gpumemoryunit"; +const GPU_MEMORY_UNIT_MEASURE = "gpumemoryunitmeasure"; +const GPU_MEMORY_MONITOR = "gpumemorymonitor"; +const GPU_DISPLAY_DEVICE_NAME = "gpudisplaydevicename"; +const GPU_DEVICES_LIST = "gpudeviceslist"; +const GPU_DEVICES_LIST_SEPARATOR = ":"; const ResourceMonitor = GObject.registerClass( - class ResourceMonitor extends PanelMenu.Button { - _init(settings) { - super._init(0.0, _(IndicatorName)); + class ResourceMonitor extends PanelMenu.Button { + _init({ settings, openPreferences, path, metadata }) { + super._init(0.0, metadata.name, false); - this._settings = settings; + this._settings = settings; + this._openPreferences = openPreferences; + this._path = path; + this._metadata = metadata; - // Variables - this._handlerIds = []; - this._handlerIdsCount = 0; + // Variables + this._handlerIds = []; + this._handlerIdsCount = 0; - this._nmEthStatus = false; - this._nmWlanStatus = false; + this._nmEthStatus = false; + this._nmWlanStatus = false; - this._cpuTotOld = 0; - this._cpuIdleOld = 0; + this._cpuTotOld = 0; + this._cpuIdleOld = 0; - this._duTotEthOld = [0, 0]; - this._ethIdleOld = 0; + this._duTotEthOld = [0, 0]; + this._ethIdleOld = 0; - this._duTotWlanOld = [0, 0]; - this._wlanIdleOld = 0; + this._duTotWlanOld = [0, 0]; + this._wlanIdleOld = 0; - this._cpuTemperatures = 0; - this._cpuTemperaturesReads = 0; + this._cpuTemperatures = 0; + this._cpuTemperaturesReads = 0; - this._createMainGui(); + this._createMainGui(); - this._initSettings(); + this._initSettings(); - this._buildMainGui(); + this._buildMainGui(); - this._connectSettingsSignals(); + this._connectSettingsSignals(); - this.connect('button-press-event', this._clickManager.bind(this)); + this.connect("button-press-event", this._clickManager.bind(this)); - if (typeof NM !== 'undefined') { - NM.Client.new_async(null, (client) => { - client.connect('active-connection-added', this._onActiveConnectionAdded.bind(this)); - client.connect('active-connection-removed', this._onActiveConnectionRemoved.bind(this)); + if (typeof NM !== "undefined") { + NM.Client.new_async(null, (client) => { + client.connect( + "active-connection-added", + this._onActiveConnectionAdded.bind(this) + ); + client.connect( + "active-connection-removed", + this._onActiveConnectionRemoved.bind(this) + ); - this._onActiveConnectionRemoved(client); - }); - } + this._onActiveConnectionRemoved(client); + }); + } + + this._mainTimer = GLib.timeout_add_seconds( + GLib.PRIORITY_DEFAULT, + this._refreshTime, + this._refreshHandler.bind(this) + ); + this._refreshHandler(); + } - this._mainTimer = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, this._refreshTime, this._refreshHandler.bind(this)); - this._refreshHandler(); - } + destroy() { + if (this._mainTimer) { + GLib.source_remove(this._mainTimer); + this._mainTimer = null; + } - destroy() { - if (this._mainTimer) { - GLib.source_remove(this._mainTimer); - this._mainTimer = null; - } + for (let i = 0; i < this._handlerIdsCount; i++) { + this._settings.disconnect(this._handlerIds[i]); + this._handlerIds[i] = 0; + } - for (let i = 0; i < this._handlerIdsCount; i++) { - this._settings.disconnect(this._handlerIds[i]); - this._handlerIds[i] = 0; - } + super.destroy(); + } - super.destroy(); - } + // GUI + _createMainGui() { + this._box = new St.BoxLayout(); + + // Icon + this._cpuIcon = new St.Icon({ + gicon: Gio.icon_new_for_string(this._path + "/icons/cpu-symbolic.svg"), + style_class: "system-status-icon", + }); + + this._ramIcon = new St.Icon({ + gicon: Gio.icon_new_for_string(this._path + "/icons/ram-symbolic.svg"), + style_class: "system-status-icon", + }); + + this._swapIcon = new St.Icon({ + gicon: Gio.icon_new_for_string(this._path + "/icons/swap-symbolic.svg"), + style_class: "system-status-icon", + }); + + this._diskStatsIcon = new St.Icon({ + gicon: Gio.icon_new_for_string( + this._path + "/icons/disk-stats-symbolic.svg" + ), + style_class: "system-status-icon", + }); + + this._diskSpaceIcon = new St.Icon({ + gicon: Gio.icon_new_for_string( + this._path + "/icons/disk-space-symbolic.svg" + ), + style_class: "system-status-icon", + }); + + this._ethIcon = new St.Icon({ + gicon: Gio.icon_new_for_string(this._path + "/icons/eth-symbolic.svg"), + style_class: "system-status-icon", + }); + + this._wlanIcon = new St.Icon({ + gicon: Gio.icon_new_for_string(this._path + "/icons/wlan-symbolic.svg"), + style_class: "system-status-icon", + }); + + this._gpuIcon = new St.Icon({ + gicon: Gio.icon_new_for_string(this._path + "/icons/gpu-symbolic.svg"), + style_class: "system-status-icon", + }); + + // Unit + this._cpuTemperatureUnit = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "°C", + }); + this._cpuTemperatureUnit.set_style("padding-left: 0.125em;"); + + this._cpuFrequencyUnit = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "KHz", + }); + this._cpuFrequencyUnit.set_style("padding-left: 0.125em;"); + + this._cpuUnit = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "%", + }); + this._cpuUnit.set_style("padding-left: 0.125em;"); + + this._ramUnit = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: this._ramUnitType ? "%" : "KB", + }); + this._ramUnit.set_style("padding-left: 0.125em;"); + + this._swapUnit = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: this._swapUnitType ? "%" : "KB", + }); + this._swapUnit.set_style("padding-left: 0.125em;"); + + this._ethUnit = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "K", + }); + this._ethUnit.set_style("padding-left: 0.125em;"); + + this._wlanUnit = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "K", + }); + this._wlanUnit.set_style("padding-left: 0.125em;"); + + // Value + this._cpuValue = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "--", + }); + this._cpuValue.set_style("text-align: right;"); + + this._ramValue = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "--", + }); + this._ramValue.set_style("text-align: right;"); + + this._swapValue = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "--", + }); + this._swapValue.set_style("text-align: right;"); + + this._diskStatsBox = new DiskContainerStats(); + this._diskSpaceBox = new DiskContainerSpace(); + + this._ethValue = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "--|--", + }); + this._ethValue.set_style("text-align: right;"); + + this._wlanValue = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "--|--", + }); + this._wlanValue.set_style("text-align: right;"); + + this._cpuTemperatureValue = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "[--", + }); + this._cpuTemperatureValueBracket = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "]", + }); + this._cpuTemperatureValue.set_style("text-align: right;"); + + this._cpuFrequencyValue = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "[--", + }); + this._cpuFrequencyValueBracket = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "]", + }); + this._cpuFrequencyValue.set_style("text-align: right;"); + + this._cpuLoadAverageValue = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "[--]", + }); + this._cpuLoadAverageValue.set_style("text-align: right;"); + + this._gpuBox = new GpuContainer(); + } - // GUI - _createMainGui() { - this._box = new St.BoxLayout(); + _buildMainGui() { + // Apply prefs settings + this._refreshGui(); - // Icon - this._cpuIcon = new St.Icon({ - gicon: Gio.icon_new_for_string(Me.path + '/icons/cpu-symbolic.svg'), - style_class: 'system-status-icon' - }); + switch (this._iconsPosition) { + case "left": + this._itemsPosition.forEach((element) => { + switch (element) { + case "cpu": + this._box.add(this._cpuIcon); + this._box.add(this._cpuValue); + this._box.add(this._cpuUnit); - this._ramIcon = new St.Icon({ - gicon: Gio.icon_new_for_string(Me.path + '/icons/ram-symbolic.svg'), - style_class: 'system-status-icon' - }); + this._box.add(this._cpuTemperatureValue); + this._box.add(this._cpuTemperatureUnit); + this._box.add(this._cpuTemperatureValueBracket); + this._box.add(this._cpuFrequencyValue); + this._box.add(this._cpuFrequencyUnit); + this._box.add(this._cpuFrequencyValueBracket); + this._box.add(this._cpuLoadAverageValue); - this._swapIcon = new St.Icon({ - gicon: Gio.icon_new_for_string(Me.path + '/icons/swap-symbolic.svg'), - style_class: 'system-status-icon' - }); + break; - this._diskStatsIcon = new St.Icon({ - gicon: Gio.icon_new_for_string(Me.path + '/icons/disk-stats-symbolic.svg'), - style_class: 'system-status-icon' - }); + case "ram": + this._box.add(this._ramIcon); + this._box.add(this._ramValue); + this._box.add(this._ramUnit); - this._diskSpaceIcon = new St.Icon({ - gicon: Gio.icon_new_for_string(Me.path + '/icons/disk-space-symbolic.svg'), - style_class: 'system-status-icon' - }); + break; - this._ethIcon = new St.Icon({ - gicon: Gio.icon_new_for_string(Me.path + '/icons/eth-symbolic.svg'), - style_class: 'system-status-icon' - }); + case "swap": + this._box.add(this._swapIcon); + this._box.add(this._swapValue); + this._box.add(this._swapUnit); - this._wlanIcon = new St.Icon({ - gicon: Gio.icon_new_for_string(Me.path + '/icons/wlan-symbolic.svg'), - style_class: 'system-status-icon' - }); + break; - this._gpuIcon = new St.Icon({ - gicon: Gio.icon_new_for_string(Me.path + '/icons/gpu-symbolic.svg'), - style_class: 'system-status-icon' - }); + case "stats": + this._box.add(this._diskStatsIcon); + this._box.add(this._diskStatsBox); - // Unit - this._cpuTemperatureUnit = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '°C' - }); - this._cpuTemperatureUnit.set_style('padding-left: 0.125em;'); + break; - this._cpuFrequencyUnit = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: 'KHz' - }); - this._cpuFrequencyUnit.set_style('padding-left: 0.125em;'); + case "space": + this._box.add(this._diskSpaceIcon); + this._box.add(this._diskSpaceBox); - this._cpuUnit = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '%' - }); - this._cpuUnit.set_style('padding-left: 0.125em;'); + break; - this._ramUnit = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: this._ramUnitType ? '%' : 'KB' - }); - this._ramUnit.set_style('padding-left: 0.125em;'); + case "eth": + this._box.add(this._ethIcon); + this._box.add(this._ethValue); + this._box.add(this._ethUnit); - this._swapUnit = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: this._swapUnitType ? '%' : 'KB' - }); - this._swapUnit.set_style('padding-left: 0.125em;'); + break; - this._ethUnit = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: 'K' - }); - this._ethUnit.set_style('padding-left: 0.125em;'); + case "wlan": + this._box.add(this._wlanIcon); + this._box.add(this._wlanValue); + this._box.add(this._wlanUnit); - this._wlanUnit = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: 'K' - }); - this._wlanUnit.set_style('padding-left: 0.125em;'); + break; - // Value - this._cpuValue = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '--' - }); - this._cpuValue.set_style('text-align: right;'); + case "gpu": + this._box.add(this._gpuIcon); + this._box.add(this._gpuBox); - this._ramValue = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '--' - }); - this._ramValue.set_style('text-align: right;'); + break; - this._swapValue = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '--' - }); - this._swapValue.set_style('text-align: right;'); + default: + break; + } + }); - this._diskStatsBox = new DiskContainerStats(); - this._diskSpaceBox = new DiskContainerSpace(); + break; - this._ethValue = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '--|--' - }); - this._ethValue.set_style('text-align: right;'); + case "right": - this._wlanValue = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '--|--' - }); - this._wlanValue.set_style('text-align: right;'); + default: + this._itemsPosition.forEach((element) => { + switch (element) { + case "cpu": + this._box.add(this._cpuValue); + this._box.add(this._cpuUnit); - this._cpuTemperatureValue = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '[--' - }); - this._cpuTemperatureValueBracket = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: ']' - }); - this._cpuTemperatureValue.set_style('text-align: right;'); + this._box.add(this._cpuTemperatureValue); + this._box.add(this._cpuTemperatureUnit); + this._box.add(this._cpuTemperatureValueBracket); + this._box.add(this._cpuFrequencyValue); + this._box.add(this._cpuFrequencyUnit); + this._box.add(this._cpuFrequencyValueBracket); + this._box.add(this._cpuLoadAverageValue); + this._box.add(this._cpuIcon); - this._cpuFrequencyValue = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '[--' - }); - this._cpuFrequencyValueBracket = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: ']' - }); - this._cpuFrequencyValue.set_style('text-align: right;'); + break; - this._cpuLoadAverageValue = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '[--]' - }); - this._cpuLoadAverageValue.set_style('text-align: right;'); + case "ram": + this._box.add(this._ramValue); + this._box.add(this._ramUnit); + this._box.add(this._ramIcon); - this._gpuBox = new GpuContainer(); - } + break; - _buildMainGui() { - // Apply prefs settings - this._refreshGui(); + case "swap": + this._box.add(this._swapValue); + this._box.add(this._swapUnit); + this._box.add(this._swapIcon); - switch (this._iconsPosition) { - case 'left': - this._itemsPosition.forEach(element => { - switch (element) { - case 'cpu': - this._box.add(this._cpuIcon); - this._box.add(this._cpuValue); - this._box.add(this._cpuUnit); + break; - this._box.add(this._cpuTemperatureValue); - this._box.add(this._cpuTemperatureUnit); - this._box.add(this._cpuTemperatureValueBracket); - this._box.add(this._cpuFrequencyValue); - this._box.add(this._cpuFrequencyUnit); - this._box.add(this._cpuFrequencyValueBracket); - this._box.add(this._cpuLoadAverageValue); + case "stats": + this._box.add(this._diskStatsBox); + this._box.add(this._diskStatsIcon); - break; + break; - case 'ram': - this._box.add(this._ramIcon); - this._box.add(this._ramValue); - this._box.add(this._ramUnit); + case "space": + this._box.add(this._diskSpaceBox); + this._box.add(this._diskSpaceIcon); - break; + break; - case 'swap': - this._box.add(this._swapIcon); - this._box.add(this._swapValue); - this._box.add(this._swapUnit); + case "eth": + this._box.add(this._ethValue); + this._box.add(this._ethUnit); + this._box.add(this._ethIcon); - break; + break; - case 'stats': - this._box.add(this._diskStatsIcon); - this._box.add(this._diskStatsBox); + case "wlan": + this._box.add(this._wlanValue); + this._box.add(this._wlanUnit); + this._box.add(this._wlanIcon); - break; + break; - case 'space': - this._box.add(this._diskSpaceIcon); - this._box.add(this._diskSpaceBox); + case "gpu": + this._box.add(this._gpuBox); + this._box.add(this._gpuIcon); - break; + break; - case 'eth': - this._box.add(this._ethIcon); - this._box.add(this._ethValue); - this._box.add(this._ethUnit); + default: + break; + } + }); - break; + break; + } - case 'wlan': - this._box.add(this._wlanIcon); - this._box.add(this._wlanValue); - this._box.add(this._wlanUnit); + this.add_child(this._box); + } - break; + // SETTINGS + _initSettings() { + this._refreshTime = this._settings.get_int(REFRESH_TIME); + this._decimalsStatus = this._settings.get_boolean(DECIMALS_STATUS); + this._leftClickStatus = this._settings.get_string(LEFT_CLICK_STATUS); + this._rightClickStatus = this._settings.get_boolean(RIGHT_CLICK_STATUS); + + this._iconsStatus = this._settings.get_boolean(ICONS_STATUS); + this._iconsPosition = this._settings.get_string(ICONS_POSITION); + + this._itemsPosition = this._settings.get_strv(ITEMS_POSITION); + + this._cpuStatus = this._settings.get_boolean(CPU_STATUS); + this._cpuWidth = this._settings.get_int(CPU_WIDTH); + this._cpuFrequencyStatus = + this._settings.get_boolean(CPU_FREQUENCY_STATUS); + this._cpuFrequencyWidth = this._settings.get_int(CPU_FREQUENCY_WIDTH); + this._cpuFrequencyUnitMeasure = this._settings.get_string( + CPU_FREQUENCY_UNIT_MEASURE + ); + this._cpuLoadAverageStatus = this._settings.get_boolean( + CPU_LOADAVERAGE_STATUS + ); + this._cpuLoadAverageWidth = this._settings.get_int(CPU_LOADAVERAGE_WIDTH); + + this._ramStatus = this._settings.get_boolean(RAM_STATUS); + this._ramWidth = this._settings.get_int(RAM_WIDTH); + this._ramUnitType = this._settings.get_string(RAM_UNIT); + this._ramUnitMeasure = this._settings.get_string(RAM_UNIT_MEASURE); + this._ramMonitor = this._settings.get_string(RAM_MONITOR); + + this._swapStatus = this._settings.get_boolean(SWAP_STATUS); + this._swapWidth = this._settings.get_int(SWAP_WIDTH); + this._swapUnitType = this._settings.get_string(SWAP_UNIT); + this._swapUnitMeasure = this._settings.get_string(SWAP_UNIT_MEASURE); + this._swapMonitor = this._settings.get_string(SWAP_MONITOR); + + this._diskStatsStatus = this._settings.get_boolean(DISK_STATS_STATUS); + this._diskStatsWidth = this._settings.get_int(DISK_STATS_WIDTH); + this._diskStatsMode = this._settings.get_string(DISK_STATS_MODE); + this._diskStatsUnitMeasure = this._settings.get_string( + DISK_STATS_UNIT_MEASURE + ); + this._diskSpaceStatus = this._settings.get_boolean(DISK_SPACE_STATUS); + this._diskSpaceWidth = this._settings.get_int(DISK_SPACE_WIDTH); + this._diskSpaceUnitType = this._settings.get_string(DISK_SPACE_UNIT); + this._diskSpaceUnitMeasure = this._settings.get_string( + DISK_SPACE_UNIT_MEASURE + ); + this._diskSpaceMonitor = this._settings.get_string(DISK_SPACE_MONITOR); + this._diskDevicesList = this._settings.get_strv(DISK_DEVICES_LIST); + + this._netAutoHideStatus = + this._settings.get_boolean(NET_AUTO_HIDE_STATUS) && + typeof NM !== "undefined"; + this._netUnit = this._settings.get_string(NET_UNIT); + this._netUnitMeasure = this._settings.get_string(NET_UNIT_MEASURE); + this._netEthStatus = this._settings.get_boolean(NET_ETH_STATUS); + this._netEthWidth = this._settings.get_int(NET_ETH_WIDTH); + this._netWlanStatus = this._settings.get_boolean(NET_WLAN_STATUS); + this._netWlanWidth = this._settings.get_int(NET_WLAN_WIDTH); + + this._thermalTemperatureUnit = this._settings.get_string( + THERMAL_TEMPERATURE_UNIT + ); + this._thermalCpuTemperatureStatus = this._settings.get_boolean( + THERMAL_CPU_TEMPERATURE_STATUS + ); + this._thermalCpuTemperatureWidth = this._settings.get_int( + THERMAL_CPU_TEMPERATURE_WIDTH + ); + this._thermalCpuTemperatureDevicesList = this._settings.get_strv( + THERMAL_CPU_TEMPERATURE_DEVICES_LIST + ); + this._thermalGpuTemperatureStatus = this._settings.get_boolean( + THERMAL_GPU_TEMPERATURE_STATUS + ); + this._thermalGpuTemperatureWidth = this._settings.get_int( + THERMAL_GPU_TEMPERATURE_WIDTH + ); + this._thermalGpuTemperatureDevicesList = this._settings.get_strv( + THERMAL_GPU_TEMPERATURE_DEVICES_LIST + ); + + this._gpuStatus = this._settings.get_boolean(GPU_STATUS); + this._gpuWidth = this._settings.get_int(GPU_WIDTH); + this._gpuMemoryUnitType = this._settings.get_string(GPU_MEMORY_UNIT); + this._gpuMemoryUnitMeasure = this._settings.get_string( + GPU_MEMORY_UNIT_MEASURE + ); + this._gpuMemoryMonitor = this._settings.get_string(GPU_MEMORY_MONITOR); + this._gpuDisplayDeviceName = this._settings.get_boolean( + GPU_DISPLAY_DEVICE_NAME + ); + this._gpuDevicesList = this._settings.get_strv(GPU_DEVICES_LIST); + } - case 'gpu': - this._box.add(this._gpuIcon); - this._box.add(this._gpuBox); + _connectSettingsSignals() { + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${REFRESH_TIME}`, + this._refreshTimeChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${DECIMALS_STATUS}`, + this._decimalsStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${LEFT_CLICK_STATUS}`, + this._leftClickStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${RIGHT_CLICK_STATUS}`, + this._rightClickStatusChanged.bind(this) + ); + + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${ICONS_STATUS}`, + this._iconsStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${ICONS_POSITION}`, + this._iconsPositionChanged.bind(this) + ); + + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${ITEMS_POSITION}`, + this._itemsPositionChanged.bind(this) + ); + + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${CPU_STATUS}`, + this._cpuStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${CPU_WIDTH}`, + this._cpuWidthChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${CPU_FREQUENCY_STATUS}`, + this._cpuFrequencyStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${CPU_FREQUENCY_WIDTH}`, + this._cpuFrequencyWidthChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${CPU_FREQUENCY_UNIT_MEASURE}`, + this._cpuFrequencyUnitMeasureChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${CPU_LOADAVERAGE_STATUS}`, + this._cpuLoadAverageStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${CPU_LOADAVERAGE_WIDTH}`, + this._cpuLoadAverageWidthChanged.bind(this) + ); + + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${RAM_STATUS}`, + this._ramStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${RAM_WIDTH}`, + this._ramWidthChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${RAM_UNIT}`, + this._ramUnitTypeChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${RAM_UNIT_MEASURE}`, + this._ramUnitMeasureChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${RAM_MONITOR}`, + this._ramMonitorChanged.bind(this) + ); + + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${SWAP_STATUS}`, + this._swapStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${SWAP_WIDTH}`, + this._swapWidthChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${SWAP_UNIT}`, + this._swapUnitTypeChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${SWAP_UNIT_MEASURE}`, + this._swapUnitMeasureChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${SWAP_MONITOR}`, + this._swapMonitorChanged.bind(this) + ); + + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${DISK_STATS_STATUS}`, + this._diskStatsStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${DISK_STATS_WIDTH}`, + this._diskStatsWidthChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${DISK_STATS_MODE}`, + this._diskStatsModeChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${DISK_STATS_UNIT_MEASURE}`, + this._diskStatsUnitMeasureChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${DISK_SPACE_STATUS}`, + this._diskSpaceStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${DISK_SPACE_WIDTH}`, + this._diskSpaceWidthChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${DISK_SPACE_UNIT}`, + this._diskSpaceUnitTypeChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${DISK_SPACE_UNIT_MEASURE}`, + this._diskSpaceUnitMeasureChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${DISK_SPACE_MONITOR}`, + this._diskSpaceMonitorChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${DISK_DEVICES_LIST}`, + this._diskDevicesListChanged.bind(this) + ); + + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${NET_AUTO_HIDE_STATUS}`, + this._netAutoHideStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${NET_UNIT}`, + this._netUnitChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${NET_UNIT_MEASURE}`, + this._netUnitMeasureChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${NET_ETH_STATUS}`, + this._netEthStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${NET_ETH_WIDTH}`, + this._netEthWidthChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${NET_WLAN_STATUS}`, + this._netWlanStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${NET_WLAN_WIDTH}`, + this._netWlanWidthChanged.bind(this) + ); + + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${THERMAL_TEMPERATURE_UNIT}`, + this._thermalTemperatureUnitChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${THERMAL_CPU_TEMPERATURE_STATUS}`, + this._thermalCpuTemperatureStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${THERMAL_CPU_TEMPERATURE_WIDTH}`, + this._thermalCpuTemperatureWidthChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${THERMAL_CPU_TEMPERATURE_DEVICES_LIST}`, + this._thermalCpuTemperatureDevicesListChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${THERMAL_GPU_TEMPERATURE_STATUS}`, + this._thermalGpuTemperatureStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${THERMAL_GPU_TEMPERATURE_WIDTH}`, + this._thermalGpuTemperatureWidthChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${THERMAL_GPU_TEMPERATURE_DEVICES_LIST}`, + this._thermalGpuTemperatureDevicesListChanged.bind(this) + ); + + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${GPU_STATUS}`, + this._gpuStatusChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${GPU_WIDTH}`, + this._gpuWidthChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${GPU_MEMORY_UNIT}`, + this._gpuMemoryUnitTypeChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${GPU_MEMORY_UNIT_MEASURE}`, + this._gpuMemoryUnitMeasureChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${GPU_MEMORY_MONITOR}`, + this._gpuMemoryMonitorChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${GPU_DISPLAY_DEVICE_NAME}`, + this._gpuDisplayDeviceNameChanged.bind(this) + ); + this._handlerIds[this._handlerIdsCount++] = this._settings.connect( + `changed::${GPU_DEVICES_LIST}`, + this._gpuDevicesListChanged.bind(this) + ); + } - break; + // HANDLERS + _clickManager(actor, event) { + switch (event.get_button()) { + case 3: // Right Click + if (this._rightClickStatus) { + this._openPreferences(); + } - default: + break; - break; - } - }); + case 1: // Left Click - break; + default: + if (this._leftClickStatus !== "") { + const appSystem = Shell.AppSystem.get_default(); + const appName = this._leftClickStatus + ".desktop"; - case 'right': + let app = appSystem.lookup_app(appName); - default: - this._itemsPosition.forEach(element => { - switch (element) { - case 'cpu': - this._box.add(this._cpuValue); - this._box.add(this._cpuUnit); + if (app) { + // Application found, activate it + app.activate(); + } else { + try { + Util.spawnCommandLine(this._leftClickStatus); + } catch (e) { + logError(`Error spawning ${this._leftClickStatus}: ${e}`); + } + } + } - this._box.add(this._cpuTemperatureValue); - this._box.add(this._cpuTemperatureUnit); - this._box.add(this._cpuTemperatureValueBracket); - this._box.add(this._cpuFrequencyValue); - this._box.add(this._cpuFrequencyUnit); - this._box.add(this._cpuFrequencyValueBracket); - this._box.add(this._cpuLoadAverageValue); - this._box.add(this._cpuIcon); + break; + } + } - break; + _onActiveConnectionAdded(client, activeConnection) { + activeConnection.get_devices().forEach((device) => { + switch (device.get_device_type()) { + case NM.DeviceType.ETHERNET: + this._nmEthStatus = true; + + break; + + case NM.DeviceType.WIFI: + this._nmWlanStatus = true; + + break; + + default: + break; + } + }); + + this._basicItemStatus( + (this._netEthStatus && this._nmEthStatus) || + (this._netEthStatus && !this._netAutoHideStatus), + true, + this._ethIcon, + this._ethValue, + this._ethUnit + ); + this._basicItemStatus( + (this._netWlanStatus && this._nmWlanStatus) || + (this._netWlanStatus && !this._netAutoHideStatus), + true, + this._wlanIcon, + this._wlanValue, + this._wlanUnit + ); + } - case 'ram': - this._box.add(this._ramValue); - this._box.add(this._ramUnit); - this._box.add(this._ramIcon); + _onActiveConnectionRemoved(client, activeConnection) { + this._nmEthStatus = false; + this._nmWlanStatus = false; - break; + client.get_active_connections().forEach((activeConnection) => { + activeConnection.get_devices().forEach((device) => { + switch (device.get_device_type()) { + case NM.DeviceType.ETHERNET: + this._nmEthStatus = true; - case 'swap': - this._box.add(this._swapValue); - this._box.add(this._swapUnit); - this._box.add(this._swapIcon); + break; - break; + case NM.DeviceType.WIFI: + this._nmWlanStatus = true; - case 'stats': - this._box.add(this._diskStatsBox); - this._box.add(this._diskStatsIcon); + break; - break; + default: + break; + } + }); + }); + + this._basicItemStatus( + (this._netEthStatus && this._nmEthStatus) || + (this._netEthStatus && !this._netAutoHideStatus), + true, + this._ethIcon, + this._ethValue, + this._ethUnit + ); + this._basicItemStatus( + (this._netWlanStatus && this._nmWlanStatus) || + (this._netWlanStatus && !this._netAutoHideStatus), + true, + this._wlanIcon, + this._wlanValue, + this._wlanUnit + ); + } - case 'space': - this._box.add(this._diskSpaceBox); - this._box.add(this._diskSpaceIcon); + _refreshTimeChanged() { + this._refreshTime = this._settings.get_int(REFRESH_TIME); - break; + if (this._mainTimer) { + GLib.source_remove(this._mainTimer); + this._mainTimer = null; + } - case 'eth': - this._box.add(this._ethValue); - this._box.add(this._ethUnit); - this._box.add(this._ethIcon); + this._mainTimer = GLib.timeout_add_seconds( + GLib.PRIORITY_DEFAULT, + this._refreshTime, + this._refreshHandler.bind(this) + ); + } - break; + _decimalsStatusChanged() { + this._decimalsStatus = this._settings.get_boolean(DECIMALS_STATUS); - case 'wlan': - this._box.add(this._wlanValue); - this._box.add(this._wlanUnit); - this._box.add(this._wlanIcon); + this._refreshHandler(); + } - break; + _leftClickStatusChanged() { + this._leftClickStatus = this._settings.get_string(LEFT_CLICK_STATUS); + } - case 'gpu': - this._box.add(this._gpuBox); - this._box.add(this._gpuIcon); + _rightClickStatusChanged() { + this._rightClickStatus = this._settings.get_boolean(RIGHT_CLICK_STATUS); + } - break; + _iconsStatusChanged() { + this._iconsStatus = this._settings.get_boolean(ICONS_STATUS); + + if (this._iconsStatus) { + if ( + this._cpuStatus || + this._cpuFrequencyStatus || + this._cpuLoadAverageStatus || + this._thermalCpuTemperatureStatus + ) { + this._cpuIcon.show(); + } + if (this._ramStatus) { + this._ramIcon.show(); + } + if (this._swapStatus) { + this._swapIcon.show(); + } + if (this._diskStatsStatus) { + this._diskStatsIcon.show(); + } + if (this._diskSpaceStatus) { + this._diskSpaceIcon.show(); + } + if ( + (this._netEthStatus && this._nmEthStatus) || + (this._netEthStatus && !this._netAutoHideStatus) + ) { + this._ethIcon.show(); + } + if ( + (this._netWlanStatus && this._nmWlanStatus) || + (this._netWlanStatus && !this._netAutoHideStatus) + ) { + this._wlanIcon.show(); + } + if (this._gpuStatus || this._thermalGpuTemperatureStatus) { + this._gpuIcon.show(); + } + } else { + this._cpuIcon.hide(); + this._ramIcon.hide(); + this._swapIcon.hide(); + this._diskStatsIcon.hide(); + this._diskSpaceIcon.hide(); + this._ethIcon.hide(); + this._wlanIcon.hide(); + this._gpuIcon.hide(); + } + } - default: - break; - } - }); + _iconsPositionChanged() { + this._iconsPosition = this._settings.get_string(ICONS_POSITION); - break; - } + this._box.remove_all_children(); - this.add_child(this._box); - } + this._buildMainGui(); + } - // SETTINGS - _initSettings() { - this._refreshTime = this._settings.get_int(REFRESH_TIME); - this._decimalsStatus = this._settings.get_boolean(DECIMALS_STATUS); - this._leftClickStatus = this._settings.get_string(LEFT_CLICK_STATUS); - this._rightClickStatus = this._settings.get_boolean(RIGHT_CLICK_STATUS); - - this._iconsStatus = this._settings.get_boolean(ICONS_STATUS); - this._iconsPosition = this._settings.get_string(ICONS_POSITION); - - this._itemsPosition = this._settings.get_strv(ITEMS_POSITION); - - this._cpuStatus = this._settings.get_boolean(CPU_STATUS); - this._cpuWidth = this._settings.get_int(CPU_WIDTH); - this._cpuFrequencyStatus = this._settings.get_boolean(CPU_FREQUENCY_STATUS); - this._cpuFrequencyWidth = this._settings.get_int(CPU_FREQUENCY_WIDTH); - this._cpuFrequencyUnitMeasure = this._settings.get_string(CPU_FREQUENCY_UNIT_MEASURE); - this._cpuLoadAverageStatus = this._settings.get_boolean(CPU_LOADAVERAGE_STATUS); - this._cpuLoadAverageWidth = this._settings.get_int(CPU_LOADAVERAGE_WIDTH); - - this._ramStatus = this._settings.get_boolean(RAM_STATUS); - this._ramWidth = this._settings.get_int(RAM_WIDTH); - this._ramUnitType = this._settings.get_string(RAM_UNIT); - this._ramUnitMeasure = this._settings.get_string(RAM_UNIT_MEASURE); - this._ramMonitor = this._settings.get_string(RAM_MONITOR); - - this._swapStatus = this._settings.get_boolean(SWAP_STATUS); - this._swapWidth = this._settings.get_int(SWAP_WIDTH); - this._swapUnitType = this._settings.get_string(SWAP_UNIT); - this._swapUnitMeasure = this._settings.get_string(SWAP_UNIT_MEASURE); - this._swapMonitor = this._settings.get_string(SWAP_MONITOR); - - this._diskStatsStatus = this._settings.get_boolean(DISK_STATS_STATUS); - this._diskStatsWidth = this._settings.get_int(DISK_STATS_WIDTH); - this._diskStatsMode = this._settings.get_string(DISK_STATS_MODE); - this._diskStatsUnitMeasure = this._settings.get_string(DISK_STATS_UNIT_MEASURE); - this._diskSpaceStatus = this._settings.get_boolean(DISK_SPACE_STATUS); - this._diskSpaceWidth = this._settings.get_int(DISK_SPACE_WIDTH); - this._diskSpaceUnitType = this._settings.get_string(DISK_SPACE_UNIT); - this._diskSpaceUnitMeasure = this._settings.get_string(DISK_SPACE_UNIT_MEASURE); - this._diskSpaceMonitor = this._settings.get_string(DISK_SPACE_MONITOR); - this._diskDevicesList = this._settings.get_strv(DISK_DEVICES_LIST); - - this._netAutoHideStatus = this._settings.get_boolean(NET_AUTO_HIDE_STATUS) && typeof NM !== 'undefined'; - this._netUnit = this._settings.get_string(NET_UNIT); - this._netUnitMeasure = this._settings.get_string(NET_UNIT_MEASURE); - this._netEthStatus = this._settings.get_boolean(NET_ETH_STATUS); - this._netEthWidth = this._settings.get_int(NET_ETH_WIDTH); - this._netWlanStatus = this._settings.get_boolean(NET_WLAN_STATUS); - this._netWlanWidth = this._settings.get_int(NET_WLAN_WIDTH); - - this._thermalTemperatureUnit = this._settings.get_string(THERMAL_TEMPERATURE_UNIT); - this._thermalCpuTemperatureStatus = this._settings.get_boolean(THERMAL_CPU_TEMPERATURE_STATUS); - this._thermalCpuTemperatureWidth = this._settings.get_int(THERMAL_CPU_TEMPERATURE_WIDTH); - this._thermalCpuTemperatureDevicesList = this._settings.get_strv(THERMAL_CPU_TEMPERATURE_DEVICES_LIST); - this._thermalGpuTemperatureStatus = this._settings.get_boolean(THERMAL_GPU_TEMPERATURE_STATUS); - this._thermalGpuTemperatureWidth = this._settings.get_int(THERMAL_GPU_TEMPERATURE_WIDTH); - this._thermalGpuTemperatureDevicesList = this._settings.get_strv(THERMAL_GPU_TEMPERATURE_DEVICES_LIST); - - this._gpuStatus = this._settings.get_boolean(GPU_STATUS); - this._gpuWidth = this._settings.get_int(GPU_WIDTH); - this._gpuMemoryUnitType = this._settings.get_string(GPU_MEMORY_UNIT); - this._gpuMemoryUnitMeasure = this._settings.get_string(GPU_MEMORY_UNIT_MEASURE); - this._gpuMemoryMonitor = this._settings.get_string(GPU_MEMORY_MONITOR); - this._gpuDisplayDeviceName = this._settings.get_boolean(GPU_DISPLAY_DEVICE_NAME); - this._gpuDevicesList = this._settings.get_strv(GPU_DEVICES_LIST); - } + _itemsPositionChanged() { + this._itemsPosition = this._settings.get_strv(ITEMS_POSITION); - _connectSettingsSignals() { - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${REFRESH_TIME}`, this._refreshTimeChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${DECIMALS_STATUS}`, this._decimalsStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${LEFT_CLICK_STATUS}`, this._leftClickStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${RIGHT_CLICK_STATUS}`, this._rightClickStatusChanged.bind(this)); - - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${ICONS_STATUS}`, this._iconsStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${ICONS_POSITION}`, this._iconsPositionChanged.bind(this)); - - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${ITEMS_POSITION}`, this._itemsPositionChanged.bind(this)); - - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${CPU_STATUS}`, this._cpuStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${CPU_WIDTH}`, this._cpuWidthChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${CPU_FREQUENCY_STATUS}`, this._cpuFrequencyStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${CPU_FREQUENCY_WIDTH}`, this._cpuFrequencyWidthChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${CPU_FREQUENCY_UNIT_MEASURE}`, this._cpuFrequencyUnitMeasureChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${CPU_LOADAVERAGE_STATUS}`, this._cpuLoadAverageStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${CPU_LOADAVERAGE_WIDTH}`, this._cpuLoadAverageWidthChanged.bind(this)); - - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${RAM_STATUS}`, this._ramStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${RAM_WIDTH}`, this._ramWidthChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${RAM_UNIT}`, this._ramUnitTypeChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${RAM_UNIT_MEASURE}`, this._ramUnitMeasureChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${RAM_MONITOR}`, this._ramMonitorChanged.bind(this)); - - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${SWAP_STATUS}`, this._swapStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${SWAP_WIDTH}`, this._swapWidthChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${SWAP_UNIT}`, this._swapUnitTypeChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${SWAP_UNIT_MEASURE}`, this._swapUnitMeasureChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${SWAP_MONITOR}`, this._swapMonitorChanged.bind(this)); - - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${DISK_STATS_STATUS}`, this._diskStatsStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${DISK_STATS_WIDTH}`, this._diskStatsWidthChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${DISK_STATS_MODE}`, this._diskStatsModeChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${DISK_STATS_UNIT_MEASURE}`, this._diskStatsUnitMeasureChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${DISK_SPACE_STATUS}`, this._diskSpaceStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${DISK_SPACE_WIDTH}`, this._diskSpaceWidthChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${DISK_SPACE_UNIT}`, this._diskSpaceUnitTypeChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${DISK_SPACE_UNIT_MEASURE}`, this._diskSpaceUnitMeasureChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${DISK_SPACE_MONITOR}`, this._diskSpaceMonitorChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${DISK_DEVICES_LIST}`, this._diskDevicesListChanged.bind(this)); - - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${NET_AUTO_HIDE_STATUS}`, this._netAutoHideStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${NET_UNIT}`, this._netUnitChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${NET_UNIT_MEASURE}`, this._netUnitMeasureChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${NET_ETH_STATUS}`, this._netEthStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${NET_ETH_WIDTH}`, this._netEthWidthChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${NET_WLAN_STATUS}`, this._netWlanStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${NET_WLAN_WIDTH}`, this._netWlanWidthChanged.bind(this)); - - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${THERMAL_TEMPERATURE_UNIT}`, this._thermalTemperatureUnitChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${THERMAL_CPU_TEMPERATURE_STATUS}`, this._thermalCpuTemperatureStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${THERMAL_CPU_TEMPERATURE_WIDTH}`, this._thermalCpuTemperatureWidthChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${THERMAL_CPU_TEMPERATURE_DEVICES_LIST}`, this._thermalCpuTemperatureDevicesListChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${THERMAL_GPU_TEMPERATURE_STATUS}`, this._thermalGpuTemperatureStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${THERMAL_GPU_TEMPERATURE_WIDTH}`, this._thermalGpuTemperatureWidthChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${THERMAL_GPU_TEMPERATURE_DEVICES_LIST}`, this._thermalGpuTemperatureDevicesListChanged.bind(this)); - - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${GPU_STATUS}`, this._gpuStatusChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${GPU_WIDTH}`, this._gpuWidthChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${GPU_MEMORY_UNIT}`, this._gpuMemoryUnitTypeChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${GPU_MEMORY_UNIT_MEASURE}`, this._gpuMemoryUnitMeasureChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${GPU_MEMORY_MONITOR}`, this._gpuMemoryMonitorChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${GPU_DISPLAY_DEVICE_NAME}`, this._gpuDisplayDeviceNameChanged.bind(this)); - this._handlerIds[this._handlerIdsCount++] = this._settings.connect(`changed::${GPU_DEVICES_LIST}`, this._gpuDevicesListChanged.bind(this)); - } + this._box.remove_all_children(); - // HANDLERS - _clickManager(actor, event) { - switch (event.get_button()) { - case 3: // Right Click - if (this._rightClickStatus) { - ExtensionUtils.openPrefs(); - } + this._buildMainGui(); + } - break; + _cpuStatusChanged() { + this._cpuStatus = this._settings.get_boolean(CPU_STATUS); + + this._basicItemStatus( + this._cpuStatus, + !this._thermalCpuTemperatureStatus && + !this._cpuFrequencyStatus && + !this._cpuLoadAverageStatus, + this._cpuIcon, + this._cpuValue, + this._cpuUnit + ); + } - case 1: // Left Click + _cpuWidthChanged() { + this._cpuWidth = this._settings.get_int(CPU_WIDTH); - default: - if (this._leftClickStatus !== "") { - let app = global.log(Shell.AppSystem.get_default().lookup_app(this._leftClickStatus + '.desktop')); + this._basicItemWidth(this._cpuWidth, this._cpuValue); + } - if (app != null) { - app.activate(); - } else { - Util.spawn([this._leftClickStatus]); - } - } + _cpuFrequencyStatusChanged() { + this._cpuFrequencyStatus = + this._settings.get_boolean(CPU_FREQUENCY_STATUS); + + this._basicItemStatus( + this._cpuFrequencyStatus, + !this._cpuStatus && + !this._thermalCpuTemperatureStatus && + !this._cpuLoadAverageStatus, + this._cpuIcon, + this._cpuFrequencyValue, + this._cpuFrequencyUnit, + this._cpuFrequencyValueBracket + ); + } - break; - } - } + _cpuFrequencyWidthChanged() { + this._cpuFrequencyWidth = this._settings.get_int(CPU_FREQUENCY_WIDTH); - _onActiveConnectionAdded(client, activeConnection) { - activeConnection.get_devices().forEach(device => { - switch (device.get_device_type()) { - case NM.DeviceType.ETHERNET: - this._nmEthStatus = true; + this._basicItemWidth(this._cpuFrequencyWidth, this._cpuFrequencyValue); + } - break; + _cpuFrequencyUnitMeasureChanged() { + this._cpuFrequencyUnitMeasure = this._settings.get_string( + CPU_FREQUENCY_UNIT_MEASURE + ); - case NM.DeviceType.WIFI: - this._nmWlanStatus = true; + if (this._cpuFrequencyStatus) { + this._refreshCpuFrequencyValue(); + } + } - break; + _cpuLoadAverageStatusChanged() { + this._cpuLoadAverageStatus = this._settings.get_boolean( + CPU_LOADAVERAGE_STATUS + ); + + this._basicItemStatus( + this._cpuLoadAverageStatus, + !this._cpuStatus && + !this._thermalCpuTemperatureStatus && + !this._cpuFrequencyStatus, + this._cpuIcon, + this._cpuLoadAverageValue + ); + } - default: + _cpuLoadAverageWidthChanged() { + this._cpuLoadAverageWidth = this._settings.get_int(CPU_LOADAVERAGE_WIDTH); - break; - } - }); + this._basicItemWidth( + this._cpuLoadAverageWidth, + this._cpuLoadAverageValue + ); + } - this._basicItemStatus((this._netEthStatus && this._nmEthStatus) || (this._netEthStatus && !this._netAutoHideStatus), true, this._ethIcon, this._ethValue, this._ethUnit); - this._basicItemStatus((this._netWlanStatus && this._nmWlanStatus) || (this._netWlanStatus && !this._netAutoHideStatus), true, this._wlanIcon, this._wlanValue, this._wlanUnit); - } + _ramStatusChanged() { + this._ramStatus = this._settings.get_boolean(RAM_STATUS); - _onActiveConnectionRemoved(client, activeConnection) { - this._nmEthStatus = false; - this._nmWlanStatus = false; + this._basicItemStatus( + this._ramStatus, + true, + this._ramIcon, + this._ramValue, + this._ramUnit + ); + } - client.get_active_connections().forEach(activeConnection => { - activeConnection.get_devices().forEach(device => { - switch (device.get_device_type()) { - case NM.DeviceType.ETHERNET: - this._nmEthStatus = true; + _ramWidthChanged() { + this._ramWidth = this._settings.get_int(RAM_WIDTH); - break; + this._basicItemWidth(this._ramWidth, this._ramValue); + } - case NM.DeviceType.WIFI: - this._nmWlanStatus = true; + _ramUnitTypeChanged() { + this._ramUnitType = this._settings.get_string(RAM_UNIT); - break; + if (this._ramStatus) { + this._refreshRamValue(); + } + } - default: + _ramUnitMeasureChanged() { + this._ramUnitMeasure = this._settings.get_string(RAM_UNIT_MEASURE); - break; - } - }); - }); + if (this._ramStatus) { + this._refreshRamValue(); + } + } - this._basicItemStatus((this._netEthStatus && this._nmEthStatus) || (this._netEthStatus && !this._netAutoHideStatus), true, this._ethIcon, this._ethValue, this._ethUnit); - this._basicItemStatus((this._netWlanStatus && this._nmWlanStatus) || (this._netWlanStatus && !this._netAutoHideStatus), true, this._wlanIcon, this._wlanValue, this._wlanUnit); - } + _ramMonitorChanged() { + this._ramMonitor = this._settings.get_string(RAM_MONITOR); - _refreshTimeChanged() { - this._refreshTime = this._settings.get_int(REFRESH_TIME); + if (this._ramStatus) { + this._refreshRamValue(); + } + } - if (this._mainTimer) { - GLib.source_remove(this._mainTimer); - this._mainTimer = null; - } + _swapStatusChanged() { + this._swapStatus = this._settings.get_boolean(SWAP_STATUS); - this._mainTimer = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, this._refreshTime, this._refreshHandler.bind(this)); - } + this._basicItemStatus( + this._swapStatus, + true, + this._swapIcon, + this._swapValue, + this._swapUnit + ); + } - _decimalsStatusChanged() { - this._decimalsStatus = this._settings.get_boolean(DECIMALS_STATUS); + _swapWidthChanged() { + this._swapWidth = this._settings.get_int(SWAP_WIDTH); - this._refreshHandler(); - } + this._basicItemWidth(this._swapWidth, this._swapValue); + } - _leftClickStatusChanged() { - this._leftClickStatus = this._settings.get_string(LEFT_CLICK_STATUS); - } + _swapUnitTypeChanged() { + this._swapUnitType = this._settings.get_string(SWAP_UNIT); - _rightClickStatusChanged() { - this._rightClickStatus = this._settings.get_boolean(RIGHT_CLICK_STATUS); - } + if (this._swapStatus) { + this._refreshSwapValue(); + } + } - _iconsStatusChanged() { - this._iconsStatus = this._settings.get_boolean(ICONS_STATUS); + _swapUnitMeasureChanged() { + this._swapUnitMeasure = this._settings.get_string(SWAP_UNIT_MEASURE); - if (this._iconsStatus) { - if (this._cpuStatus || this._cpuFrequencyStatus || this._cpuLoadAverageStatus || this._thermalCpuTemperatureStatus) { - this._cpuIcon.show(); - } - if (this._ramStatus) { - this._ramIcon.show(); - } - if (this._swapStatus) { - this._swapIcon.show(); - } - if (this._diskStatsStatus) { - this._diskStatsIcon.show(); - } - if (this._diskSpaceStatus) { - this._diskSpaceIcon.show(); - } - if ((this._netEthStatus && this._nmEthStatus) || (this._netEthStatus && !this._netAutoHideStatus)) { - this._ethIcon.show(); - } - if ((this._netWlanStatus && this._nmWlanStatus) || (this._netWlanStatus && !this._netAutoHideStatus)) { - this._wlanIcon.show(); - } - if (this._gpuStatus || this._thermalGpuTemperatureStatus) { - this._gpuIcon.show(); - } - } else { - this._cpuIcon.hide(); - this._ramIcon.hide(); - this._swapIcon.hide(); - this._diskStatsIcon.hide(); - this._diskSpaceIcon.hide(); - this._ethIcon.hide(); - this._wlanIcon.hide(); - this._gpuIcon.hide(); - } - } + if (this._swapStatus) { + this._refreshSwapValue(); + } + } - _iconsPositionChanged() { - this._iconsPosition = this._settings.get_string(ICONS_POSITION); + _swapMonitorChanged() { + this._swapMonitor = this._settings.get_string(SWAP_MONITOR); - this._box.remove_all_children(); + if (this._swapStatus) { + this._refreshSwapValue(); + } + } - this._buildMainGui(); - } + _diskStatsStatusChanged() { + this._diskStatsStatus = this._settings.get_boolean(DISK_STATS_STATUS); - _itemsPositionChanged() { - this._itemsPosition = this._settings.get_strv(ITEMS_POSITION); + this._basicItemStatus( + this._diskStatsStatus, + true, + this._diskStatsIcon, + this._diskStatsBox + ); + } - this._box.remove_all_children(); + _diskStatsWidthChanged() { + this._diskStatsWidth = this._settings.get_int(DISK_STATS_WIDTH); - this._buildMainGui(); - } + this._diskStatsBox.set_element_width(this._diskStatsWidth); + } - _cpuStatusChanged() { - this._cpuStatus = this._settings.get_boolean(CPU_STATUS); + _diskStatsModeChanged() { + this._diskStatsMode = this._settings.get_string(DISK_STATS_MODE); - this._basicItemStatus(this._cpuStatus, (!this._thermalCpuTemperatureStatus && !this._cpuFrequencyStatus && !this._cpuLoadAverageStatus), this._cpuIcon, this._cpuValue, this._cpuUnit); - } + this._diskStatsBox.update_mode(this._diskStatsMode); + } - _cpuWidthChanged() { - this._cpuWidth = this._settings.get_int(CPU_WIDTH); + _diskStatsUnitMeasureChanged() { + this._diskStatsUnitMeasure = this._settings.get_string( + DISK_STATS_UNIT_MEASURE + ); - this._basicItemWidth(this._cpuWidth, this._cpuValue); - } + if (this._diskStatsStatus) { + this._refreshDiskStatsValue(); + } + } - _cpuFrequencyStatusChanged() { - this._cpuFrequencyStatus = this._settings.get_boolean(CPU_FREQUENCY_STATUS); + _diskSpaceStatusChanged() { + this._diskSpaceStatus = this._settings.get_boolean(DISK_SPACE_STATUS); - this._basicItemStatus(this._cpuFrequencyStatus, (!this._cpuStatus && !this._thermalCpuTemperatureStatus && !this._cpuLoadAverageStatus), this._cpuIcon, this._cpuFrequencyValue, this._cpuFrequencyUnit, this._cpuFrequencyValueBracket); - } + this._basicItemStatus( + this._diskSpaceStatus, + true, + this._diskSpaceIcon, + this._diskSpaceBox + ); + } - _cpuFrequencyWidthChanged() { - this._cpuFrequencyWidth = this._settings.get_int(CPU_FREQUENCY_WIDTH); + _diskSpaceWidthChanged() { + this._diskSpaceWidth = this._settings.get_int(DISK_SPACE_WIDTH); - this._basicItemWidth(this._cpuFrequencyWidth, this._cpuFrequencyValue); - } + this._diskSpaceBox.set_element_width(this._diskSpaceWidth); + } - _cpuFrequencyUnitMeasureChanged() { - this._cpuFrequencyUnitMeasure = this._settings.get_string(CPU_FREQUENCY_UNIT_MEASURE); + _diskSpaceUnitTypeChanged() { + this._diskSpaceUnitType = this._settings.get_string(DISK_SPACE_UNIT); - if (this._cpuFrequencyStatus) { - this._refreshCpuFrequencyValue(); - } - } + if (this._diskSpaceStatus) { + this._refreshDiskSpaceValue(); + } + } - _cpuLoadAverageStatusChanged() { - this._cpuLoadAverageStatus = this._settings.get_boolean(CPU_LOADAVERAGE_STATUS); + _diskSpaceUnitMeasureChanged() { + this._diskSpaceUnitMeasure = this._settings.get_string( + DISK_SPACE_UNIT_MEASURE + ); - this._basicItemStatus(this._cpuLoadAverageStatus, (!this._cpuStatus && !this._thermalCpuTemperatureStatus && !this._cpuFrequencyStatus), this._cpuIcon, this._cpuLoadAverageValue); - } + if (this._diskSpaceStatus) { + this._refreshDiskSpaceValue(); + } + } - _cpuLoadAverageWidthChanged() { - this._cpuLoadAverageWidth = this._settings.get_int(CPU_LOADAVERAGE_WIDTH); + _diskSpaceMonitorChanged() { + this._diskSpaceMonitor = this._settings.get_string(DISK_SPACE_MONITOR); - this._basicItemWidth(this._cpuLoadAverageWidth, this._cpuLoadAverageValue); - } + if (this._diskSpaceStatus) { + this._refreshDiskSpaceValue(); + } + } - _ramStatusChanged() { - this._ramStatus = this._settings.get_boolean(RAM_STATUS); + _diskDevicesListChanged() { + this._diskDevicesList = this._settings.get_strv(DISK_DEVICES_LIST); - this._basicItemStatus(this._ramStatus, true, this._ramIcon, this._ramValue, this._ramUnit); - } + this._diskStatsBox.cleanup_elements(); + this._diskSpaceBox.cleanup_elements(); - _ramWidthChanged() { - this._ramWidth = this._settings.get_int(RAM_WIDTH); + this._diskDevicesList.forEach((element) => { + const it = element.split(DISK_DEVICES_LIST_SEPARATOR); - this._basicItemWidth(this._ramWidth, this._ramValue); - } + const filesystem = it[0]; + const mountPoint = it[1]; + const stats = it[2] === "true"; + const space = it[3] === "true"; - _ramUnitTypeChanged() { - this._ramUnitType = this._settings.get_string(RAM_UNIT); + let label = ""; - if (this._ramStatus) { - this._refreshRamValue(); - } + if (filesystem.match(/(\/\w+)+/)) { + label = filesystem.split("/").pop(); + } else { + label = filesystem; } - _ramUnitMeasureChanged() { - this._ramUnitMeasure = this._settings.get_string(RAM_UNIT_MEASURE); - - if (this._ramStatus) { - this._refreshRamValue(); - } + if (stats) { + this._diskStatsBox.add_element(filesystem, label); } - _ramMonitorChanged() { - this._ramMonitor = this._settings.get_string(RAM_MONITOR); - - if (this._ramStatus) { - this._refreshRamValue(); - } + if (space) { + this._diskSpaceBox.add_element(filesystem, label); } + }); - _swapStatusChanged() { - this._swapStatus = this._settings.get_boolean(SWAP_STATUS); - - this._basicItemStatus(this._swapStatus, true, this._swapIcon, this._swapValue, this._swapUnit); - } + this._diskStatsBox.add_single(); + this._diskStatsBox.update_mode(this._diskStatsMode); - _swapWidthChanged() { - this._swapWidth = this._settings.get_int(SWAP_WIDTH); + this._diskStatsBox.set_element_width(this._diskStatsWidth); + this._diskSpaceBox.set_element_width(this._diskSpaceWidth); + } - this._basicItemWidth(this._swapWidth, this._swapValue); - } + _netAutoHideStatusChanged() { + this._netAutoHideStatus = + this._settings.get_boolean(NET_AUTO_HIDE_STATUS) && + typeof NM !== "undefined"; + + this._basicItemStatus( + (this._netEthStatus && this._nmEthStatus) || + (this._netEthStatus && !this._netAutoHideStatus), + true, + this._ethIcon, + this._ethValue, + this._ethUnit + ); + this._basicItemStatus( + (this._netWlanStatus && this._nmWlanStatus) || + (this._netWlanStatus && !this._netAutoHideStatus), + true, + this._wlanIcon, + this._wlanValue, + this._wlanUnit + ); + } - _swapUnitTypeChanged() { - this._swapUnitType = this._settings.get_string(SWAP_UNIT); + _netUnitChanged() { + this._netUnit = this._settings.get_string(NET_UNIT); - if (this._swapStatus) { - this._refreshSwapValue(); - } - } + if (this._netEthStatus) { + this._refreshEthValue(); + } + if (this._netWlanStatus) { + this._refreshWlanValue(); + } + } - _swapUnitMeasureChanged() { - this._swapUnitMeasure = this._settings.get_string(SWAP_UNIT_MEASURE); + _netUnitMeasureChanged() { + this._netUnitMeasure = this._settings.get_string(NET_UNIT_MEASURE); - if (this._swapStatus) { - this._refreshSwapValue(); - } - } + if (this._netEthStatus) { + this._refreshEthValue(); + } + if (this._netWlanStatus) { + this._refreshWlanValue(); + } + } - _swapMonitorChanged() { - this._swapMonitor = this._settings.get_string(SWAP_MONITOR); + _netEthStatusChanged() { + this._netEthStatus = this._settings.get_boolean(NET_ETH_STATUS); + + this._basicItemStatus( + (this._netEthStatus && this._nmEthStatus) || + (this._netEthStatus && !this._netAutoHideStatus), + true, + this._ethIcon, + this._ethValue, + this._ethUnit + ); + } - if (this._swapStatus) { - this._refreshSwapValue(); - } - } + _netEthWidthChanged() { + this._netEthWidth = this._settings.get_int(NET_ETH_WIDTH); - _diskStatsStatusChanged() { - this._diskStatsStatus = this._settings.get_boolean(DISK_STATS_STATUS); + this._basicItemWidth(this._netEthWidth, this._ethValue); + } - this._basicItemStatus(this._diskStatsStatus, true, this._diskStatsIcon, this._diskStatsBox); - } + _netWlanStatusChanged() { + this._netWlanStatus = this._settings.get_boolean(NET_WLAN_STATUS); + + this._basicItemStatus( + (this._netWlanStatus && this._nmWlanStatus) || + (this._netWlanStatus && !this._netAutoHideStatus), + true, + this._wlanIcon, + this._wlanValue, + this._wlanUnit + ); + } - _diskStatsWidthChanged() { - this._diskStatsWidth = this._settings.get_int(DISK_STATS_WIDTH); + _netWlanWidthChanged() { + this._netWlanWidth = this._settings.get_int(NET_WLAN_WIDTH); - this._diskStatsBox.set_element_width(this._diskStatsWidth); - } + this._basicItemWidth(this._netWlanWidth, this._wlanValue); + } - _diskStatsModeChanged() { - this._diskStatsMode = this._settings.get_string(DISK_STATS_MODE); + _thermalCpuTemperatureStatusChanged() { + this._thermalCpuTemperatureStatus = this._settings.get_boolean( + THERMAL_CPU_TEMPERATURE_STATUS + ); + + this._basicItemStatus( + this._thermalCpuTemperatureStatus, + !this._cpuStatus && + !this._cpuFrequencyStatus && + !this._cpuLoadAverageStatus, + this._cpuIcon, + this._cpuTemperatureValue, + this._cpuTemperatureUnit, + this._cpuTemperatureValueBracket + ); + } - this._diskStatsBox.update_mode(this._diskStatsMode); - } + _thermalCpuTemperatureWidthChanged() { + this._thermalCpuTemperatureWidth = this._settings.get_int( + THERMAL_CPU_TEMPERATURE_WIDTH + ); - _diskStatsUnitMeasureChanged() { - this._diskStatsUnitMeasure = this._settings.get_string(DISK_STATS_UNIT_MEASURE); + this._basicItemWidth( + this._thermalCpuTemperatureWidth, + this._cpuTemperatureValue + ); + } - if (this._diskStatsStatus) { - this._refreshDiskStatsValue(); - } - } + _thermalTemperatureUnitChanged() { + this._thermalTemperatureUnit = this._settings.get_string( + THERMAL_TEMPERATURE_UNIT + ); - _diskSpaceStatusChanged() { - this._diskSpaceStatus = this._settings.get_boolean(DISK_SPACE_STATUS); + if (this._thermalCpuTemperatureStatus) { + this._refreshCpuTemperatureValue(); + } + } - this._basicItemStatus(this._diskSpaceStatus, true, this._diskSpaceIcon, this._diskSpaceBox); - } + _thermalCpuTemperatureDevicesListChanged() { + this._thermalCpuTemperatureDevicesList = this._settings.get_strv( + THERMAL_CPU_TEMPERATURE_DEVICES_LIST + ); - _diskSpaceWidthChanged() { - this._diskSpaceWidth = this._settings.get_int(DISK_SPACE_WIDTH); + if (this._thermalCpuTemperatureStatus) { + this._refreshCpuTemperatureValue(); + } + } - this._diskSpaceBox.set_element_width(this._diskSpaceWidth); - } + _thermalGpuTemperatureStatusChanged() { + this._thermalGpuTemperatureStatus = this._settings.get_boolean( + THERMAL_GPU_TEMPERATURE_STATUS + ); + + this._basicItemStatus( + this._gpuStatus || this._thermalGpuTemperatureStatus, + !this._gpuStatus, + this._gpuIcon, + this._gpuBox + ); + this._gpuDevicesListChanged(); + } - _diskSpaceUnitTypeChanged() { - this._diskSpaceUnitType = this._settings.get_string(DISK_SPACE_UNIT); + _thermalGpuTemperatureWidthChanged() { + this._thermalGpuTemperatureWidth = this._settings.get_int( + THERMAL_GPU_TEMPERATURE_WIDTH + ); - if (this._diskSpaceStatus) { - this._refreshDiskSpaceValue(); - } - } + this._gpuBox.set_element_thermal_width(this._thermalGpuTemperatureWidth); + } - _diskSpaceUnitMeasureChanged() { - this._diskSpaceUnitMeasure = this._settings.get_string(DISK_SPACE_UNIT_MEASURE); + _thermalGpuTemperatureDevicesListChanged() { + this._thermalGpuTemperatureDevicesList = this._settings.get_strv( + THERMAL_GPU_TEMPERATURE_DEVICES_LIST + ); - if (this._diskSpaceStatus) { - this._refreshDiskSpaceValue(); - } - } + this._gpuDevicesListChanged(); + } - _diskSpaceMonitorChanged() { - this._diskSpaceMonitor = this._settings.get_string(DISK_SPACE_MONITOR); + _gpuStatusChanged() { + this._gpuStatus = this._settings.get_boolean(GPU_STATUS); - if (this._diskSpaceStatus) { - this._refreshDiskSpaceValue(); - } - } + this._basicItemStatus( + this._gpuStatus || this._thermalGpuTemperatureStatus, + !this._thermalGpuTemperatureStatus, + this._gpuIcon, + this._gpuBox + ); + this._gpuDevicesListChanged(); + } - _diskDevicesListChanged() { - this._diskDevicesList = this._settings.get_strv(DISK_DEVICES_LIST); + _gpuWidthChanged() { + this._gpuWidth = this._settings.get_int(GPU_WIDTH); - this._diskStatsBox.cleanup_elements(); - this._diskSpaceBox.cleanup_elements(); + this._gpuBox.set_element_width(this._gpuWidth); + } - this._diskDevicesList.forEach(element => { - const it = element.split(DISK_DEVICES_LIST_SEPARATOR); + _gpuMemoryUnitTypeChanged() { + this._gpuMemoryUnitType = this._settings.get_string(GPU_MEMORY_UNIT); - const filesystem = it[0]; - const mountPoint = it[1]; - const stats = (it[2] === 'true'); - const space = (it[3] === 'true'); + if (this._gpuStatus) { + this._refreshGpuValue(); + } + } - let label = ''; + _gpuMemoryUnitMeasureChanged() { + this._gpuMemoryUnitMeasure = this._settings.get_string( + GPU_MEMORY_UNIT_MEASURE + ); - if (filesystem.match(/(\/\w+)+/)) { - label = filesystem.split('/').pop(); - } else { - label = filesystem; - } + if (this._gpuStatus) { + this._refreshGpuValue(); + } + } - if (stats) { - this._diskStatsBox.add_element(filesystem, label); - } + _gpuMemoryMonitorChanged() { + this._gpuMemoryMonitor = this._settings.get_string(GPU_MEMORY_MONITOR); - if (space) { - this._diskSpaceBox.add_element(filesystem, label); - } - }); + if (this._gpuStatus) { + this._refreshGpuValue(); + } + } - this._diskStatsBox.add_single(); - this._diskStatsBox.update_mode(this._diskStatsMode); + _gpuDisplayDeviceNameChanged() { + this._gpuDisplayDeviceName = this._settings.get_boolean( + GPU_DISPLAY_DEVICE_NAME + ); - this._diskStatsBox.set_element_width(this._diskStatsWidth); - this._diskSpaceBox.set_element_width(this._diskSpaceWidth); - } + this._gpuDevicesListChanged(); + } - _netAutoHideStatusChanged() { - this._netAutoHideStatus = this._settings.get_boolean(NET_AUTO_HIDE_STATUS) && typeof NM !== 'undefined'; + _gpuDevicesListChanged() { + this._gpuDevicesList = this._settings.get_strv(GPU_DEVICES_LIST); - this._basicItemStatus((this._netEthStatus && this._nmEthStatus) || (this._netEthStatus && !this._netAutoHideStatus), true, this._ethIcon, this._ethValue, this._ethUnit); - this._basicItemStatus((this._netWlanStatus && this._nmWlanStatus) || (this._netWlanStatus && !this._netAutoHideStatus), true, this._wlanIcon, this._wlanValue, this._wlanUnit); - } + this._gpuBox.cleanup_elements(); - _netUnitChanged() { - this._netUnit = this._settings.get_string(NET_UNIT); + this._gpuDevicesList.forEach((element) => { + const it = element.split(GPU_DEVICES_LIST_SEPARATOR); - if (this._netEthStatus) { - this._refreshEthValue(); - } - if (this._netWlanStatus) { - this._refreshWlanValue(); - } - } + const uuid = it[0]; + const name = this._gpuDisplayDeviceName ? it[1] : null; + const usage = it[2] === "true" && this._gpuStatus; + const memory = it[3] === "true" && this._gpuStatus; + let thermal = false; - _netUnitMeasureChanged() { - this._netUnitMeasure = this._settings.get_string(NET_UNIT_MEASURE); + if (this._thermalGpuTemperatureStatus) { + this._thermalGpuTemperatureDevicesList.forEach((element) => { + const it = element.split(GPU_DEVICES_LIST_SEPARATOR); - if (this._netEthStatus) { - this._refreshEthValue(); - } - if (this._netWlanStatus) { - this._refreshWlanValue(); + if (uuid === it[0]) { + thermal = it[2] === "true"; } + }); } - _netEthStatusChanged() { - this._netEthStatus = this._settings.get_boolean(NET_ETH_STATUS); + this._gpuBox.add_element(uuid, name, usage, memory, thermal); + }); - this._basicItemStatus((this._netEthStatus && this._nmEthStatus) || (this._netEthStatus && !this._netAutoHideStatus), true, this._ethIcon, this._ethValue, this._ethUnit); - } + this._gpuBox.set_element_width(this._gpuWidth); + } - _netEthWidthChanged() { - this._netEthWidth = this._settings.get_int(NET_ETH_WIDTH); + _refreshHandler() { + if (this._cpuStatus) { + this._refreshCpuValue(); + } + if (this._ramStatus) { + this._refreshRamValue(); + } + if (this._swapStatus) { + this._refreshSwapValue(); + } + if (this._diskStatsStatus) { + this._refreshDiskStatsValue(); + } + if (this._diskSpaceStatus) { + this._refreshDiskSpaceValue(); + } + if (this._netEthStatus) { + this._refreshEthValue(); + } + if (this._netWlanStatus) { + this._refreshWlanValue(); + } + if (this._cpuFrequencyStatus) { + this._refreshCpuFrequencyValue(); + } + if (this._cpuLoadAverageStatus) { + this._refreshCpuLoadAverageValue(); + } + if (this._thermalCpuTemperatureStatus) { + this._refreshCpuTemperatureValue(); + } + if (this._gpuStatus || this._thermalGpuTemperatureStatus) { + this._refreshGpuValue(); + } + + return GLib.SOURCE_CONTINUE; + } - this._basicItemWidth(this._netEthWidth, this._ethValue); - } + _refreshGui() { + //this._onActiveConnectionAdded(client, activeConnection); - _netWlanStatusChanged() { - this._netWlanStatus = this._settings.get_boolean(NET_WLAN_STATUS); + //this._onActiveConnectionRemoved(client, activeConnection); - this._basicItemStatus((this._netWlanStatus && this._nmWlanStatus) || (this._netWlanStatus && !this._netAutoHideStatus), true, this._wlanIcon, this._wlanValue, this._wlanUnit); - } + //this._refreshTimeChanged(); - _netWlanWidthChanged() { - this._netWlanWidth = this._settings.get_int(NET_WLAN_WIDTH); + //this._decimalsStatusChanged(); - this._basicItemWidth(this._netWlanWidth, this._wlanValue); - } + //this._leftClickStatusChanged(); - _thermalCpuTemperatureStatusChanged() { - this._thermalCpuTemperatureStatus = this._settings.get_boolean(THERMAL_CPU_TEMPERATURE_STATUS); + this._rightClickStatusChanged(); - this._basicItemStatus(this._thermalCpuTemperatureStatus, (!this._cpuStatus && !this._cpuFrequencyStatus && !this._cpuLoadAverageStatus), this._cpuIcon, this._cpuTemperatureValue, this._cpuTemperatureUnit, this._cpuTemperatureValueBracket); - } + this._iconsStatusChanged(); - _thermalCpuTemperatureWidthChanged() { - this._thermalCpuTemperatureWidth = this._settings.get_int(THERMAL_CPU_TEMPERATURE_WIDTH); + //this._iconsPositionChanged(); - this._basicItemWidth(this._thermalCpuTemperatureWidth, this._cpuTemperatureValue); - } + //this._itemsPositionChanged(); - _thermalTemperatureUnitChanged() { - this._thermalTemperatureUnit = this._settings.get_string(THERMAL_TEMPERATURE_UNIT); + this._cpuStatusChanged(); - if (this._thermalCpuTemperatureStatus) { - this._refreshCpuTemperatureValue(); - } - } + this._cpuWidthChanged(); - _thermalCpuTemperatureDevicesListChanged() { - this._thermalCpuTemperatureDevicesList = this._settings.get_strv(THERMAL_CPU_TEMPERATURE_DEVICES_LIST); + this._cpuFrequencyStatusChanged(); - if (this._thermalCpuTemperatureStatus) { - this._refreshCpuTemperatureValue(); - } - } + this._cpuFrequencyWidthChanged(); - _thermalGpuTemperatureStatusChanged() { - this._thermalGpuTemperatureStatus = this._settings.get_boolean(THERMAL_GPU_TEMPERATURE_STATUS); + //this._cpuFrequencyUnitMeasureChanged(); - this._basicItemStatus((this._gpuStatus || this._thermalGpuTemperatureStatus), !this._gpuStatus, this._gpuIcon, this._gpuBox); - this._gpuDevicesListChanged(); - } + this._cpuLoadAverageStatusChanged(); - _thermalGpuTemperatureWidthChanged() { - this._thermalGpuTemperatureWidth = this._settings.get_int(THERMAL_GPU_TEMPERATURE_WIDTH); + this._cpuLoadAverageWidthChanged(); - this._gpuBox.set_element_thermal_width(this._thermalGpuTemperatureWidth); - } + this._ramStatusChanged(); - _thermalGpuTemperatureDevicesListChanged() { - this._thermalGpuTemperatureDevicesList = this._settings.get_strv(THERMAL_GPU_TEMPERATURE_DEVICES_LIST); + this._ramWidthChanged(); - this._gpuDevicesListChanged(); - } + //this._ramUnitTypeChanged(); - _gpuStatusChanged() { - this._gpuStatus = this._settings.get_boolean(GPU_STATUS); + //this._ramUnitMeasureChanged(); - this._basicItemStatus((this._gpuStatus || this._thermalGpuTemperatureStatus), !this._thermalGpuTemperatureStatus, this._gpuIcon, this._gpuBox); - this._gpuDevicesListChanged(); - } + //this._ramMonitorChanged(); - _gpuWidthChanged() { - this._gpuWidth = this._settings.get_int(GPU_WIDTH); + this._swapStatusChanged(); - this._gpuBox.set_element_width(this._gpuWidth); - } + this._swapWidthChanged(); - _gpuMemoryUnitTypeChanged() { - this._gpuMemoryUnitType = this._settings.get_string(GPU_MEMORY_UNIT); + //this._swapUnitTypeChanged(); - if (this._gpuStatus) { - this._refreshGpuValue(); - } - } + //this._swapUnitMeasureChanged(); - _gpuMemoryUnitMeasureChanged() { - this._gpuMemoryUnitMeasure = this._settings.get_string(GPU_MEMORY_UNIT_MEASURE); + //this._swapMonitorChanged(); - if (this._gpuStatus) { - this._refreshGpuValue(); - } - } + this._diskStatsStatusChanged(); - _gpuMemoryMonitorChanged() { - this._gpuMemoryMonitor = this._settings.get_string(GPU_MEMORY_MONITOR); + this._diskStatsWidthChanged(); - if (this._gpuStatus) { - this._refreshGpuValue(); - } - } + this._diskStatsModeChanged(); - _gpuDisplayDeviceNameChanged() { - this._gpuDisplayDeviceName = this._settings.get_boolean(GPU_DISPLAY_DEVICE_NAME); + //this._diskStatsUnitMeasureChanged(); - this._gpuDevicesListChanged(); - } + this._diskSpaceStatusChanged(); - _gpuDevicesListChanged() { - this._gpuDevicesList = this._settings.get_strv(GPU_DEVICES_LIST); + this._diskSpaceWidthChanged(); - this._gpuBox.cleanup_elements(); + //this._diskSpaceUnitTypeChanged(); - this._gpuDevicesList.forEach(element => { - const it = element.split(GPU_DEVICES_LIST_SEPARATOR); + //this._diskSpaceUnitMeasureChanged(); - const uuid = it[0]; - const name = this._gpuDisplayDeviceName ? it[1] : null; - const usage = (it[2] === 'true') && this._gpuStatus; - const memory = (it[3] === 'true') && this._gpuStatus; - let thermal = false; + //this._diskSpaceMonitorChanged(); - if (this._thermalGpuTemperatureStatus) { - this._thermalGpuTemperatureDevicesList.forEach(element => { - const it = element.split(GPU_DEVICES_LIST_SEPARATOR); + this._diskDevicesListChanged(); - if (uuid === it[0]) { - thermal = (it[2] === 'true'); - } - }); - } + //this._netAutoHideStatusChanged(); - this._gpuBox.add_element(uuid, name, usage, memory, thermal); - }); + //this._netUnitChanged(); - this._gpuBox.set_element_width(this._gpuWidth); - } + //this._netUnitMeasureChanged(); - _refreshHandler() { - if (this._cpuStatus) { - this._refreshCpuValue(); - } - if (this._ramStatus) { - this._refreshRamValue(); - } - if (this._swapStatus) { - this._refreshSwapValue(); - } - if (this._diskStatsStatus) { - this._refreshDiskStatsValue(); - } - if (this._diskSpaceStatus) { - this._refreshDiskSpaceValue(); - } - if (this._netEthStatus) { - this._refreshEthValue(); - } - if (this._netWlanStatus) { - this._refreshWlanValue(); - } - if (this._cpuFrequencyStatus) { - this._refreshCpuFrequencyValue(); - } - if (this._cpuLoadAverageStatus) { - this._refreshCpuLoadAverageValue(); - } - if (this._thermalCpuTemperatureStatus) { - this._refreshCpuTemperatureValue(); - } - if (this._gpuStatus || this._thermalGpuTemperatureStatus) { - this._refreshGpuValue(); - } + this._netEthStatusChanged(); - return GLib.SOURCE_CONTINUE; - } + this._netEthWidthChanged(); - _refreshGui() { - //this._onActiveConnectionAdded(client, activeConnection); + this._netWlanStatusChanged(); - //this._onActiveConnectionRemoved(client, activeConnection); + this._netWlanWidthChanged(); - //this._refreshTimeChanged(); + this._thermalCpuTemperatureStatusChanged(); - //this._decimalsStatusChanged(); + this._thermalCpuTemperatureWidthChanged(); - //this._leftClickStatusChanged(); + //this._thermalCpuTemperatureUnitChanged(); - this._rightClickStatusChanged(); + //this._thermalCpuTemperatureDevicesListChanged(); - this._iconsStatusChanged(); + this._thermalGpuTemperatureStatusChanged(); - //this._iconsPositionChanged(); + this._thermalGpuTemperatureWidthChanged(); - //this._itemsPositionChanged(); + //this._thermalGpuTemperatureDevicesListChanged(); - this._cpuStatusChanged(); + this._gpuStatusChanged(); - this._cpuWidthChanged(); + this._gpuWidthChanged(); - this._cpuFrequencyStatusChanged(); + //this._gpuMemoryUnitTypeChanged(); - this._cpuFrequencyWidthChanged(); + //this._gpuMemoryUnitMeasureChanged(); - //this._cpuFrequencyUnitMeasureChanged(); + //this._gpuMemoryMonitorChanged(); - this._cpuLoadAverageStatusChanged(); + //this._gpuDisplayDeviceNameChanged(); - this._cpuLoadAverageWidthChanged(); + this._gpuDevicesListChanged(); + } - this._ramStatusChanged(); + _refreshCpuValue() { + this._loadFile("/proc/stat").then((contents) => { + const lines = new TextDecoder().decode(contents).split("\n"); - this._ramWidthChanged(); + const entry = lines[0].trim().split(/\s+/); + let cpuTot = 0; + const idle = parseInt(entry[4]); - //this._ramUnitTypeChanged(); + // user sys nice idle iowait + for (let i = 1; i < 5; i++) cpuTot += parseInt(entry[i]); - //this._ramUnitMeasureChanged(); + const delta = cpuTot - this._cpuTotOld; + const deltaIdle = idle - this._cpuIdleOld; - //this._ramMonitorChanged(); + const cpuCurr = (100 * (delta - deltaIdle)) / delta; - this._swapStatusChanged(); + this._cpuTotOld = cpuTot; + this._cpuIdleOld = idle; - this._swapWidthChanged(); + if (this._decimalsStatus) { + this._cpuValue.text = `${cpuCurr.toFixed(1)}`; + } else { + this._cpuValue.text = `${cpuCurr.toFixed(0)}`; + } + }); + } - //this._swapUnitTypeChanged(); + _refreshRamValue() { + this._loadFile("/proc/meminfo").then((contents) => { + const lines = new TextDecoder().decode(contents).split("\n"); - //this._swapUnitMeasureChanged(); + let total, available, used; - //this._swapMonitorChanged(); + for (let i = 0; i < 3; i++) { + const line = lines[i]; + let values; - this._diskStatsStatusChanged(); + if (line.match(/^MemTotal/)) { + values = line.match(/^MemTotal:\s*([^ ]*)\s*([^ ]*)$/); + total = parseInt(values[1]); + } else if (line.match(/^MemAvailable/)) { + values = line.match(/^MemAvailable:\s*([^ ]*)\s*([^ ]*)$/); + available = parseInt(values[1]); + } + } - this._diskStatsWidthChanged(); + used = total - available; - this._diskStatsModeChanged(); + let value = 0; + let unit = "KB"; + switch (this._ramMonitor) { + case "free": + value = available; - //this._diskStatsUnitMeasureChanged(); + break; - this._diskSpaceStatusChanged(); + case "used": - this._diskSpaceWidthChanged(); + default: + value = used; - //this._diskSpaceUnitTypeChanged(); + break; + } - //this._diskSpaceUnitMeasureChanged(); + switch (this._ramUnitType) { + case "perc": + if (this._decimalsStatus) { + this._ramValue.text = `${((100 * value) / total).toFixed(1)}`; + } else { + this._ramValue.text = `${((100 * value) / total).toFixed(0)}`; + } - //this._diskSpaceMonitorChanged(); + this._ramUnit.text = "%"; + + break; + + case "numeric": + + default: + switch (this._ramUnitMeasure) { + case "k": + unit = "KB"; + break; + + case "m": + unit = "MB"; + value /= 1000; + break; + + case "g": + unit = "GB"; + value /= 1000; + value /= 1000; + break; + + case "t": + unit = "TB"; + value /= 1000; + value /= 1000; + value /= 1000; + break; + + case "auto": + + default: + if (value > 1000) { + unit = "MB"; + value /= 1000; + if (value > 1000) { + unit = "GB"; + value /= 1000; + if (value > 1000) { + unit = "TB"; + value /= 1000; + } + } + } else { + unit = "KB"; + } - this._diskDevicesListChanged(); + break; + } - //this._netAutoHideStatusChanged(); + if (this._decimalsStatus) { + this._ramValue.text = `${value.toFixed(1)}`; + } else { + this._ramValue.text = `${value.toFixed(0)}`; + } - //this._netUnitChanged(); + this._ramUnit.text = unit; - //this._netUnitMeasureChanged(); + break; + } + }); + } - this._netEthStatusChanged(); + _refreshSwapValue() { + this._loadFile("/proc/meminfo").then((contents) => { + const lines = new TextDecoder().decode(contents).split("\n"); - this._netEthWidthChanged(); + let total, available, used; - this._netWlanStatusChanged(); + for (let i = 0; i < 16; i++) { + const line = lines[i]; + let values; - this._netWlanWidthChanged(); + if (line.match(/^SwapTotal/)) { + values = line.match(/^SwapTotal:\s*([^ ]*)\s*([^ ]*)$/); + total = parseInt(values[1]); + } else if (line.match(/^SwapFree/)) { + values = line.match(/^SwapFree:\s*([^ ]*)\s*([^ ]*)$/); + available = parseInt(values[1]); + } + } - this._thermalCpuTemperatureStatusChanged(); + used = total - available; - this._thermalCpuTemperatureWidthChanged(); + let value = 0; + let unit = "KB"; + switch (this._swapMonitor) { + case "free": + value = available; - //this._thermalCpuTemperatureUnitChanged(); + break; - //this._thermalCpuTemperatureDevicesListChanged(); + case "used": - this._thermalGpuTemperatureStatusChanged(); + default: + value = used; - this._thermalGpuTemperatureWidthChanged(); + break; + } - //this._thermalGpuTemperatureDevicesListChanged(); - - this._gpuStatusChanged(); - - this._gpuWidthChanged(); - - //this._gpuMemoryUnitTypeChanged(); - - //this._gpuMemoryUnitMeasureChanged(); - - //this._gpuMemoryMonitorChanged(); - - //this._gpuDisplayDeviceNameChanged(); - - this._gpuDevicesListChanged(); - } - - _refreshCpuValue() { - this._loadFile('/proc/stat').then(contents => { - const lines = ByteArray.toString(contents).split('\n'); - - const entry = lines[0].trim().split(/\s+/); - let cpuTot = 0; - const idle = parseInt(entry[4]); - - // user sys nice idle iowait - for (let i = 1; i < 5; i++) - cpuTot += parseInt(entry[i]); - - const delta = cpuTot - this._cpuTotOld; - const deltaIdle = idle - this._cpuIdleOld; - - const cpuCurr = 100 * (delta - deltaIdle) / delta; - - this._cpuTotOld = cpuTot; - this._cpuIdleOld = idle; - - if (this._decimalsStatus) { - this._cpuValue.text = `${cpuCurr.toFixed(1)}`; - } else { - this._cpuValue.text = `${cpuCurr.toFixed(0)}`; - } - }); - } - - _refreshRamValue() { - this._loadFile('/proc/meminfo').then(contents => { - const lines = ByteArray.toString(contents).split('\n'); - - let total, available, used; - - for (let i = 0; i < 3; i++) { - const line = lines[i]; - let values; + switch (this._swapUnitType) { + case "perc": + if (this._decimalsStatus) { + this._swapValue.text = `${((100 * value) / total).toFixed(1)}`; + } else { + this._swapValue.text = `${((100 * value) / total).toFixed(0)}`; + } - if (line.match(/^MemTotal/)) { - values = line.match(/^MemTotal:\s*([^ ]*)\s*([^ ]*)$/); - total = parseInt(values[1]); - } else if (line.match(/^MemAvailable/)) { - values = line.match(/^MemAvailable:\s*([^ ]*)\s*([^ ]*)$/); - available = parseInt(values[1]); + this._swapUnit.text = "%"; + + break; + + case "numeric": + + default: + switch (this._swapUnitMeasure) { + case "k": + unit = "KB"; + break; + + case "m": + unit = "MB"; + value /= 1000; + break; + + case "g": + unit = "GB"; + value /= 1000; + value /= 1000; + break; + + case "t": + unit = "TB"; + value /= 1000; + value /= 1000; + value /= 1000; + break; + + case "auto": + + default: + if (value > 1000) { + unit = "MB"; + value /= 1000; + if (value > 1000) { + unit = "GB"; + value /= 1000; + if (value > 1000) { + unit = "TB"; + value /= 1000; } + } + } else { + unit = "KB"; } - used = total - available; - - let value = 0; - let unit = 'KB'; - switch (this._ramMonitor) { - case 'free': - value = available; - - break; - - case 'used': - - default: - value = used; - - break; - } - - switch (this._ramUnitType) { - case 'perc': - if (this._decimalsStatus) { - this._ramValue.text = `${(100 * value / total).toFixed(1)}`; - } else { - this._ramValue.text = `${(100 * value / total).toFixed(0)}`; - } - - this._ramUnit.text = '%'; - - break; - - case 'numeric': - - default: - switch (this._ramUnitMeasure) { - case 'k': - unit = 'KB'; - break; - - case 'm': - unit = 'MB'; - value /= 1000; - break; - - case 'g': - unit = 'GB'; - value /= 1000; - value /= 1000; - break; - - case 't': - unit = 'TB'; - value /= 1000; - value /= 1000; - value /= 1000; - break; - - case 'auto': - - default: - if (value > 1000) { - unit = 'MB'; - value /= 1000; - if (value > 1000) { - unit = 'GB'; - value /= 1000; - if (value > 1000) { - unit = 'TB'; - value /= 1000; - } - } - } else { - unit = 'KB'; - } - - break; - } + break; + } - if (this._decimalsStatus) { - this._ramValue.text = `${value.toFixed(1)}`; - } else { - this._ramValue.text = `${value.toFixed(0)}`; - } + if (this._decimalsStatus) { + this._swapValue.text = `${value.toFixed(1)}`; + } else { + this._swapValue.text = `${value.toFixed(0)}`; + } - this._ramUnit.text = unit; + this._swapUnit.text = unit; - break; - } - }); + break; } + }); + } - _refreshSwapValue() { - this._loadFile('/proc/meminfo').then(contents => { - const lines = ByteArray.toString(contents).split('\n'); - - let total, available, used; - - for (let i = 0; i < 16; i++) { - const line = lines[i]; - let values; - - if (line.match(/^SwapTotal/)) { - values = line.match(/^SwapTotal:\s*([^ ]*)\s*([^ ]*)$/); - total = parseInt(values[1]); - } else if (line.match(/^SwapFree/)) { - values = line.match(/^SwapFree:\s*([^ ]*)\s*([^ ]*)$/); - available = parseInt(values[1]); - } - } - - used = total - available; - - let value = 0; - let unit = 'KB'; - switch (this._swapMonitor) { - case 'free': - value = available; - - break; - - case 'used': - - default: - value = used; + _refreshDiskStatsValue() { + this._loadFile("/proc/diskstats").then((contents) => { + const lines = new TextDecoder().decode(contents).split("\n"); - break; - } + switch (this._diskStatsMode) { + case "single": + let rwTot = [0, 0]; + let rw = [0, 0]; - switch (this._swapUnitType) { - case 'perc': - if (this._decimalsStatus) { - this._swapValue.text = `${(100 * value / total).toFixed(1)}`; - } else { - this._swapValue.text = `${(100 * value / total).toFixed(0)}`; - } + const filesystem = "single"; - this._swapUnit.text = '%'; + for (let i = 0; i < lines.length - 1; i++) { + const line = lines[i]; + const entry = line.trim().split(/\s+/); - break; + if (entry[2].match(/loop*/)) { + continue; + } - case 'numeric': + // Found + if (this._diskStatsBox.get_filesystem(entry[2])) { + rwTot[0] += parseInt(entry[5]); + rwTot[1] += parseInt(entry[9]); - default: - switch (this._swapUnitMeasure) { - case 'k': - unit = 'KB'; - break; - - case 'm': - unit = 'MB'; - value /= 1000; - break; - - case 'g': - unit = 'GB'; - value /= 1000; - value /= 1000; - break; - - case 't': - unit = 'TB'; - value /= 1000; - value /= 1000; - value /= 1000; - break; - - case 'auto': - - default: - if (value > 1000) { - unit = 'MB'; - value /= 1000; - if (value > 1000) { - unit = 'GB'; - value /= 1000; - if (value > 1000) { - unit = 'TB'; - value /= 1000; - } - } - } else { - unit = 'KB'; - } - - break; - } + // sector is 512 bytes + // 1 kilobyte = 2 sectors + rwTot[0] /= 2; + rwTot[1] /= 2; + } + } - if (this._decimalsStatus) { - this._swapValue.text = `${value.toFixed(1)}`; - } else { - this._swapValue.text = `${value.toFixed(0)}`; - } + const idle = GLib.get_monotonic_time() / 1000; + const delta = + (idle - this._diskStatsBox.get_idle(filesystem)) / 1000; + this._diskStatsBox.set_idle(filesystem, idle); + + let unit = ""; + + if (delta > 0) { + const rwTotOld = this._diskStatsBox.get_rw_tot(filesystem); + for (let i = 0; i < 2; i++) { + rw[i] = (rwTot[i] - rwTotOld[i]) / delta; + } + this._diskStatsBox.set_rw_tot(filesystem, rwTot); + + switch (this._diskStatsUnitMeasure) { + case "k": + unit = "K"; + break; + + case "m": + unit = "M"; + rw[0] /= 1024; + rw[1] /= 1024; + break; + + case "g": + unit = "G"; + rw[0] /= 1024; + rw[1] /= 1024; + rw[0] /= 1024; + rw[1] /= 1024; + break; + + case "t": + unit = "T"; + rw[0] /= 1024; + rw[1] /= 1024; + rw[0] /= 1024; + rw[1] /= 1024; + rw[0] /= 1024; + rw[1] /= 1024; + break; + + case "auto": - this._swapUnit.text = unit; + default: + if (rw[0] > 1024 || rw[1] > 1024) { + unit = "M"; + rw[0] /= 1024; + rw[1] /= 1024; + if (rw[0] > 1024 || rw[1] > 1024) { + unit = "G"; + rw[0] /= 1024; + rw[1] /= 1024; + if (rw[0] > 1024 || rw[1] > 1024) { + unit = "T"; + rw[0] /= 1024; + rw[1] /= 1024; + } + } + } else { + unit = "K"; + } - break; - } - }); - } + break; + } + } - _refreshDiskStatsValue() { - this._loadFile('/proc/diskstats').then(contents => { - const lines = ByteArray.toString(contents).split('\n'); + if (this._decimalsStatus) { + this._diskStatsBox.update_element_value( + filesystem, + `${rw[0].toFixed(1)}|${rw[1].toFixed(1)}`, + unit + ); + } else { + this._diskStatsBox.update_element_value( + filesystem, + `${rw[0].toFixed(0)}|${rw[1].toFixed(0)}`, + unit + ); + } - switch (this._diskStatsMode) { - case 'single': - let rwTot = [0, 0]; - let rw = [0, 0]; + break; - const filesystem = 'single'; + case "multiple": - for (let i = 0; i < lines.length - 1; i++) { - const line = lines[i]; - const entry = line.trim().split(/\s+/); + default: + for (let i = 0; i < lines.length - 1; i++) { + const line = lines[i]; + const entry = line.trim().split(/\s+/); - if (entry[2].match(/loop*/)) { - continue; - } + if (entry[2].match(/loop*/)) { + continue; + } - // Found - if (this._diskStatsBox.get_filesystem(entry[2])) { - rwTot[0] += parseInt(entry[5]); - rwTot[1] += parseInt(entry[9]); + const filesystem = this._diskStatsBox.get_filesystem(entry[2]); + // Found + if (filesystem) { + let rwTot = [0, 0]; + let rw = [0, 0]; - // sector is 512 bytes - // 1 kilobyte = 2 sectors - rwTot[0] /= 2; - rwTot[1] /= 2; - } - } + rwTot[0] += parseInt(entry[5]); + rwTot[1] += parseInt(entry[9]); - const idle = GLib.get_monotonic_time() / 1000; - const delta = (idle - this._diskStatsBox.get_idle(filesystem)) / 1000; - this._diskStatsBox.set_idle(filesystem, idle); - - let unit = ''; - - if (delta > 0) { - const rwTotOld = this._diskStatsBox.get_rw_tot(filesystem); - for (let i = 0; i < 2; i++) { - rw[i] = (rwTot[i] - rwTotOld[i]) / delta; - } - this._diskStatsBox.set_rw_tot(filesystem, rwTot); - - switch (this._diskStatsUnitMeasure) { - case 'k': - unit = 'K'; - break; - - case 'm': - unit = 'M'; - rw[0] /= 1024; - rw[1] /= 1024; - break; - - case 'g': - unit = 'G'; - rw[0] /= 1024; - rw[1] /= 1024; - rw[0] /= 1024; - rw[1] /= 1024; - break; - - case 't': - unit = 'T'; - rw[0] /= 1024; - rw[1] /= 1024; - rw[0] /= 1024; - rw[1] /= 1024; - rw[0] /= 1024; - rw[1] /= 1024; - break; - - case 'auto': - - default: - if (rw[0] > 1024 || rw[1] > 1024) { - unit = 'M'; - rw[0] /= 1024; - rw[1] /= 1024; - if (rw[0] > 1024 || rw[1] > 1024) { - unit = 'G'; - rw[0] /= 1024; - rw[1] /= 1024; - if (rw[0] > 1024 || rw[1] > 1024) { - unit = 'T'; - rw[0] /= 1024; - rw[1] /= 1024; - } - } - } else { - unit = 'K'; - } - - break; - } - } + // sector is 512 bytes + // 1 kilobyte = 2 sectors + rwTot[0] /= 2; + rwTot[1] /= 2; - if (this._decimalsStatus) { - this._diskStatsBox.update_element_value(filesystem, `${rw[0].toFixed(1)}|${rw[1].toFixed(1)}`, unit); - } else { - this._diskStatsBox.update_element_value(filesystem, `${rw[0].toFixed(0)}|${rw[1].toFixed(0)}`, unit); - } + const idle = GLib.get_monotonic_time() / 1000; + const delta = + (idle - this._diskStatsBox.get_idle(filesystem)) / 1000; + this._diskStatsBox.set_idle(filesystem, idle); - break; + let unit = ""; - case 'multiple': + if (delta > 0) { + const rwTotOld = this._diskStatsBox.get_rw_tot(filesystem); + for (let i = 0; i < 2; i++) { + rw[i] = (rwTot[i] - rwTotOld[i]) / delta; + } + this._diskStatsBox.set_rw_tot(filesystem, rwTot); + + switch (this._diskStatsUnitMeasure) { + case "k": + unit = "K"; + break; + + case "m": + unit = "M"; + rw[0] /= 1024; + rw[1] /= 1024; + break; + + case "g": + unit = "G"; + rw[0] /= 1024; + rw[1] /= 1024; + rw[0] /= 1024; + rw[1] /= 1024; + break; + + case "t": + unit = "T"; + rw[0] /= 1024; + rw[1] /= 1024; + rw[0] /= 1024; + rw[1] /= 1024; + rw[0] /= 1024; + rw[1] /= 1024; + break; + + case "auto": default: - for (let i = 0; i < lines.length - 1; i++) { - const line = lines[i]; - const entry = line.trim().split(/\s+/); - - if (entry[2].match(/loop*/)) { - continue; - } - - const filesystem = this._diskStatsBox.get_filesystem(entry[2]); - // Found - if (filesystem) { - let rwTot = [0, 0]; - let rw = [0, 0]; - - rwTot[0] += parseInt(entry[5]); - rwTot[1] += parseInt(entry[9]); - - // sector is 512 bytes - // 1 kilobyte = 2 sectors - rwTot[0] /= 2; - rwTot[1] /= 2; - - const idle = GLib.get_monotonic_time() / 1000; - const delta = (idle - this._diskStatsBox.get_idle(filesystem)) / 1000; - this._diskStatsBox.set_idle(filesystem, idle); - - let unit = ''; - - if (delta > 0) { - const rwTotOld = this._diskStatsBox.get_rw_tot(filesystem); - for (let i = 0; i < 2; i++) { - rw[i] = (rwTot[i] - rwTotOld[i]) / delta; - } - this._diskStatsBox.set_rw_tot(filesystem, rwTot); - - switch (this._diskStatsUnitMeasure) { - case 'k': - unit = 'K'; - break; - - case 'm': - unit = 'M'; - rw[0] /= 1024; - rw[1] /= 1024; - break; - - case 'g': - unit = 'G'; - rw[0] /= 1024; - rw[1] /= 1024; - rw[0] /= 1024; - rw[1] /= 1024; - break; - - case 't': - unit = 'T'; - rw[0] /= 1024; - rw[1] /= 1024; - rw[0] /= 1024; - rw[1] /= 1024; - rw[0] /= 1024; - rw[1] /= 1024; - break; - - case 'auto': - - default: - if (rw[0] > 1024 || rw[1] > 1024) { - unit = 'M'; - rw[0] /= 1024; - rw[1] /= 1024; - if (rw[0] > 1024 || rw[1] > 1024) { - unit = 'G'; - rw[0] /= 1024; - rw[1] /= 1024; - if (rw[0] > 1024 || rw[1] > 1024) { - unit = 'T'; - rw[0] /= 1024; - rw[1] /= 1024; - } - } - } else { - unit = 'K'; - } - - break; - } - } - - if (this._decimalsStatus) { - this._diskStatsBox.update_element_value(filesystem, `${rw[0].toFixed(1)}|${rw[1].toFixed(1)}`, unit); - } else { - this._diskStatsBox.update_element_value(filesystem, `${rw[0].toFixed(0)}|${rw[1].toFixed(0)}`, unit); - } - } else { // Not found - this._diskStatsBox.update_element_value(filesystem, '--|--', ''); - } + if (rw[0] > 1024 || rw[1] > 1024) { + unit = "M"; + rw[0] /= 1024; + rw[1] /= 1024; + if (rw[0] > 1024 || rw[1] > 1024) { + unit = "G"; + rw[0] /= 1024; + rw[1] /= 1024; + if (rw[0] > 1024 || rw[1] > 1024) { + unit = "T"; + rw[0] /= 1024; + rw[1] /= 1024; + } } + } else { + unit = "K"; + } - break; + break; + } } - }); - } - - _refreshDiskSpaceValue() { - this._executeCommand(['df', '-BKB', '-x', 'squashfs', '-x', 'tmpfs']).then(output => { - const lines = output.split('\n'); - - // Excludes the first line of output - for (let i = 1; i < lines.length - 1; i++) { - const line = lines[i]; - const entry = line.trim().split(/\s+/); - - const filesystem = entry[0]; - - let value = ''; - let unit = 'KB'; - switch (this._diskSpaceUnitType) { - case 'perc': - const used = `${entry[4].slice(0, -1)}`; - switch (this._diskSpaceMonitor) { - case 'free': - value = (100 - parseInt(used)).toString(); - - break; - - case 'used': - - default: - value = used; - - break; - } - - this._diskSpaceBox.update_element_value(filesystem, value, '%'); + if (this._decimalsStatus) { + this._diskStatsBox.update_element_value( + filesystem, + `${rw[0].toFixed(1)}|${rw[1].toFixed(1)}`, + unit + ); + } else { + this._diskStatsBox.update_element_value( + filesystem, + `${rw[0].toFixed(0)}|${rw[1].toFixed(0)}`, + unit + ); + } + } else { + // Not found + this._diskStatsBox.update_element_value( + filesystem, + "--|--", + "" + ); + } + } - break; + break; + } + }); + } - case 'numeric': + _refreshDiskSpaceValue() { + this._executeCommand([ + "df", + "-BKB", + "-x", + "squashfs", + "-x", + "tmpfs", + ]).then((output) => { + const lines = output.split("\n"); - default: - switch (this._diskSpaceMonitor) { - case 'free': - value = parseInt(entry[3].slice(0, -2)); + // Excludes the first line of output + for (let i = 1; i < lines.length - 1; i++) { + const line = lines[i]; + const entry = line.trim().split(/\s+/); - break; + const filesystem = entry[0]; - case 'used': + let value = ""; + let unit = "KB"; + switch (this._diskSpaceUnitType) { + case "perc": + const used = `${entry[4].slice(0, -1)}`; - default: - value = parseInt(entry[2].slice(0, -2)); + switch (this._diskSpaceMonitor) { + case "free": + value = (100 - parseInt(used)).toString(); - break; - } + break; - switch (this._diskSpaceUnitMeasure) { - case 'k': - unit = 'KB'; - break; + case "used": - case 'm': - unit = 'MB'; - value /= 1000; - break; + default: + value = used; - case 'g': - unit = 'GB'; - value /= 1000; - value /= 1000; - break; + break; + } - case 't': - unit = 'TB'; - value /= 1000; - value /= 1000; - value /= 1000; - break; + this._diskSpaceBox.update_element_value(filesystem, value, "%"); - case 'auto': + break; - default: - if (value > 1000) { - unit = 'MB'; - value /= 1000; - if (value > 1000) { - unit = 'GB'; - value /= 1000; - if (value > 1000) { - unit = 'TB'; - value /= 1000; - } - } - } else { - unit = 'KB'; - } + case "numeric": - break; - } + default: + switch (this._diskSpaceMonitor) { + case "free": + value = parseInt(entry[3].slice(0, -2)); - if (this._decimalsStatus) { - this._diskSpaceBox.update_element_value(filesystem, `${value.toFixed(1)}`, unit); - } else { - this._diskSpaceBox.update_element_value(filesystem, `${value.toFixed(0)}`, unit); - } + break; - break; - } - } - }); - } + case "used": - _refreshEthValue() { - this._loadFile('/proc/net/dev').then(contents => { - const lines = ByteArray.toString(contents).split('\n'); + default: + value = parseInt(entry[2].slice(0, -2)); - let duTot = [0, 0]; - let du = [0, 0]; + break; + } - // Excludes the first two lines of output - for (let i = 2; i < lines.length - 1; i++) { - const line = lines[i]; - const entry = line.trim().split(':'); - if (entry[0].match(/(eth[0-9]+|en[a-z0-9]*)/)) { - const values = entry[1].trim().split(/\s+/); + switch (this._diskSpaceUnitMeasure) { + case "k": + unit = "KB"; + break; - duTot[0] += parseInt(values[0]); - duTot[1] += parseInt(values[8]); - } - } + case "m": + unit = "MB"; + value /= 1000; + break; - const idle = GLib.get_monotonic_time() / 1000; - const delta = (idle - this._ethIdleOld) / 1000; + case "g": + unit = "GB"; + value /= 1000; + value /= 1000; + break; - // True bits - // False Bytes - const boolUnit = this._netUnit === 'bits'; + case "t": + unit = "TB"; + value /= 1000; + value /= 1000; + value /= 1000; + break; - const factor = boolUnit ? 8 : 1; + case "auto": - if (delta > 0) { - for (let i = 0; i < 2; i++) { - du[i] = ((duTot[i] - this._duTotEthOld[i]) * factor) / delta; - this._duTotEthOld[i] = duTot[i]; + default: + if (value > 1000) { + unit = "MB"; + value /= 1000; + if (value > 1000) { + unit = "GB"; + value /= 1000; + if (value > 1000) { + unit = "TB"; + value /= 1000; + } } + } else { + unit = "KB"; + } + + break; + } + + if (this._decimalsStatus) { + this._diskSpaceBox.update_element_value( + filesystem, + `${value.toFixed(1)}`, + unit + ); + } else { + this._diskSpaceBox.update_element_value( + filesystem, + `${value.toFixed(0)}`, + unit + ); + } + + break; + } + } + }); + } - switch (this._netUnitMeasure) { - case 'b': - this._ethUnit.text = boolUnit ? 'b' : 'B'; - break; - - case 'k': - this._ethUnit.text = boolUnit ? 'k' : 'K'; - du[0] /= 1024; - du[1] /= 1024; - break; - - case 'm': - this._ethUnit.text = boolUnit ? 'm' : 'M'; - du[0] /= 1024; - du[1] /= 1024; - du[0] /= 1024; - du[1] /= 1024; - break; - - case 'g': - this._ethUnit.text = boolUnit ? 'g' : 'G'; - du[0] /= 1024; - du[1] /= 1024; - du[0] /= 1024; - du[1] /= 1024; - du[0] /= 1024; - du[1] /= 1024; - break; - - case 't': - this._ethUnit.text = boolUnit ? 't' : 'T'; - du[0] /= 1024; - du[1] /= 1024; - du[0] /= 1024; - du[1] /= 1024; - du[0] /= 1024; - du[1] /= 1024; - du[0] /= 1024; - du[1] /= 1024; - break; - - case 'auto': - - default: - if (du[0] > 1024 || du[1] > 1024) { - this._ethUnit.text = boolUnit ? 'k' : 'K'; - du[0] /= 1024; - du[1] /= 1024; - if (du[0] > 1024 || du[1] > 1024) { - this._ethUnit.text = boolUnit ? 'm' : 'M'; - du[0] /= 1024; - du[1] /= 1024; - if (du[0] > 1024 || du[1] > 1024) { - this._ethUnit.text = boolUnit ? 'g' : 'G'; - du[0] /= 1024; - du[1] /= 1024; - if (du[0] > 1024 || du[1] > 1024) { - this._ethUnit.text = boolUnit ? 't' : 'T'; - du[0] /= 1024; - du[1] /= 1024; - } - } - } - } else { - this._ethUnit.text = boolUnit ? 'b' : 'B'; - } - - break; + _refreshEthValue() { + this._loadFile("/proc/net/dev").then((contents) => { + const lines = new TextDecoder().decode(contents).split("\n"); + + let duTot = [0, 0]; + let du = [0, 0]; + + // Excludes the first two lines of output + for (let i = 2; i < lines.length - 1; i++) { + const line = lines[i]; + const entry = line.trim().split(":"); + if (entry[0].match(/(eth[0-9]+|en[a-z0-9]*)/)) { + const values = entry[1].trim().split(/\s+/); + + duTot[0] += parseInt(values[0]); + duTot[1] += parseInt(values[8]); + } + } + + const idle = GLib.get_monotonic_time() / 1000; + const delta = (idle - this._ethIdleOld) / 1000; + + // True bits + // False Bytes + const boolUnit = this._netUnit === "bits"; + + const factor = boolUnit ? 8 : 1; + + if (delta > 0) { + for (let i = 0; i < 2; i++) { + du[i] = ((duTot[i] - this._duTotEthOld[i]) * factor) / delta; + this._duTotEthOld[i] = duTot[i]; + } + + switch (this._netUnitMeasure) { + case "b": + this._ethUnit.text = boolUnit ? "b" : "B"; + break; + + case "k": + this._ethUnit.text = boolUnit ? "k" : "K"; + du[0] /= 1024; + du[1] /= 1024; + break; + + case "m": + this._ethUnit.text = boolUnit ? "m" : "M"; + du[0] /= 1024; + du[1] /= 1024; + du[0] /= 1024; + du[1] /= 1024; + break; + + case "g": + this._ethUnit.text = boolUnit ? "g" : "G"; + du[0] /= 1024; + du[1] /= 1024; + du[0] /= 1024; + du[1] /= 1024; + du[0] /= 1024; + du[1] /= 1024; + break; + + case "t": + this._ethUnit.text = boolUnit ? "t" : "T"; + du[0] /= 1024; + du[1] /= 1024; + du[0] /= 1024; + du[1] /= 1024; + du[0] /= 1024; + du[1] /= 1024; + du[0] /= 1024; + du[1] /= 1024; + break; + + case "auto": + + default: + if (du[0] > 1024 || du[1] > 1024) { + this._ethUnit.text = boolUnit ? "k" : "K"; + du[0] /= 1024; + du[1] /= 1024; + if (du[0] > 1024 || du[1] > 1024) { + this._ethUnit.text = boolUnit ? "m" : "M"; + du[0] /= 1024; + du[1] /= 1024; + if (du[0] > 1024 || du[1] > 1024) { + this._ethUnit.text = boolUnit ? "g" : "G"; + du[0] /= 1024; + du[1] /= 1024; + if (du[0] > 1024 || du[1] > 1024) { + this._ethUnit.text = boolUnit ? "t" : "T"; + du[0] /= 1024; + du[1] /= 1024; } + } } + } else { + this._ethUnit.text = boolUnit ? "b" : "B"; + } - this._ethIdleOld = idle; - - if (this._decimalsStatus) { - this._ethValue.text = `${du[0].toFixed(1)}|${du[1].toFixed(1)}`; - } else { - this._ethValue.text = `${du[0].toFixed(0)}|${du[1].toFixed(0)}`; - } - }); + break; + } } - _refreshWlanValue() { - this._loadFile('/proc/net/dev').then(contents => { - const lines = ByteArray.toString(contents).split('\n'); - - let duTot = [0, 0]; - let du = [0, 0]; - - // Excludes the first two lines of output - for (let i = 2; i < lines.length - 1; i++) { - const line = lines[i]; - const entry = line.trim().split(':'); - if (entry[0].match(/(wlan[0-9]+|wl[a-z0-9]*)/)) { - const values = entry[1].trim().split(/\s+/); - - duTot[0] += parseInt(values[0]); - duTot[1] += parseInt(values[8]); - } - } - - const idle = GLib.get_monotonic_time() / 1000; - const delta = (idle - this._wlanIdleOld) / 1000; - - // True bits - // False Bytes - const boolUnit = this._netUnit === 'bits'; - - const factor = boolUnit ? 8 : 1; - - if (delta > 0) { - for (let i = 0; i < 2; i++) { - du[i] = ((duTot[i] - this._duTotWlanOld[i]) * factor) / delta; - this._duTotWlanOld[i] = duTot[i]; - } - - switch (this._netUnitMeasure) { - case 'b': - this._wlanUnit.text = boolUnit ? 'b' : 'B'; - break; - - case 'k': - this._wlanUnit.text = boolUnit ? 'k' : 'K'; - du[0] /= 1024; - du[1] /= 1024; - break; - - case 'm': - this._wlanUnit.text = boolUnit ? 'm' : 'M'; - du[0] /= 1024; - du[1] /= 1024; - du[0] /= 1024; - du[1] /= 1024; - break; - - case 'g': - this._wlanUnit.text = boolUnit ? 'g' : 'G'; - du[0] /= 1024; - du[1] /= 1024; - du[0] /= 1024; - du[1] /= 1024; - du[0] /= 1024; - du[1] /= 1024; - break; - - case 't': - this._wlanUnit.text = boolUnit ? 't' : 'T'; - du[0] /= 1024; - du[1] /= 1024; - du[0] /= 1024; - du[1] /= 1024; - du[0] /= 1024; - du[1] /= 1024; - du[0] /= 1024; - du[1] /= 1024; - break; - - case 'auto': - - default: - if (du[0] > 1024 || du[1] > 1024) { - this._wlanUnit.text = boolUnit ? 'k' : 'K'; - du[0] /= 1024; - du[1] /= 1024; - if (du[0] > 1024 || du[1] > 1024) { - this._wlanUnit.text = boolUnit ? 'm' : 'M'; - du[0] /= 1024; - du[1] /= 1024; - if (du[0] > 1024 || du[1] > 1024) { - this._wlanUnit.text = boolUnit ? 'g' : 'G'; - du[0] /= 1024; - du[1] /= 1024; - if (du[0] > 1024 || du[1] > 1024) { - this._wlanUnit.text = boolUnit ? 't' : 'T'; - du[0] /= 1024; - du[1] /= 1024; - } - } - } - } else { - this._wlanUnit.text = boolUnit ? 'b' : 'B'; - } - - break; - } - } - - this._wlanIdleOld = idle; + this._ethIdleOld = idle; - if (this._decimalsStatus) { - this._wlanValue.text = `${du[0].toFixed(1)}|${du[1].toFixed(1)}`; - } else { - this._wlanValue.text = `${du[0].toFixed(0)}|${du[1].toFixed(0)}`; - } - }); + if (this._decimalsStatus) { + this._ethValue.text = `${du[0].toFixed(1)}|${du[1].toFixed(1)}`; + } else { + this._ethValue.text = `${du[0].toFixed(0)}|${du[1].toFixed(0)}`; } + }); + } - _refreshCpuFrequencyValue() { - if (GLib.file_test('/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq', GLib.FileTest.EXISTS)) { - this._loadFile('/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq').then(contents => { - let value = parseInt(ByteArray.toString(contents)); - let unit = ""; - - switch (this._cpuFrequencyUnitMeasure) { - case 'k': - unit = "KHz" - break; - - case 'm': - unit = "MHz" - value /= 1000; - break; - - case 'g': - unit = "GHz" - value /= 1000; - value /= 1000; - break; - - case 'auto': - - default: - if (value > 1000) { - unit = 'MHz'; - value /= 1000; - if (value > 1000) { - unit = 'GHz'; - value /= 1000; - } - } else { - unit = 'KHz'; - } - - break; + _refreshWlanValue() { + this._loadFile("/proc/net/dev").then((contents) => { + const lines = new TextDecoder().decode(contents).split("\n"); + + let duTot = [0, 0]; + let du = [0, 0]; + + // Excludes the first two lines of output + for (let i = 2; i < lines.length - 1; i++) { + const line = lines[i]; + const entry = line.trim().split(":"); + if (entry[0].match(/(wlan[0-9]+|wl[a-z0-9]*)/)) { + const values = entry[1].trim().split(/\s+/); + + duTot[0] += parseInt(values[0]); + duTot[1] += parseInt(values[8]); + } + } + + const idle = GLib.get_monotonic_time() / 1000; + const delta = (idle - this._wlanIdleOld) / 1000; + + // True bits + // False Bytes + const boolUnit = this._netUnit === "bits"; + + const factor = boolUnit ? 8 : 1; + + if (delta > 0) { + for (let i = 0; i < 2; i++) { + du[i] = ((duTot[i] - this._duTotWlanOld[i]) * factor) / delta; + this._duTotWlanOld[i] = duTot[i]; + } + + switch (this._netUnitMeasure) { + case "b": + this._wlanUnit.text = boolUnit ? "b" : "B"; + break; + + case "k": + this._wlanUnit.text = boolUnit ? "k" : "K"; + du[0] /= 1024; + du[1] /= 1024; + break; + + case "m": + this._wlanUnit.text = boolUnit ? "m" : "M"; + du[0] /= 1024; + du[1] /= 1024; + du[0] /= 1024; + du[1] /= 1024; + break; + + case "g": + this._wlanUnit.text = boolUnit ? "g" : "G"; + du[0] /= 1024; + du[1] /= 1024; + du[0] /= 1024; + du[1] /= 1024; + du[0] /= 1024; + du[1] /= 1024; + break; + + case "t": + this._wlanUnit.text = boolUnit ? "t" : "T"; + du[0] /= 1024; + du[1] /= 1024; + du[0] /= 1024; + du[1] /= 1024; + du[0] /= 1024; + du[1] /= 1024; + du[0] /= 1024; + du[1] /= 1024; + break; + + case "auto": + + default: + if (du[0] > 1024 || du[1] > 1024) { + this._wlanUnit.text = boolUnit ? "k" : "K"; + du[0] /= 1024; + du[1] /= 1024; + if (du[0] > 1024 || du[1] > 1024) { + this._wlanUnit.text = boolUnit ? "m" : "M"; + du[0] /= 1024; + du[1] /= 1024; + if (du[0] > 1024 || du[1] > 1024) { + this._wlanUnit.text = boolUnit ? "g" : "G"; + du[0] /= 1024; + du[1] /= 1024; + if (du[0] > 1024 || du[1] > 1024) { + this._wlanUnit.text = boolUnit ? "t" : "T"; + du[0] /= 1024; + du[1] /= 1024; } + } + } + } else { + this._wlanUnit.text = boolUnit ? "b" : "B"; + } - this._cpuFrequencyUnit.text = unit; - - if (this._decimalsStatus) { - this._cpuFrequencyValue.text = `[${value.toFixed(2)}`; - } else { - this._cpuFrequencyValue.text = `[${value.toFixed(0)}`; - } - }); - } else { - this._cpuFrequencyValue.text = _('[Frequency Error'); - this._cpuFrequencyUnit.text = ''; - } + break; + } } - _refreshCpuLoadAverageValue() { - this._loadFile('/proc/loadavg').then(contents => { - const lines = ByteArray.toString(contents).split('\n'); - - const entry = lines[0].trim().split(/\s/); - - const l0 = entry[0]; - const l1 = entry[1]; - const l2 = entry[2]; + this._wlanIdleOld = idle; - this._cpuLoadAverageValue.text = '[' + l0 + ' ' + l1 + ' ' + l2 + ']'; - }); + if (this._decimalsStatus) { + this._wlanValue.text = `${du[0].toFixed(1)}|${du[1].toFixed(1)}`; + } else { + this._wlanValue.text = `${du[0].toFixed(0)}|${du[1].toFixed(0)}`; } + }); + } - _refreshCpuTemperatureValue() { - if (this._thermalCpuTemperatureDevicesList.length > 0) { - for (let i = 0; i < this._thermalCpuTemperatureDevicesList.length; i++) { - const element = this._thermalCpuTemperatureDevicesList[i]; - const it = element.split(THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR); - - const status = it[1]; - const path = it[2]; - - if (status === 'false') { - continue; - } - - if (GLib.file_test(path, GLib.FileTest.EXISTS)) { - this._loadFile(path).then(contents => { - const value = parseInt(ByteArray.toString(contents)); - - this._cpuTemperatures += value / 1000; - this._cpuTemperaturesReads++; - - if (this._cpuTemperaturesReads >= this._thermalCpuTemperatureDevicesList.length) { - // Temperatures Average - this._cpuTemperatures /= this._cpuTemperaturesReads; - - switch (this._thermalTemperatureUnit) { - case 'f': - this._cpuTemperatures = (this._cpuTemperatures * 1.8) + 32; - this._cpuTemperatureUnit.text = '°F'; - - break; - - case 'c': - - default: - this._cpuTemperatureUnit.text = '°C'; - - break; - } - - if (this._decimalsStatus) { - this._cpuTemperatureValue.text = `[${this._cpuTemperatures.toFixed(1)}`; - } else { - this._cpuTemperatureValue.text = `[${this._cpuTemperatures.toFixed(0)}`; - } - - this._cpuTemperatures = 0; - this._cpuTemperaturesReads = 0; - } - }); - } else { - this._cpuTemperatureValue.text = _('[Temperature Error'); - this._cpuTemperatureUnit.text = ''; - } + _refreshCpuFrequencyValue() { + if ( + GLib.file_test( + "/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq", + GLib.FileTest.EXISTS + ) + ) { + this._loadFile( + "/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq" + ).then((contents) => { + let value = parseInt(new TextDecoder().decode(contents)); + let unit = ""; + + switch (this._cpuFrequencyUnitMeasure) { + case "k": + unit = "KHz"; + break; + + case "m": + unit = "MHz"; + value /= 1000; + break; + + case "g": + unit = "GHz"; + value /= 1000; + value /= 1000; + break; + + case "auto": + + default: + if (value > 1000) { + unit = "MHz"; + value /= 1000; + if (value > 1000) { + unit = "GHz"; + value /= 1000; } - } else { - this._cpuTemperatureValue.text = _('[--'); - } - } - - _refreshGpuValue() { - this._executeCommand(['nvidia-smi', '--query-gpu=uuid,memory.total,memory.used,memory.free,utilization.gpu,temperature.gpu', '--format=csv,noheader']).then(output => { - const lines = output.split('\n'); - - for (let i = 0; i < lines.length - 1; i++) { - const line = lines[i]; - const entry = line.trim().split(/\,\s/); - - const uuid = entry[0]; - let memoryTotal = entry[1].slice(0, -4); - let memoryUsed = entry[2].slice(0, -4); - let memoryFree = entry[3].slice(0, -4); - const usage = entry[4].slice(0, -1); - const temperature = entry[5]; - - // mebibyte - memoryTotal = parseInt(memoryTotal); - memoryUsed = parseInt(memoryUsed); - memoryFree = parseInt(memoryFree); + } else { + unit = "KHz"; + } - // kibibyte - memoryTotal *= 1024; - memoryUsed *= 1024; - memoryFree *= 1024; + break; + } - // kilobyte - memoryTotal *= 1.024; - memoryUsed *= 1.024; - memoryFree *= 1.024; + this._cpuFrequencyUnit.text = unit; - this._gpuBox.update_element_value(uuid, usage, '%'); + if (this._decimalsStatus) { + this._cpuFrequencyValue.text = `[${value.toFixed(2)}`; + } else { + this._cpuFrequencyValue.text = `[${value.toFixed(0)}`; + } + }); + } else { + this._cpuFrequencyValue.text = _("[Frequency Error"); + this._cpuFrequencyUnit.text = ""; + } + } - let value = 0; - let unit = 'KB'; - switch (this._gpuMemoryUnitType) { - case 'perc': - const used = (100 * memoryUsed) / memoryTotal; - unit = '%'; + _refreshCpuLoadAverageValue() { + this._loadFile("/proc/loadavg").then((contents) => { + const lines = new TextDecoder().decode(contents).split("\n"); - switch (this._gpuMemoryMonitor) { - case 'free': - value = 100 - used; + const entry = lines[0].trim().split(/\s/); - break; + const l0 = entry[0]; + const l1 = entry[1]; + const l2 = entry[2]; - case 'used': + this._cpuLoadAverageValue.text = "[" + l0 + " " + l1 + " " + l2 + "]"; + }); + } - default: - value = used; + _refreshCpuTemperatureValue() { + if (this._thermalCpuTemperatureDevicesList.length > 0) { + for ( + let i = 0; + i < this._thermalCpuTemperatureDevicesList.length; + i++ + ) { + const element = this._thermalCpuTemperatureDevicesList[i]; + const it = element.split( + THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR + ); + + const status = it[1]; + const path = it[2]; + + if (status === "false") { + continue; + } + + if (GLib.file_test(path, GLib.FileTest.EXISTS)) { + this._loadFile(path).then((contents) => { + const value = parseInt(new TextDecoder().decode(contents)); + + this._cpuTemperatures += value / 1000; + this._cpuTemperaturesReads++; + + if ( + this._cpuTemperaturesReads >= + this._thermalCpuTemperatureDevicesList.length + ) { + // Temperatures Average + this._cpuTemperatures /= this._cpuTemperaturesReads; + + switch (this._thermalTemperatureUnit) { + case "f": + this._cpuTemperatures = this._cpuTemperatures * 1.8 + 32; + this._cpuTemperatureUnit.text = "°F"; - break; - } + break; - break; + case "c": - case 'numeric': + default: + this._cpuTemperatureUnit.text = "°C"; - default: - switch (this._gpuMemoryMonitor) { - case 'free': - value = memoryFree; + break; + } - break; + if (this._decimalsStatus) { + this._cpuTemperatureValue.text = `[${this._cpuTemperatures.toFixed( + 1 + )}`; + } else { + this._cpuTemperatureValue.text = `[${this._cpuTemperatures.toFixed( + 0 + )}`; + } - case 'used': + this._cpuTemperatures = 0; + this._cpuTemperaturesReads = 0; + } + }); + } else { + this._cpuTemperatureValue.text = _("[Temperature Error"); + this._cpuTemperatureUnit.text = ""; + } + } + } else { + this._cpuTemperatureValue.text = _("[--"); + } + } - default: - value = memoryUsed; + _refreshGpuValue() { + this._executeCommand([ + "nvidia-smi", + "--query-gpu=uuid,memory.total,memory.used,memory.free,utilization.gpu,temperature.gpu", + "--format=csv,noheader", + ]).then((output) => { + const lines = output.split("\n"); + + for (let i = 0; i < lines.length - 1; i++) { + const line = lines[i]; + const entry = line.trim().split(/\,\s/); + + const uuid = entry[0]; + let memoryTotal = entry[1].slice(0, -4); + let memoryUsed = entry[2].slice(0, -4); + let memoryFree = entry[3].slice(0, -4); + const usage = entry[4].slice(0, -1); + const temperature = entry[5]; + + // mebibyte + memoryTotal = parseInt(memoryTotal); + memoryUsed = parseInt(memoryUsed); + memoryFree = parseInt(memoryFree); + + // kibibyte + memoryTotal *= 1024; + memoryUsed *= 1024; + memoryFree *= 1024; + + // kilobyte + memoryTotal *= 1.024; + memoryUsed *= 1.024; + memoryFree *= 1.024; + + this._gpuBox.update_element_value(uuid, usage, "%"); + + let value = 0; + let unit = "KB"; + switch (this._gpuMemoryUnitType) { + case "perc": + const used = (100 * memoryUsed) / memoryTotal; + unit = "%"; + + switch (this._gpuMemoryMonitor) { + case "free": + value = 100 - used; + + break; + + case "used": - break; - } + default: + value = used; - switch (this._gpuMemoryUnitMeasure) { - case 'k': - unit = 'KB'; - break; + break; + } - case 'm': - unit = 'MB'; - value /= 1000; + break; - break; + case "numeric": - case 'g': - unit = 'GB'; - value /= 1000; - value /= 1000; + default: + switch (this._gpuMemoryMonitor) { + case "free": + value = memoryFree; - break; + break; - case 't': - unit = 'TB'; - value /= 1000; - value /= 1000; - value /= 1000; + case "used": - break; + default: + value = memoryUsed; - case 'auto': + break; + } - default: - if (value > 1000) { - unit = 'MB'; - value /= 1000; - if (value > 1000) { - unit = 'GB'; - value /= 1000; - if (value > 1000) { - unit = 'TB'; - value /= 1000; - } - } - } else { - unit = 'KB'; - } + switch (this._gpuMemoryUnitMeasure) { + case "k": + unit = "KB"; + break; - break; - } + case "m": + unit = "MB"; + value /= 1000; - break; - } + break; - let valueT = parseInt(temperature); - let unitT = '°C'; - switch (this._thermalTemperatureUnit) { - case 'f': - valueT = (valueT * 1.8) + 32; - unitT = '°F'; + case "g": + unit = "GB"; + value /= 1000; + value /= 1000; - break; + break; - case 'c': + case "t": + unit = "TB"; + value /= 1000; + value /= 1000; + value /= 1000; - default: - unitT = '°C'; + break; - break; - } + case "auto": - if (this._decimalsStatus) { - this._gpuBox.update_element_memory_value(uuid, `${value.toFixed(1)}`, unit); - this._gpuBox.update_element_thermal_value(uuid, `${valueT.toFixed(1)}`, unitT); - } else { - this._gpuBox.update_element_memory_value(uuid, `${value.toFixed(0)}`, unit); - this._gpuBox.update_element_thermal_value(uuid, `${valueT.toFixed(0)}`, unitT); + default: + if (value > 1000) { + unit = "MB"; + value /= 1000; + if (value > 1000) { + unit = "GB"; + value /= 1000; + if (value > 1000) { + unit = "TB"; + value /= 1000; + } } - } - }); - } - - // Common Function - _basicItemStatus(status, iconCondition, icon, ...elements) { - if (status) { - if (this._iconsStatus) { - icon.show(); - } - elements.forEach(element => { - element.show(); - }); - } else { - if (iconCondition) { - icon.hide(); - } - elements.forEach(element => { - element.hide(); - }); - } - } - - _basicItemWidth(width, element) { - if (width === 0) { - element.min_width = 0; - element.natural_width = 0; - element.min_width_set = false; - element.natural_width_set = false; - } else { - element.width = width; - } - } - - _loadContents(file, cancellable = null) { - return new Promise((resolve, reject) => { - file.load_contents_async(cancellable, (source_object, res) => { - try { - const [ok, contents, etag_out] = source_object.load_contents_finish(res); + } else { + unit = "KB"; + } + + break; + } + + break; + } + + let valueT = parseInt(temperature); + let unitT = "°C"; + switch (this._thermalTemperatureUnit) { + case "f": + valueT = valueT * 1.8 + 32; + unitT = "°F"; + + break; + + case "c": + + default: + unitT = "°C"; + + break; + } + + if (this._decimalsStatus) { + this._gpuBox.update_element_memory_value( + uuid, + `${value.toFixed(1)}`, + unit + ); + this._gpuBox.update_element_thermal_value( + uuid, + `${valueT.toFixed(1)}`, + unitT + ); + } else { + this._gpuBox.update_element_memory_value( + uuid, + `${value.toFixed(0)}`, + unit + ); + this._gpuBox.update_element_thermal_value( + uuid, + `${valueT.toFixed(0)}`, + unitT + ); + } + } + }); + } - resolve(contents); - } catch (e) { - reject(e); - } - }); - }); + // Common Function + _basicItemStatus(status, iconCondition, icon, ...elements) { + if (status) { + if (this._iconsStatus) { + icon.show(); } - - async _loadFile(path, cancellable = null) { - try { - const file = Gio.File.new_for_path(path); - const contents = await this._loadContents(file, cancellable); - - return contents; - } catch (error) { - log('[Resource_Monitor] Load File Error (' + error + ')'); - } + elements.forEach((element) => { + element.show(); + }); + } else { + if (iconCondition) { + icon.hide(); } + elements.forEach((element) => { + element.hide(); + }); + } + } - _readOutput(proc, cancellable = null) { - return new Promise((resolve, reject) => { - proc.communicate_utf8_async(null, cancellable, (source_object, res) => { - try { - const [ok, stdout, stderr] = source_object.communicate_utf8_finish(res); + _basicItemWidth(width, element) { + if (width === 0) { + element.min_width = 0; + element.natural_width = 0; + element.min_width_set = false; + element.natural_width_set = false; + } else { + element.width = width; + } + } - if (source_object.get_successful()) { - resolve(stdout); - } else { - throw new Error(stderr); - } - } catch (e) { - reject(e); - } - }); - }); - } + _loadContents(file, cancellable = null) { + return new Promise((resolve, reject) => { + file.load_contents_async(cancellable, (source_object, res) => { + try { + const [ok, contents, etag_out] = + source_object.load_contents_finish(res); + + resolve(contents); + } catch (e) { + reject(e); + } + }); + }); + } - async _executeCommand(command, cancellable = null) { - try { - const proc = Gio.Subprocess.new(command, Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE); - const output = await this._readOutput(proc, cancellable); + async _loadFile(path, cancellable = null) { + try { + const file = Gio.File.new_for_path(path); + const contents = await this._loadContents(file, cancellable); - return output; - } catch (error) { - log('[Resource_Monitor] Execute Command Error (' + error + ')'); - } - } - }); + return contents; + } catch (error) { + console.error("[Resource_Monitor] Load File Error (" + error + ")"); + } + } -const DiskContainer = GObject.registerClass( - class DiskContainer extends St.BoxLayout { - _init() { - super._init(); - - this._elementsPath = []; - this._elementsName = []; - this._elementsLabel = []; - this._elementsValue = []; - this._elementsUnit = []; - } + _readOutput(proc, cancellable = null) { + return new Promise((resolve, reject) => { + proc.communicate_utf8_async(null, cancellable, (source_object, res) => { + try { + const [ok, stdout, stderr] = + source_object.communicate_utf8_finish(res); - set_element_width(width) { - if (width === 0) { - this._elementsPath.forEach(element => { - this._elementsValue[element].min_width = 0; - this._elementsValue[element].natural_width = 0; - this._elementsValue[element].min_width_set = false; - this._elementsValue[element].natural_width_set = false; - }); + if (source_object.get_successful()) { + resolve(stdout); } else { - this._elementsPath.forEach(element => { - this._elementsValue[element].width = width; - }); + throw new Error(stderr); } - } - - cleanup_elements() { - this._elementsPath = []; - this._elementsName = []; - this._elementsLabel = []; - this._elementsValue = []; - this._elementsUnit = []; + } catch (e) { + reject(e); + } + }); + }); + } - this.remove_all_children(); - } - }); + async _executeCommand(command, cancellable = null) { + try { + const proc = Gio.Subprocess.new( + command, + Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE + ); + const output = await this._readOutput(proc, cancellable); + + return output; + } catch (error) { + console.error( + "[Resource_Monitor] Execute Command Error (" + error + ")" + ); + } + } + } +); -const DiskContainerStats = GObject.registerClass( - class DiskContainerStats extends DiskContainer { - _init() { - super._init(); +const DiskContainer = GObject.registerClass( + class DiskContainer extends St.BoxLayout { + _init() { + super._init(); + + this._elementsPath = []; + this._elementsName = []; + this._elementsLabel = []; + this._elementsValue = []; + this._elementsUnit = []; + } - this.idleOld = []; - this.rwTotOld = []; + set_element_width(width) { + if (width === 0) { + this._elementsPath.forEach((element) => { + this._elementsValue[element].min_width = 0; + this._elementsValue[element].natural_width = 0; + this._elementsValue[element].min_width_set = false; + this._elementsValue[element].natural_width_set = false; + }); + } else { + this._elementsPath.forEach((element) => { + this._elementsValue[element].width = width; + }); + } + } - this.add_single(); - } + cleanup_elements() { + this._elementsPath = []; + this._elementsName = []; + this._elementsLabel = []; + this._elementsValue = []; + this._elementsUnit = []; - add_single() { - this._elementsPath.push('single'); + this.remove_all_children(); + } + } +); - this._elementsValue['single'] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '--|--' - }); - this._elementsValue['single'].set_style('text-align: right;'); +const DiskContainerStats = GObject.registerClass( + class DiskContainerStats extends DiskContainer { + _init() { + super._init(); - this._elementsUnit['single'] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: 'K' - }); - this._elementsUnit['single'].set_style('padding-left: 0.125em;'); + this.idleOld = []; + this.rwTotOld = []; - this.add(this._elementsValue['single']); - this.add(this._elementsUnit['single']); + this.add_single(); + } - this.idleOld['single'] = 0; - this.rwTotOld['single'] = [0, 0]; - } + add_single() { + this._elementsPath.push("single"); - add_element(filesystem, label) { - this._elementsPath.push(filesystem); + this._elementsValue["single"] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "--|--", + }); + this._elementsValue["single"].set_style("text-align: right;"); - this._elementsName[filesystem] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: ` ${label}: ` - }); + this._elementsUnit["single"] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "K", + }); + this._elementsUnit["single"].set_style("padding-left: 0.125em;"); - this._elementsValue[filesystem] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '--|--' - }); - this._elementsValue[filesystem].set_style('text-align: right;'); + this.add(this._elementsValue["single"]); + this.add(this._elementsUnit["single"]); - this._elementsUnit[filesystem] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: 'K' - }); - this._elementsUnit[filesystem].set_style('padding-left: 0.125em;'); + this.idleOld["single"] = 0; + this.rwTotOld["single"] = [0, 0]; + } - this.add(this._elementsName[filesystem]); - this.add(this._elementsValue[filesystem]); - this.add(this._elementsUnit[filesystem]); + add_element(filesystem, label) { + this._elementsPath.push(filesystem); - this.idleOld[filesystem] = 0; - this.rwTotOld[filesystem] = [0, 0]; - } + this._elementsName[filesystem] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: ` ${label}: `, + }); - update_mode(mode) { - switch (mode) { - case 'single': - this._elementsPath.forEach(element => { - if (element !== 'single') { - this._elementsName[element].hide(); - this._elementsValue[element].hide(); - this._elementsUnit[element].hide(); - } else { - this._elementsValue[element].show(); - this._elementsUnit[element].show(); - } - }); + this._elementsValue[filesystem] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "--|--", + }); + this._elementsValue[filesystem].set_style("text-align: right;"); - break; + this._elementsUnit[filesystem] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "K", + }); + this._elementsUnit[filesystem].set_style("padding-left: 0.125em;"); - case 'multiple': + this.add(this._elementsName[filesystem]); + this.add(this._elementsValue[filesystem]); + this.add(this._elementsUnit[filesystem]); - default: - this._elementsPath.forEach(element => { - if (element !== 'single') { - this._elementsName[element].show(); - this._elementsValue[element].show(); - this._elementsUnit[element].show(); - } else { - this._elementsValue[element].hide(); - this._elementsUnit[element].hide(); - } - }); + this.idleOld[filesystem] = 0; + this.rwTotOld[filesystem] = [0, 0]; + } - break; + update_mode(mode) { + switch (mode) { + case "single": + this._elementsPath.forEach((element) => { + if (element !== "single") { + this._elementsName[element].hide(); + this._elementsValue[element].hide(); + this._elementsUnit[element].hide(); + } else { + this._elementsValue[element].show(); + this._elementsUnit[element].show(); } - } + }); - get_filesystem(name) { - return this._elementsPath.filter(item => item.endsWith(name)).shift(); - } + break; - get_idle(filesystem) { - return this.idleOld[filesystem]; - } - - get_rw_tot(filesystem) { - return this.rwTotOld[filesystem]; - } + case "multiple": - set_idle(filesystem, idle) { - this.idleOld[filesystem] = idle; - } - - set_rw_tot(filesystem, rwTot) { - this.rwTotOld[filesystem] = rwTot; - } - - update_element_value(filesystem, value, unit) { - if (this._elementsValue[filesystem]) { - this._elementsValue[filesystem].text = value; - this._elementsUnit[filesystem].text = unit; + default: + this._elementsPath.forEach((element) => { + if (element !== "single") { + this._elementsName[element].show(); + this._elementsValue[element].show(); + this._elementsUnit[element].show(); + } else { + this._elementsValue[element].hide(); + this._elementsUnit[element].hide(); } - } - }); - -const DiskContainerSpace = GObject.registerClass( - class DiskContainerSpace extends DiskContainer { - add_element(filesystem, label) { - this._elementsPath.push(filesystem); - - this._elementsName[filesystem] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: ` ${label}: ` - }); + }); - this._elementsValue[filesystem] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '--' - }); - this._elementsValue[filesystem].set_style('text-align: right;'); + break; + } + } - this._elementsUnit[filesystem] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: this._diskSpaceUnitType ? '%' : 'KB' - }); - this._elementsUnit[filesystem].set_style('padding-left: 0.125em;'); + get_filesystem(name) { + return this._elementsPath.filter((item) => item.endsWith(name)).shift(); + } - this.add(this._elementsName[filesystem]); - this.add(this._elementsValue[filesystem]); - this.add(this._elementsUnit[filesystem]); - } + get_idle(filesystem) { + return this.idleOld[filesystem]; + } - update_element_value(filesystem, value, unit) { - if (this._elementsValue[filesystem]) { - this._elementsValue[filesystem].text = value; - this._elementsUnit[filesystem].text = unit; - } - } - }); + get_rw_tot(filesystem) { + return this.rwTotOld[filesystem]; + } -const GpuContainer = GObject.registerClass( - class GpuContainer extends St.BoxLayout { - _init() { - super._init(); - - this._elementsUuid = []; - this._elementsName = []; - this._elementsValue = []; - this._elementsUnit = []; - this._elementsMemoryValue = []; - this._elementsMemoryUnit = []; - this._elementsThermalValue = []; - this._elementsThermalUnit = []; - } + set_idle(filesystem, idle) { + this.idleOld[filesystem] = idle; + } - set_element_width(width) { - if (width === 0) { - this._elementsUuid.forEach(element => { - if (typeof this._elementsValue[element] !== 'undefined') { - this._elementsValue[element].min_width = 0; - this._elementsValue[element].natural_width = 0; - this._elementsValue[element].min_width_set = false; - this._elementsValue[element].natural_width_set = false; - } + set_rw_tot(filesystem, rwTot) { + this.rwTotOld[filesystem] = rwTot; + } - if (typeof this._elementsMemoryValue[element] !== 'undefined') { - this._elementsMemoryValue[element].min_width = 0; - this._elementsMemoryValue[element].natural_width = 0; - this._elementsMemoryValue[element].min_width_set = false; - this._elementsMemoryValue[element].natural_width_set = false; - } - }); - } else { - this._elementsUuid.forEach(element => { - if (typeof this._elementsValue[element] !== 'undefined') { - this._elementsValue[element].width = width; - } + update_element_value(filesystem, value, unit) { + if (this._elementsValue[filesystem]) { + this._elementsValue[filesystem].text = value; + this._elementsUnit[filesystem].text = unit; + } + } + } +); - if (typeof this._elementsMemoryValue[element] !== 'undefined') { - this._elementsMemoryValue[element].width = width; - } - }); - } - } +const DiskContainerSpace = GObject.registerClass( + class DiskContainerSpace extends DiskContainer { + add_element(filesystem, label) { + this._elementsPath.push(filesystem); + + this._elementsName[filesystem] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: ` ${label}: `, + }); + + this._elementsValue[filesystem] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "--", + }); + this._elementsValue[filesystem].set_style("text-align: right;"); + + this._elementsUnit[filesystem] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: this._diskSpaceUnitType ? "%" : "KB", + }); + this._elementsUnit[filesystem].set_style("padding-left: 0.125em;"); + + this.add(this._elementsName[filesystem]); + this.add(this._elementsValue[filesystem]); + this.add(this._elementsUnit[filesystem]); + } - set_element_thermal_width(width) { - if (width === 0) { - this._elementsUuid.forEach(element => { - if (typeof this._elementsThermalValue[element] !== 'undefined') { - this._elementsThermalValue[element].min_width = 0; - this._elementsThermalValue[element].natural_width = 0; - this._elementsThermalValue[element].min_width_set = false; - this._elementsThermalValue[element].natural_width_set = false; - } - }); - } else { - this._elementsUuid.forEach(element => { - if (typeof this._elementsThermalValue[element] !== 'undefined') { - this._elementsThermalValue[element].width = width; - } - }); - } - } + update_element_value(filesystem, value, unit) { + if (this._elementsValue[filesystem]) { + this._elementsValue[filesystem].text = value; + this._elementsUnit[filesystem].text = unit; + } + } + } +); - cleanup_elements() { - this._elementsUuid = []; - this._elementsName = []; - this._elementsValue = []; - this._elementsUnit = []; - this._elementsMemoryValue = []; - this._elementsMemoryUnit = []; - this._elementsThermalValue = []; - this._elementsThermalUnit = []; - - this.remove_all_children(); - } +const GpuContainer = GObject.registerClass( + class GpuContainer extends St.BoxLayout { + _init() { + super._init(); + + this._elementsUuid = []; + this._elementsName = []; + this._elementsValue = []; + this._elementsUnit = []; + this._elementsMemoryValue = []; + this._elementsMemoryUnit = []; + this._elementsThermalValue = []; + this._elementsThermalUnit = []; + } - add_element(uuid, label, usage, memory, thermal) { - this._elementsUuid.push(uuid); + set_element_width(width) { + if (width === 0) { + this._elementsUuid.forEach((element) => { + if (typeof this._elementsValue[element] !== "undefined") { + this._elementsValue[element].min_width = 0; + this._elementsValue[element].natural_width = 0; + this._elementsValue[element].min_width_set = false; + this._elementsValue[element].natural_width_set = false; + } + + if (typeof this._elementsMemoryValue[element] !== "undefined") { + this._elementsMemoryValue[element].min_width = 0; + this._elementsMemoryValue[element].natural_width = 0; + this._elementsMemoryValue[element].min_width_set = false; + this._elementsMemoryValue[element].natural_width_set = false; + } + }); + } else { + this._elementsUuid.forEach((element) => { + if (typeof this._elementsValue[element] !== "undefined") { + this._elementsValue[element].width = width; + } + + if (typeof this._elementsMemoryValue[element] !== "undefined") { + this._elementsMemoryValue[element].width = width; + } + }); + } + } - if (label !== null) { - this._elementsName[uuid] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: ` ${label}: ` - }); - this.add(this._elementsName[uuid]); - } + set_element_thermal_width(width) { + if (width === 0) { + this._elementsUuid.forEach((element) => { + if (typeof this._elementsThermalValue[element] !== "undefined") { + this._elementsThermalValue[element].min_width = 0; + this._elementsThermalValue[element].natural_width = 0; + this._elementsThermalValue[element].min_width_set = false; + this._elementsThermalValue[element].natural_width_set = false; + } + }); + } else { + this._elementsUuid.forEach((element) => { + if (typeof this._elementsThermalValue[element] !== "undefined") { + this._elementsThermalValue[element].width = width; + } + }); + } + } - // Usage - if (usage) { - this._elementsValue[uuid] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '--' - }); - this._elementsValue[uuid].set_style('text-align: right;'); - - this._elementsUnit[uuid] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '%' - }); - this._elementsUnit[uuid].set_style('padding-left: 0.125em;'); - - this.add(new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '[' - })); - this.add(this._elementsValue[uuid]); - this.add(this._elementsUnit[uuid]); - this.add(new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: ']' - })); - } + cleanup_elements() { + this._elementsUuid = []; + this._elementsName = []; + this._elementsValue = []; + this._elementsUnit = []; + this._elementsMemoryValue = []; + this._elementsMemoryUnit = []; + this._elementsThermalValue = []; + this._elementsThermalUnit = []; + + this.remove_all_children(); + } - // Memory - if (memory) { - this._elementsMemoryValue[uuid] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '--' - }); - this._elementsMemoryValue[uuid].set_style('text-align: right;'); - - this._elementsMemoryUnit[uuid] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: this._gpuMemoryUnitType ? '%' : 'KB' - }); - this._elementsMemoryUnit[uuid].set_style('padding-left: 0.125em;'); - - this.add(new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '[' - })); - this.add(this._elementsMemoryValue[uuid]); - this.add(this._elementsMemoryUnit[uuid]); - this.add(new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: ']' - })); - } + add_element(uuid, label, usage, memory, thermal) { + this._elementsUuid.push(uuid); - // Thermal - if (thermal) { - this._elementsThermalValue[uuid] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '--' - }); - this._elementsThermalValue[uuid].set_style('text-align: right;'); - - this._elementsThermalUnit[uuid] = new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '°C' - }); - this._elementsThermalUnit[uuid].set_style('padding-left: 0.125em;'); - - this.add(new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: '[' - })); - this.add(this._elementsThermalValue[uuid]); - this.add(this._elementsThermalUnit[uuid]); - this.add(new St.Label({ - y_align: Clutter.ActorAlign.CENTER, - text: ']' - })); - } - } + if (label !== null) { + this._elementsName[uuid] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: ` ${label}: `, + }); + this.add(this._elementsName[uuid]); + } + + // Usage + if (usage) { + this._elementsValue[uuid] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "--", + }); + this._elementsValue[uuid].set_style("text-align: right;"); - update_element_value(uuid, value, unit) { - if (this._elementsValue[uuid]) { - this._elementsValue[uuid].text = value; - this._elementsUnit[uuid].text = unit; - } - } + this._elementsUnit[uuid] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "%", + }); + this._elementsUnit[uuid].set_style("padding-left: 0.125em;"); + + this.add( + new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "[", + }) + ); + this.add(this._elementsValue[uuid]); + this.add(this._elementsUnit[uuid]); + this.add( + new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "]", + }) + ); + } + + // Memory + if (memory) { + this._elementsMemoryValue[uuid] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "--", + }); + this._elementsMemoryValue[uuid].set_style("text-align: right;"); - update_element_memory_value(uuid, value, unit) { - if (this._elementsMemoryValue[uuid]) { - this._elementsMemoryValue[uuid].text = value; - this._elementsMemoryUnit[uuid].text = unit; - } - } + this._elementsMemoryUnit[uuid] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: this._gpuMemoryUnitType ? "%" : "KB", + }); + this._elementsMemoryUnit[uuid].set_style("padding-left: 0.125em;"); + + this.add( + new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "[", + }) + ); + this.add(this._elementsMemoryValue[uuid]); + this.add(this._elementsMemoryUnit[uuid]); + this.add( + new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "]", + }) + ); + } + + // Thermal + if (thermal) { + this._elementsThermalValue[uuid] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "--", + }); + this._elementsThermalValue[uuid].set_style("text-align: right;"); - update_element_thermal_value(uuid, value, unit) { - if (this._elementsThermalValue[uuid]) { - this._elementsThermalValue[uuid].text = value; - this._elementsThermalUnit[uuid].text = unit; - } - } - }); + this._elementsThermalUnit[uuid] = new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "°C", + }); + this._elementsThermalUnit[uuid].set_style("padding-left: 0.125em;"); + + this.add( + new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "[", + }) + ); + this.add(this._elementsThermalValue[uuid]); + this.add(this._elementsThermalUnit[uuid]); + this.add( + new St.Label({ + y_align: Clutter.ActorAlign.CENTER, + text: "]", + }) + ); + } + } -class Extension { - constructor(uuid) { - this._uuid = uuid; + update_element_value(uuid, value, unit) { + if (this._elementsValue[uuid]) { + this._elementsValue[uuid].text = value; + this._elementsUnit[uuid].text = unit; + } + } - ExtensionUtils.initTranslations(GETTEXT_DOMAIN); + update_element_memory_value(uuid, value, unit) { + if (this._elementsMemoryValue[uuid]) { + this._elementsMemoryValue[uuid].text = value; + this._elementsMemoryUnit[uuid].text = unit; + } } - enable() { - this._settings = ExtensionUtils.getSettings(); - this._indicator = new ResourceMonitor(this._settings); + update_element_thermal_value(uuid, value, unit) { + if (this._elementsThermalValue[uuid]) { + this._elementsThermalValue[uuid].text = value; + this._elementsThermalUnit[uuid].text = unit; + } + } + } +); + +export default class ResourceMonitorExtension extends Extension { + enable() { + this._settings = this.getSettings(); + this._indicator = new ResourceMonitor({ + settings: this._settings, + openPreferences: () => { + this.openPreferences(); + }, + path: this.path, + metadata: this.metadata, + }); - const index = { - left: -1, - center: 0, - right: 0, - }; + const index = { + left: -1, + center: 0, + right: 0, + }; + this._extensionPosition = this._settings.get_string(EXTENSION_POSITION); + this._handlerId = this._settings.connect( + `changed::${EXTENSION_POSITION}`, + () => { this._extensionPosition = this._settings.get_string(EXTENSION_POSITION); - this._handlerId = this._settings.connect(`changed::${EXTENSION_POSITION}`, () => { - this._extensionPosition = this._settings.get_string(EXTENSION_POSITION); - - this._indicator.destroy(); - this._indicator = null; - this._indicator = new ResourceMonitor(this._settings); - - Main.panel.addToStatusArea(this._uuid, this._indicator, index[this._extensionPosition], this._extensionPosition); - }); - - Main.panel.addToStatusArea(this._uuid, this._indicator, index[this._extensionPosition], this._extensionPosition); - } - - disable() { - // Disconnect Signal - this._settings.disconnect(this._handlerId); this._indicator.destroy(); this._indicator = null; - } -} + this._indicator = new ResourceMonitor({ + settings: this._settings, + openPreferences: () => { + this.openPreferences(); + }, + path: this.path, + metadata: this.metadata, + }); -function init(meta) { - return new Extension(meta.uuid); + Main.panel.addToStatusArea( + this.uuid, + this._indicator, + index[this._extensionPosition], + this._extensionPosition + ); + } + ); + + Main.panel.addToStatusArea( + this.uuid, + this._indicator, + index[this._extensionPosition], + this._extensionPosition + ); + } + + disable() { + // Disconnect Signal + this._settings.disconnect(this._handlerId); + this._settings = null; + + this._indicator.destroy(); + this._indicator = null; + } } diff --git a/Resource_Monitor@Ory0n/metadata.json b/Resource_Monitor@Ory0n/metadata.json index 621992f..6e8de2c 100644 --- a/Resource_Monitor@Ory0n/metadata.json +++ b/Resource_Monitor@Ory0n/metadata.json @@ -1,18 +1,14 @@ { - "_generated": "Generated by SweetTooth, do not edit", - "author": "Giuseppe Silvestro", - "description": "Monitor the use of system resources like cpu, ram, disk, network and display them in gnome shell top bar.", - "gettext-domain": "com-github-Ory0n-Resource_Monitor", "name": "Resource Monitor", - "settings-schema": "com.github.Ory0n.Resource_Monitor", + "uuid": "Resource_Monitor@Ory0n", + "description": "Monitor the use of system resources like cpu, ram, disk, network and display them in gnome shell top bar.", "shell-version": [ - "40", - "41", - "42", - "43", - "44" + "45" ], "url": "https://github.com/0ry0n/Resource_Monitor/", - "uuid": "Resource_Monitor@Ory0n", - "version": 19 -} + "donations": { + "paypal": "0ry0n" + }, + "gettext-domain": "com-github-Ory0n-Resource_Monitor", + "settings-schema": "com.github.Ory0n.Resource_Monitor" +} \ No newline at end of file diff --git a/Resource_Monitor@Ory0n/prefs.css b/Resource_Monitor@Ory0n/prefs.css index 05cb6b6..e216e9d 100644 --- a/Resource_Monitor@Ory0n/prefs.css +++ b/Resource_Monitor@Ory0n/prefs.css @@ -1,3 +1,3 @@ .main-label { - font-weight: bold; -} \ No newline at end of file + font-weight: bold; +} diff --git a/Resource_Monitor@Ory0n/prefs.js b/Resource_Monitor@Ory0n/prefs.js index 5fa2695..ed176f4 100644 --- a/Resource_Monitor@Ory0n/prefs.js +++ b/Resource_Monitor@Ory0n/prefs.js @@ -1,5 +1,4 @@ /* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */ -/* exported init, buildPrefsWidget */ /* * Resource_Monitor is Copyright © 2018-2023 Giuseppe Silvestro @@ -20,784 +19,1185 @@ * along with Resource_Monitor. If not, see . */ -'use strict'; +import Gio from "gi://Gio"; +import GObject from "gi://GObject"; +import Gtk from "gi://Gtk"; +import Gdk from "gi://Gdk"; +import Adw from "gi://Adw"; -const GETTEXT_DOMAIN = 'com-github-Ory0n-Resource_Monitor'; - -const { Gio, GObject, Gtk, Gdk, GLib } = imports.gi; - -const ExtensionUtils = imports.misc.extensionUtils; -const ByteArray = imports.byteArray; -const Me = ExtensionUtils.getCurrentExtension(); -const Gettext = imports.gettext; - -const Domain = Gettext.domain(Me.metadata.uuid); - -const _ = Domain.gettext; -const ngettext = Domain.ngettext; +import { + ExtensionPreferences, + gettext as _, +} from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js"; // Settings -const REFRESH_TIME = 'refreshtime'; -const EXTENSION_POSITION = 'extensionposition'; -const DECIMALS_STATUS = 'decimalsstatus'; -const LEFT_CLICK_STATUS = 'leftclickstatus'; -const RIGHT_CLICK_STATUS = 'rightclickstatus'; -const CUSTOM_LEFT_CLICK_STATUS = 'customleftclickstatus'; - -const ICONS_STATUS = 'iconsstatus'; -const ICONS_POSITION = 'iconsposition'; - -const ITEMS_POSITION = 'itemsposition'; - -const CPU_STATUS = 'cpustatus'; -const CPU_WIDTH = 'cpuwidth'; -const CPU_FREQUENCY_STATUS = 'cpufrequencystatus'; -const CPU_FREQUENCY_WIDTH = 'cpufrequencywidth'; -const CPU_FREQUENCY_UNIT_MEASURE = 'cpufrequencyunitmeasure'; -const CPU_LOADAVERAGE_STATUS = 'cpuloadaveragestatus'; -const CPU_LOADAVERAGE_WIDTH = 'cpuloadaveragewidth'; - -const RAM_STATUS = 'ramstatus'; -const RAM_WIDTH = 'ramwidth'; -const RAM_UNIT = 'ramunit'; -const RAM_UNIT_MEASURE = 'ramunitmeasure'; -const RAM_MONITOR = 'rammonitor'; - -const SWAP_STATUS = 'swapstatus'; -const SWAP_WIDTH = 'swapwidth'; -const SWAP_UNIT = 'swapunit'; -const SWAP_UNIT_MEASURE = 'swapunitmeasure'; -const SWAP_MONITOR = 'swapmonitor'; - -const DISK_STATS_STATUS = 'diskstatsstatus'; -const DISK_STATS_WIDTH = 'diskstatswidth'; -const DISK_STATS_MODE = 'diskstatsmode'; -const DISK_STATS_UNIT_MEASURE = 'diskstatsunitmeasure'; -const DISK_SPACE_STATUS = 'diskspacestatus'; -const DISK_SPACE_WIDTH = 'diskspacewidth'; -const DISK_SPACE_UNIT = 'diskspaceunit'; -const DISK_SPACE_UNIT_MEASURE = 'diskspaceunitmeasure'; -const DISK_SPACE_MONITOR = 'diskspacemonitor'; -const DISK_DEVICES_DISPLAY_ALL = 'diskdevicesdisplayall'; -const DISK_DEVICES_LIST = 'diskdeviceslist'; -const DISK_DEVICES_LIST_SEPARATOR = ' '; - -const NET_AUTO_HIDE_STATUS = 'netautohidestatus'; -const NET_UNIT = 'netunit'; -const NET_UNIT_MEASURE = 'netunitmeasure'; -const NET_ETH_STATUS = 'netethstatus'; -const NET_ETH_WIDTH = 'netethwidth'; -const NET_WLAN_STATUS = 'netwlanstatus'; -const NET_WLAN_WIDTH = 'netwlanwidth'; - -const THERMAL_TEMPERATURE_UNIT = 'thermaltemperatureunit'; -const THERMAL_CPU_TEMPERATURE_STATUS = 'thermalcputemperaturestatus'; -const THERMAL_CPU_TEMPERATURE_WIDTH = 'thermalcputemperaturewidth'; -const THERMAL_CPU_TEMPERATURE_DEVICES_LIST = 'thermalcputemperaturedeviceslist'; -const THERMAL_GPU_TEMPERATURE_STATUS = 'thermalgputemperaturestatus'; -const THERMAL_GPU_TEMPERATURE_WIDTH = 'thermalgputemperaturewidth'; -const THERMAL_GPU_TEMPERATURE_DEVICES_LIST = 'thermalgputemperaturedeviceslist'; -const THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR = '-'; - -const GPU_STATUS = 'gpustatus'; -const GPU_WIDTH = 'gpuwidth'; -const GPU_MEMORY_UNIT = 'gpumemoryunit'; -const GPU_MEMORY_UNIT_MEASURE = 'gpumemoryunitmeasure'; -const GPU_MEMORY_MONITOR = 'gpumemorymonitor'; -const GPU_DISPLAY_DEVICE_NAME = 'gpudisplaydevicename' -const GPU_DEVICES_LIST = 'gpudeviceslist'; -const GPU_DEVICES_LIST_SEPARATOR = ':'; - -const ResourceMonitorBuilderScope = GObject.registerClass({ +const REFRESH_TIME = "refreshtime"; +const EXTENSION_POSITION = "extensionposition"; +const DECIMALS_STATUS = "decimalsstatus"; +const LEFT_CLICK_STATUS = "leftclickstatus"; +const RIGHT_CLICK_STATUS = "rightclickstatus"; +const CUSTOM_LEFT_CLICK_STATUS = "customleftclickstatus"; + +const ICONS_STATUS = "iconsstatus"; +const ICONS_POSITION = "iconsposition"; + +const ITEMS_POSITION = "itemsposition"; + +const CPU_STATUS = "cpustatus"; +const CPU_WIDTH = "cpuwidth"; +const CPU_FREQUENCY_STATUS = "cpufrequencystatus"; +const CPU_FREQUENCY_WIDTH = "cpufrequencywidth"; +const CPU_FREQUENCY_UNIT_MEASURE = "cpufrequencyunitmeasure"; +const CPU_LOADAVERAGE_STATUS = "cpuloadaveragestatus"; +const CPU_LOADAVERAGE_WIDTH = "cpuloadaveragewidth"; + +const RAM_STATUS = "ramstatus"; +const RAM_WIDTH = "ramwidth"; +const RAM_UNIT = "ramunit"; +const RAM_UNIT_MEASURE = "ramunitmeasure"; +const RAM_MONITOR = "rammonitor"; + +const SWAP_STATUS = "swapstatus"; +const SWAP_WIDTH = "swapwidth"; +const SWAP_UNIT = "swapunit"; +const SWAP_UNIT_MEASURE = "swapunitmeasure"; +const SWAP_MONITOR = "swapmonitor"; + +const DISK_STATS_STATUS = "diskstatsstatus"; +const DISK_STATS_WIDTH = "diskstatswidth"; +const DISK_STATS_MODE = "diskstatsmode"; +const DISK_STATS_UNIT_MEASURE = "diskstatsunitmeasure"; +const DISK_SPACE_STATUS = "diskspacestatus"; +const DISK_SPACE_WIDTH = "diskspacewidth"; +const DISK_SPACE_UNIT = "diskspaceunit"; +const DISK_SPACE_UNIT_MEASURE = "diskspaceunitmeasure"; +const DISK_SPACE_MONITOR = "diskspacemonitor"; +const DISK_DEVICES_DISPLAY_ALL = "diskdevicesdisplayall"; +const DISK_DEVICES_LIST = "diskdeviceslist"; +const DISK_DEVICES_LIST_SEPARATOR = " "; + +const NET_AUTO_HIDE_STATUS = "netautohidestatus"; +const NET_UNIT = "netunit"; +const NET_UNIT_MEASURE = "netunitmeasure"; +const NET_ETH_STATUS = "netethstatus"; +const NET_ETH_WIDTH = "netethwidth"; +const NET_WLAN_STATUS = "netwlanstatus"; +const NET_WLAN_WIDTH = "netwlanwidth"; + +const THERMAL_TEMPERATURE_UNIT = "thermaltemperatureunit"; +const THERMAL_CPU_TEMPERATURE_STATUS = "thermalcputemperaturestatus"; +const THERMAL_CPU_TEMPERATURE_WIDTH = "thermalcputemperaturewidth"; +const THERMAL_CPU_TEMPERATURE_DEVICES_LIST = "thermalcputemperaturedeviceslist"; +const THERMAL_GPU_TEMPERATURE_STATUS = "thermalgputemperaturestatus"; +const THERMAL_GPU_TEMPERATURE_WIDTH = "thermalgputemperaturewidth"; +const THERMAL_GPU_TEMPERATURE_DEVICES_LIST = "thermalgputemperaturedeviceslist"; +const THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR = "-"; + +const GPU_STATUS = "gpustatus"; +const GPU_WIDTH = "gpuwidth"; +const GPU_MEMORY_UNIT = "gpumemoryunit"; +const GPU_MEMORY_UNIT_MEASURE = "gpumemoryunitmeasure"; +const GPU_MEMORY_MONITOR = "gpumemorymonitor"; +const GPU_DISPLAY_DEVICE_NAME = "gpudisplaydevicename"; +const GPU_DEVICES_LIST = "gpudeviceslist"; +const GPU_DEVICES_LIST_SEPARATOR = ":"; + +const ResourceMonitorBuilderScope = GObject.registerClass( + { Implements: [Gtk.BuilderScope], -}, class ResourceMonitorBuilderScope extends GObject.Object { - + }, + class ResourceMonitorBuilderScope extends GObject.Object { vfunc_create_closure(builder, handlerName, flags, connectObject) { - if (flags & Gtk.BuilderClosureFlags.SWAPPED) - throw new Error('Unsupported template signal flag "swapped"'); + if (flags & Gtk.BuilderClosureFlags.SWAPPED) + throw new Error('Unsupported template signal flag "swapped"'); - if (typeof this[handlerName] === 'undefined') - throw new Error(`${handlerName} is undefined`); + if (typeof this[handlerName] === "undefined") + throw new Error(`${handlerName} is undefined`); - return this[handlerName].bind(connectObject || this); + return this[handlerName].bind(connectObject || this); } -}); + } +); const ResourceMonitorPrefsWidget = GObject.registerClass( - class ResourceMonitorPrefsWidget extends GObject.Object { - _connectSpinButton(settings, settingsName, element) { - settings.bind(settingsName, element, 'value', Gio.SettingsBindFlags.DEFAULT); - } - - _connectComboBox(settings, settingsName, element) { - settings.bind(settingsName, element, 'active-id', Gio.SettingsBindFlags.DEFAULT); - } - - _connectSwitchButton(settings, settingsName, element) { - settings.bind(settingsName, element, 'active', Gio.SettingsBindFlags.DEFAULT); - } - - _init() { - // Gtk Css Provider - this._provider = new Gtk.CssProvider(); - this._provider.load_from_path(Me.dir.get_path() + '/prefs.css'); - Gtk.StyleContext.add_provider_for_display( - Gdk.Display.get_default(), - this._provider, - Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - - // Gtk Builder - this._builder = new Gtk.Builder(); - this._builder.set_scope(new ResourceMonitorBuilderScope()); - this._builder.set_translation_domain(GETTEXT_DOMAIN); - this._builder.add_from_file(Me.dir.get_path() + '/prefs.ui'); - - // Settings - this._settings = ExtensionUtils.getSettings(); + class ResourceMonitorPrefsWidget extends GObject.Object { + _connectSpinButton(settings, settingsName, element) { + settings.bind( + settingsName, + element, + "value", + Gio.SettingsBindFlags.DEFAULT + ); + } - // PREFS - this.notebook = this._builder.get_object('main_notebook'); + _connectComboBox(settings, settingsName, element) { + settings.bind( + settingsName, + element, + "active-id", + Gio.SettingsBindFlags.DEFAULT + ); + } - // GLOBAL FRAME - this._buildGlobal(); + _connectSwitchButton(settings, settingsName, element) { + settings.bind( + settingsName, + element, + "active", + Gio.SettingsBindFlags.DEFAULT + ); + } - // CPU FRAME - this._buildCpu(); + _init({ settings, dir, metadata }) { + this._settings = settings; + this._dir = dir; + this._metadata = metadata; - // RAM FRAME - this._buildRam(); + // Gtk Css Provider + this._provider = new Gtk.CssProvider(); + this._provider.load_from_path(this._dir.get_path() + "/prefs.css"); + Gtk.StyleContext.add_provider_for_display( + Gdk.Display.get_default(), + this._provider, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION + ); - // SWAP FRAME - this._buildSwap(); + // Gtk Builder + this._builder = new Gtk.Builder(); + this._builder.set_scope(new ResourceMonitorBuilderScope()); + this._builder.set_translation_domain(this._metadata["gettext-domain"]); + this._builder.add_from_file(this._dir.get_path() + "/prefs.ui"); - // DISK FRAME - this._buildDisk(); + // PREFS + this.notebook = this._builder.get_object("main_notebook"); - // NET FRAME - this._buildNet(); + // GLOBAL FRAME + this._buildGlobal(); - // THERMAL FRAME - this._buildThermal(); + // CPU FRAME + this._buildCpu(); - // GPU FRAME - this._buildGpu(); - } + // RAM FRAME + this._buildRam(); - _buildGlobal() { - this._secondsSpinbutton = this._builder.get_object('seconds_spinbutton'); - this._extensionPositionCombobox = this._builder.get_object('extension_position_combobox'); - this._extensionLeftClickRadioButtonSM = this._builder.get_object('extension_left_click_radiobutton_sm'); - this._extensionLeftClickRadioButtonU = this._builder.get_object('extension_left_click_radiobutton_u'); - this._extensionLeftClickRadioButtonCustom = this._builder.get_object('extension_left_click_radiobutton_custom'); - this._extensionLeftClickTextViewCustom = this._builder.get_object('extension_left_click_textview_custom'); - this._extensionLeftClickTextViewTextBuffer = this._builder.get_object('extension_left_click_textview_textbuffer'); - this._extensionRightClickPrefs = this._builder.get_object('extension_right_click_prefs'); - this._decimalsDisplay = this._builder.get_object('decimals_display'); - this._iconsDisplay = this._builder.get_object('icons_display') - this._iconsPositionCombobox = this._builder.get_object('icons_position_combobox'); - this._itemsPositionListbox = this._builder.get_object('items_position_listbox') - - this._connectSpinButton(this._settings, REFRESH_TIME, this._secondsSpinbutton); - this._connectComboBox(this._settings, EXTENSION_POSITION, this._extensionPositionCombobox); - this._connectSwitchButton(this._settings, RIGHT_CLICK_STATUS, this._extensionRightClickPrefs); - this._connectSwitchButton(this._settings, DECIMALS_STATUS, this._decimalsDisplay); - this._connectSwitchButton(this._settings, ICONS_STATUS, this._iconsDisplay); - this._connectComboBox(this._settings, ICONS_POSITION, this._iconsPositionCombobox); - - this._iconsDisplay.connect('state-set', button => { - this._iconsPositionCombobox.sensitive = button.active; - }); - this._iconsPositionCombobox.sensitive = this._iconsDisplay.active; + // SWAP FRAME + this._buildSwap(); - // LEFT-CLICK - let active = this._settings.get_string(LEFT_CLICK_STATUS); - let textBufferCustom = this._settings.get_string(CUSTOM_LEFT_CLICK_STATUS); + // DISK FRAME + this._buildDisk(); - this._extensionLeftClickRadioButtonSM.connect('toggled', button => { - if (button.active) { - this._settings.set_string(LEFT_CLICK_STATUS, 'gnome-system-monitor'); - } - }); - this._extensionLeftClickRadioButtonSM.active = ('gnome-system-monitor' === active); + // NET FRAME + this._buildNet(); - this._extensionLeftClickRadioButtonU.connect('toggled', button => { - if (button.active) { - this._settings.set_string(LEFT_CLICK_STATUS, 'gnome-usage'); - } - }); - this._extensionLeftClickRadioButtonU.active = ('gnome-usage' === active); - - this._extensionLeftClickRadioButtonCustom.connect('toggled', button => { - if (button.active) { - this._settings.set_string(LEFT_CLICK_STATUS, textBufferCustom); - } - this._extensionLeftClickTextViewCustom.sensitive = button.active; - }); - this._extensionLeftClickRadioButtonCustom.active = (textBufferCustom === active); - this._extensionLeftClickTextViewCustom.sensitive = this._extensionLeftClickRadioButtonCustom.active; - this._extensionLeftClickTextViewTextBuffer.text = textBufferCustom; + // THERMAL FRAME + this._buildThermal(); - this._extensionLeftClickTextViewTextBuffer.connect('changed', tBuffer => { - this._settings.set_string(LEFT_CLICK_STATUS, tBuffer.text); - this._settings.set_string(CUSTOM_LEFT_CLICK_STATUS, tBuffer.text); - }); - - // ListBox - let itemsPositionArray = this._settings.get_strv(ITEMS_POSITION); - - for (let i = 0; i < itemsPositionArray.length; i++) { - const element = itemsPositionArray[i]; - - let row = new Gtk.ListBoxRow(); - let box = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL }); - - let up = new Gtk.Button({ icon_name: 'go-up' }); - up.connect('clicked', button => { - const index = row.get_index() - if (index > 0) { - [itemsPositionArray[index], itemsPositionArray[index - 1]] = [itemsPositionArray[index - 1], itemsPositionArray[index]]; - this._itemsPositionListbox.remove(row); - this._itemsPositionListbox.insert(row, index - 1); - - this._settings.set_strv(ITEMS_POSITION, itemsPositionArray); - } - }); - let down = new Gtk.Button({ icon_name: 'go-down' }); - down.connect('clicked', button => { - const index = row.get_index() - if (index < itemsPositionArray.length) { - [itemsPositionArray[index], itemsPositionArray[index + 1]] = [itemsPositionArray[index + 1], itemsPositionArray[index]]; - this._itemsPositionListbox.remove(row); - this._itemsPositionListbox.insert(row, index + 1); - - this._settings.set_strv(ITEMS_POSITION, itemsPositionArray); - } - }); - - box.append(new Gtk.Label({ label: element, hexpand: true, halign: Gtk.Align.START })); - box.append(up); - box.append(down); - - row.child = box; + // GPU FRAME + this._buildGpu(); + } - this._itemsPositionListbox.insert(row, i); - } + _buildGlobal() { + this._secondsSpinbutton = this._builder.get_object("seconds_spinbutton"); + this._extensionPositionCombobox = this._builder.get_object( + "extension_position_combobox" + ); + this._extensionLeftClickRadioButtonSM = this._builder.get_object( + "extension_left_click_radiobutton_sm" + ); + this._extensionLeftClickRadioButtonU = this._builder.get_object( + "extension_left_click_radiobutton_u" + ); + this._extensionLeftClickRadioButtonCustom = this._builder.get_object( + "extension_left_click_radiobutton_custom" + ); + this._extensionLeftClickTextViewCustom = this._builder.get_object( + "extension_left_click_textview_custom" + ); + this._extensionLeftClickTextViewTextBuffer = this._builder.get_object( + "extension_left_click_textview_textbuffer" + ); + this._extensionRightClickPrefs = this._builder.get_object( + "extension_right_click_prefs" + ); + this._decimalsDisplay = this._builder.get_object("decimals_display"); + this._iconsDisplay = this._builder.get_object("icons_display"); + this._iconsPositionCombobox = this._builder.get_object( + "icons_position_combobox" + ); + this._itemsPositionListbox = this._builder.get_object( + "items_position_listbox" + ); + + this._connectSpinButton( + this._settings, + REFRESH_TIME, + this._secondsSpinbutton + ); + this._connectComboBox( + this._settings, + EXTENSION_POSITION, + this._extensionPositionCombobox + ); + this._connectSwitchButton( + this._settings, + RIGHT_CLICK_STATUS, + this._extensionRightClickPrefs + ); + this._connectSwitchButton( + this._settings, + DECIMALS_STATUS, + this._decimalsDisplay + ); + this._connectSwitchButton( + this._settings, + ICONS_STATUS, + this._iconsDisplay + ); + this._connectComboBox( + this._settings, + ICONS_POSITION, + this._iconsPositionCombobox + ); + + this._iconsDisplay.connect("state-set", (button) => { + this._iconsPositionCombobox.sensitive = button.active; + }); + this._iconsPositionCombobox.sensitive = this._iconsDisplay.active; + + // LEFT-CLICK + let active = this._settings.get_string(LEFT_CLICK_STATUS); + let textBufferCustom = this._settings.get_string( + CUSTOM_LEFT_CLICK_STATUS + ); + + this._extensionLeftClickRadioButtonSM.connect("toggled", (button) => { + if (button.active) { + this._settings.set_string(LEFT_CLICK_STATUS, "gnome-system-monitor"); } + }); + this._extensionLeftClickRadioButtonSM.active = + "gnome-system-monitor" === active; - _buildCpu() { - this._cpuDisplay = this._builder.get_object('cpu_display'); - this._cpuWidthSpinbutton = this._builder.get_object('cpu_width_spinbutton'); - this._cpuFrequencyDisplay = this._builder.get_object('cpu_frequency_display'); - this._cpuFrequencyWidthSpinbutton = this._builder.get_object('cpu_frequency_width_spinbutton'); - this._cpuFrequencyUnitMeasureCombobox = this._builder.get_object('cpu_frequency_unit_measure_combobox'); - this._cpuLoadAverageDisplay = this._builder.get_object('cpu_loadaverage_display'); - this._cpuLoadAverageWidthSpinbutton = this._builder.get_object('cpu_loadaverage_width_spinbutton'); - - this._connectSwitchButton(this._settings, CPU_STATUS, this._cpuDisplay); - this._connectSpinButton(this._settings, CPU_WIDTH, this._cpuWidthSpinbutton); - this._connectSwitchButton(this._settings, CPU_FREQUENCY_STATUS, this._cpuFrequencyDisplay); - this._connectSpinButton(this._settings, CPU_FREQUENCY_WIDTH, this._cpuFrequencyWidthSpinbutton); - this._connectComboBox(this._settings, CPU_FREQUENCY_UNIT_MEASURE, this._cpuFrequencyUnitMeasureCombobox); - this._connectSwitchButton(this._settings, CPU_LOADAVERAGE_STATUS, this._cpuLoadAverageDisplay); - this._connectSpinButton(this._settings, CPU_LOADAVERAGE_WIDTH, this._cpuLoadAverageWidthSpinbutton); - - this._cpuDisplay.connect('state-set', button => { - this._cpuWidthSpinbutton.sensitive = button.active; - }); - this._cpuWidthSpinbutton.sensitive = this._cpuDisplay.active; - - this._cpuFrequencyDisplay.connect('state-set', button => { - this._cpuFrequencyWidthSpinbutton.sensitive = button.active; - this._cpuFrequencyUnitMeasureCombobox.sensitive = button.active; - }); - this._cpuFrequencyWidthSpinbutton.sensitive = this._cpuFrequencyDisplay.active; - this._cpuFrequencyUnitMeasureCombobox.sensitive = this._cpuFrequencyDisplay.active; - - this._cpuLoadAverageDisplay.connect('state-set', button => { - this._cpuLoadAverageWidthSpinbutton.sensitive = button.active; - }); - this._cpuLoadAverageWidthSpinbutton.sensitive = this._cpuLoadAverageDisplay.active; + this._extensionLeftClickRadioButtonU.connect("toggled", (button) => { + if (button.active) { + this._settings.set_string(LEFT_CLICK_STATUS, "gnome-usage"); } + }); + this._extensionLeftClickRadioButtonU.active = "gnome-usage" === active; - _buildRam() { - this._ramDisplay = this._builder.get_object('ram_display'); - this._ramWidthSpinbutton = this._builder.get_object('ram_width_spinbutton'); - this._ramUnitCombobox = this._builder.get_object('ram_unit_combobox'); - this._ramUnitMeasureCombobox = this._builder.get_object('ram_unit_measure_combobox'); - this._ramMonitorCombobox = this._builder.get_object('ram_monitor_combobox'); - - this._connectSwitchButton(this._settings, RAM_STATUS, this._ramDisplay); - this._connectSpinButton(this._settings, RAM_WIDTH, this._ramWidthSpinbutton); - this._connectComboBox(this._settings, RAM_UNIT, this._ramUnitCombobox); - this._connectComboBox(this._settings, RAM_UNIT_MEASURE, this._ramUnitMeasureCombobox); - this._connectComboBox(this._settings, RAM_MONITOR, this._ramMonitorCombobox); - - this._ramDisplay.connect('state-set', button => { - this._ramWidthSpinbutton.sensitive = button.active; - this._ramUnitCombobox.sensitive = button.active; - this._ramUnitMeasureCombobox.sensitive = button.active; - this._ramMonitorCombobox.sensitive = button.active; - }); - this._ramWidthSpinbutton.sensitive = this._ramDisplay.active; - this._ramUnitCombobox.sensitive = this._ramDisplay.active; - this._ramUnitMeasureCombobox.sensitive = this._ramDisplay.active; - this._ramMonitorCombobox.sensitive = this._ramDisplay.active; + this._extensionLeftClickRadioButtonCustom.connect("toggled", (button) => { + if (button.active) { + this._settings.set_string(LEFT_CLICK_STATUS, textBufferCustom); } - - _buildSwap() { - this._swapDisplay = this._builder.get_object('swap_display'); - this._swapWidthSpinbutton = this._builder.get_object('swap_width_spinbutton'); - this._swapUnitCombobox = this._builder.get_object('swap_unit_combobox'); - this._swapUnitMeasureCombobox = this._builder.get_object('swap_unit_measure_combobox'); - this._swapMonitorCombobox = this._builder.get_object('swap_monitor_combobox'); - - this._connectSwitchButton(this._settings, SWAP_STATUS, this._swapDisplay); - this._connectSpinButton(this._settings, SWAP_WIDTH, this._swapWidthSpinbutton); - this._connectComboBox(this._settings, SWAP_UNIT, this._swapUnitCombobox); - this._connectComboBox(this._settings, SWAP_UNIT_MEASURE, this._swapUnitMeasureCombobox); - this._connectComboBox(this._settings, SWAP_MONITOR, this._swapMonitorCombobox); - - this._swapDisplay.connect('state-set', button => { - this._swapWidthSpinbutton.sensitive = button.active; - this._swapUnitCombobox.sensitive = button.active; - this._swapUnitMeasureCombobox.sensitive = button.active; - this._swapMonitorCombobox.sensitive = button.active; - }); - this._swapWidthSpinbutton.sensitive = this._swapDisplay.active; - this._swapUnitCombobox.sensitive = this._swapDisplay.active; - this._swapUnitMeasureCombobox.sensitive = this._swapDisplay.active; - this._swapMonitorCombobox.sensitive = this._swapDisplay.active; + this._extensionLeftClickTextViewCustom.sensitive = button.active; + }); + this._extensionLeftClickRadioButtonCustom.active = + textBufferCustom === active; + this._extensionLeftClickTextViewCustom.sensitive = + this._extensionLeftClickRadioButtonCustom.active; + this._extensionLeftClickTextViewTextBuffer.text = textBufferCustom; + + this._extensionLeftClickTextViewTextBuffer.connect( + "changed", + (tBuffer) => { + this._settings.set_string(LEFT_CLICK_STATUS, tBuffer.text); + this._settings.set_string(CUSTOM_LEFT_CLICK_STATUS, tBuffer.text); } + ); + + // ListBox + let itemsPositionArray = this._settings.get_strv(ITEMS_POSITION); + + for (let i = 0; i < itemsPositionArray.length; i++) { + const element = itemsPositionArray[i]; + + let row = new Gtk.ListBoxRow(); + let box = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL }); + + let up = new Gtk.Button({ icon_name: "go-up" }); + up.connect("clicked", (button) => { + const index = row.get_index(); + if (index > 0) { + [itemsPositionArray[index], itemsPositionArray[index - 1]] = [ + itemsPositionArray[index - 1], + itemsPositionArray[index], + ]; + this._itemsPositionListbox.remove(row); + this._itemsPositionListbox.insert(row, index - 1); + + this._settings.set_strv(ITEMS_POSITION, itemsPositionArray); + } + }); + let down = new Gtk.Button({ icon_name: "go-down" }); + down.connect("clicked", (button) => { + const index = row.get_index(); + if (index < itemsPositionArray.length) { + [itemsPositionArray[index], itemsPositionArray[index + 1]] = [ + itemsPositionArray[index + 1], + itemsPositionArray[index], + ]; + this._itemsPositionListbox.remove(row); + this._itemsPositionListbox.insert(row, index + 1); + + this._settings.set_strv(ITEMS_POSITION, itemsPositionArray); + } + }); + + box.append( + new Gtk.Label({ + label: element, + hexpand: true, + halign: Gtk.Align.START, + }) + ); + box.append(up); + box.append(down); + + row.child = box; + + this._itemsPositionListbox.insert(row, i); + } + } - _buildDisk() { - this._diskStatsDisplay = this._builder.get_object('disk_stats_display'); - this._diskStatsWidthSpinbutton = this._builder.get_object('disk_stats_width_spinbutton'); - this._diskStatsModeCombobox = this._builder.get_object('disk_stats_mode_combobox'); - this._diskStatsUnitMeasureCombobox = this._builder.get_object('disk_stats_unit_measure_combobox'); - this._diskSpaceDisplay = this._builder.get_object('disk_space_display'); - this._diskSpaceWidthSpinbutton = this._builder.get_object('disk_space_width_spinbutton'); - this._diskSpaceUnitCombobox = this._builder.get_object('disk_space_unit_combobox'); - this._diskSpaceUnitMeasureCombobox = this._builder.get_object('disk_space_unit_measure_combobox'); - this._diskSpaceMonitorCombobox = this._builder.get_object('disk_space_monitor_combobox'); - this._diskDevicesDisplayAll = this._builder.get_object('disk_devices_display_all'); - this._diskDevicesTreeView = this._builder.get_object('disk_devices_treeview') - - this._connectSwitchButton(this._settings, DISK_STATS_STATUS, this._diskStatsDisplay); - this._connectSpinButton(this._settings, DISK_STATS_WIDTH, this._diskStatsWidthSpinbutton); - this._connectComboBox(this._settings, DISK_STATS_MODE, this._diskStatsModeCombobox); - this._connectComboBox(this._settings, DISK_STATS_UNIT_MEASURE, this._diskStatsUnitMeasureCombobox); - this._connectSwitchButton(this._settings, DISK_SPACE_STATUS, this._diskSpaceDisplay); - this._connectSpinButton(this._settings, DISK_SPACE_WIDTH, this._diskSpaceWidthSpinbutton); - this._connectComboBox(this._settings, DISK_SPACE_UNIT, this._diskSpaceUnitCombobox); - this._connectComboBox(this._settings, DISK_SPACE_UNIT_MEASURE, this._diskSpaceUnitMeasureCombobox); - this._connectComboBox(this._settings, DISK_SPACE_MONITOR, this._diskSpaceMonitorCombobox); - this._connectSwitchButton(this._settings, DISK_DEVICES_DISPLAY_ALL, this._diskDevicesDisplayAll); - - this._diskStatsDisplay.connect('state-set', button => { - this._diskStatsWidthSpinbutton.sensitive = button.active; - this._diskStatsModeCombobox.sensitive = button.active; - this._diskStatsUnitMeasureCombobox.sensitive = button.active; - }); - this._diskStatsWidthSpinbutton.sensitive = this._diskStatsDisplay.active; - this._diskStatsModeCombobox.sensitive = this._diskStatsDisplay.active; - this._diskStatsUnitMeasureCombobox.sensitive = this._diskStatsDisplay.active; - - this._diskSpaceDisplay.connect('state-set', button => { - this._diskSpaceWidthSpinbutton.sensitive = button.active; - this._diskSpaceUnitCombobox.sensitive = button.active; - this._diskSpaceMonitorCombobox.sensitive = button.active; - this._diskSpaceUnitMeasureCombobox.sensitive = button.active; - }); - this._diskSpaceWidthSpinbutton.sensitive = this._diskSpaceDisplay.active; - this._diskSpaceUnitCombobox.sensitive = this._diskSpaceDisplay.active; - this._diskSpaceMonitorCombobox.sensitive = this._diskSpaceDisplay.active; - this._diskSpaceUnitMeasureCombobox.sensitive = this._diskSpaceDisplay.active; - - // TreeView - this._disk_devices_model = new Gtk.ListStore(); - this._disk_devices_model.set_column_types([GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_BOOLEAN, GObject.TYPE_BOOLEAN]); - - this._diskDevicesTreeView.set_model(this._disk_devices_model); - - let deviceCol = this._diskDevicesTreeView.get_column(0); - let mountPointCol = this._diskDevicesTreeView.get_column(1); - let statsCol = this._diskDevicesTreeView.get_column(2); - let spaceCol = this._diskDevicesTreeView.get_column(3); - - let empty = new Gtk.TreeViewColumn(); - empty.pack_start(new Gtk.CellRendererText(), true); - this._diskDevicesTreeView.append_column(empty); - - let deviceColText = new Gtk.CellRendererText(); - deviceCol.pack_start(deviceColText, false); - deviceCol.add_attribute(deviceColText, 'text', 0); - - let mountPointColText = new Gtk.CellRendererText(); - mountPointCol.pack_start(mountPointColText, false); - mountPointCol.add_attribute(mountPointColText, 'text', 1); + _buildCpu() { + this._cpuDisplay = this._builder.get_object("cpu_display"); + this._cpuWidthSpinbutton = this._builder.get_object( + "cpu_width_spinbutton" + ); + this._cpuFrequencyDisplay = this._builder.get_object( + "cpu_frequency_display" + ); + this._cpuFrequencyWidthSpinbutton = this._builder.get_object( + "cpu_frequency_width_spinbutton" + ); + this._cpuFrequencyUnitMeasureCombobox = this._builder.get_object( + "cpu_frequency_unit_measure_combobox" + ); + this._cpuLoadAverageDisplay = this._builder.get_object( + "cpu_loadaverage_display" + ); + this._cpuLoadAverageWidthSpinbutton = this._builder.get_object( + "cpu_loadaverage_width_spinbutton" + ); + + this._connectSwitchButton(this._settings, CPU_STATUS, this._cpuDisplay); + this._connectSpinButton( + this._settings, + CPU_WIDTH, + this._cpuWidthSpinbutton + ); + this._connectSwitchButton( + this._settings, + CPU_FREQUENCY_STATUS, + this._cpuFrequencyDisplay + ); + this._connectSpinButton( + this._settings, + CPU_FREQUENCY_WIDTH, + this._cpuFrequencyWidthSpinbutton + ); + this._connectComboBox( + this._settings, + CPU_FREQUENCY_UNIT_MEASURE, + this._cpuFrequencyUnitMeasureCombobox + ); + this._connectSwitchButton( + this._settings, + CPU_LOADAVERAGE_STATUS, + this._cpuLoadAverageDisplay + ); + this._connectSpinButton( + this._settings, + CPU_LOADAVERAGE_WIDTH, + this._cpuLoadAverageWidthSpinbutton + ); + + this._cpuDisplay.connect("state-set", (button) => { + this._cpuWidthSpinbutton.sensitive = button.active; + }); + this._cpuWidthSpinbutton.sensitive = this._cpuDisplay.active; + + this._cpuFrequencyDisplay.connect("state-set", (button) => { + this._cpuFrequencyWidthSpinbutton.sensitive = button.active; + this._cpuFrequencyUnitMeasureCombobox.sensitive = button.active; + }); + this._cpuFrequencyWidthSpinbutton.sensitive = + this._cpuFrequencyDisplay.active; + this._cpuFrequencyUnitMeasureCombobox.sensitive = + this._cpuFrequencyDisplay.active; + + this._cpuLoadAverageDisplay.connect("state-set", (button) => { + this._cpuLoadAverageWidthSpinbutton.sensitive = button.active; + }); + this._cpuLoadAverageWidthSpinbutton.sensitive = + this._cpuLoadAverageDisplay.active; + } - let statsColToggle = new Gtk.CellRendererToggle(); - statsCol.pack_start(statsColToggle, false); - statsCol.add_attribute(statsColToggle, 'active', 2); - statsColToggle.connect('toggled', (toggle, row) => { - let treeiter = this._disk_devices_model.get_iter_from_string(row.toString()); // bool, iter + _buildRam() { + this._ramDisplay = this._builder.get_object("ram_display"); + this._ramWidthSpinbutton = this._builder.get_object( + "ram_width_spinbutton" + ); + this._ramUnitCombobox = this._builder.get_object("ram_unit_combobox"); + this._ramUnitMeasureCombobox = this._builder.get_object( + "ram_unit_measure_combobox" + ); + this._ramMonitorCombobox = this._builder.get_object( + "ram_monitor_combobox" + ); + + this._connectSwitchButton(this._settings, RAM_STATUS, this._ramDisplay); + this._connectSpinButton( + this._settings, + RAM_WIDTH, + this._ramWidthSpinbutton + ); + this._connectComboBox(this._settings, RAM_UNIT, this._ramUnitCombobox); + this._connectComboBox( + this._settings, + RAM_UNIT_MEASURE, + this._ramUnitMeasureCombobox + ); + this._connectComboBox( + this._settings, + RAM_MONITOR, + this._ramMonitorCombobox + ); + + this._ramDisplay.connect("state-set", (button) => { + this._ramWidthSpinbutton.sensitive = button.active; + this._ramUnitCombobox.sensitive = button.active; + this._ramUnitMeasureCombobox.sensitive = button.active; + this._ramMonitorCombobox.sensitive = button.active; + }); + this._ramWidthSpinbutton.sensitive = this._ramDisplay.active; + this._ramUnitCombobox.sensitive = this._ramDisplay.active; + this._ramUnitMeasureCombobox.sensitive = this._ramDisplay.active; + this._ramMonitorCombobox.sensitive = this._ramDisplay.active; + } - this._disk_devices_model.set_value(treeiter[1], 2, !toggle.active); - }); + _buildSwap() { + this._swapDisplay = this._builder.get_object("swap_display"); + this._swapWidthSpinbutton = this._builder.get_object( + "swap_width_spinbutton" + ); + this._swapUnitCombobox = this._builder.get_object("swap_unit_combobox"); + this._swapUnitMeasureCombobox = this._builder.get_object( + "swap_unit_measure_combobox" + ); + this._swapMonitorCombobox = this._builder.get_object( + "swap_monitor_combobox" + ); + + this._connectSwitchButton(this._settings, SWAP_STATUS, this._swapDisplay); + this._connectSpinButton( + this._settings, + SWAP_WIDTH, + this._swapWidthSpinbutton + ); + this._connectComboBox(this._settings, SWAP_UNIT, this._swapUnitCombobox); + this._connectComboBox( + this._settings, + SWAP_UNIT_MEASURE, + this._swapUnitMeasureCombobox + ); + this._connectComboBox( + this._settings, + SWAP_MONITOR, + this._swapMonitorCombobox + ); + + this._swapDisplay.connect("state-set", (button) => { + this._swapWidthSpinbutton.sensitive = button.active; + this._swapUnitCombobox.sensitive = button.active; + this._swapUnitMeasureCombobox.sensitive = button.active; + this._swapMonitorCombobox.sensitive = button.active; + }); + this._swapWidthSpinbutton.sensitive = this._swapDisplay.active; + this._swapUnitCombobox.sensitive = this._swapDisplay.active; + this._swapUnitMeasureCombobox.sensitive = this._swapDisplay.active; + this._swapMonitorCombobox.sensitive = this._swapDisplay.active; + } - let spaceColToggle = new Gtk.CellRendererToggle(); - spaceColToggle.connect('toggled', (toggle, row) => { - let treeiter = this._disk_devices_model.get_iter_from_string(row.toString()); // bool, iter + _buildDisk() { + this._diskStatsDisplay = this._builder.get_object("disk_stats_display"); + this._diskStatsWidthSpinbutton = this._builder.get_object( + "disk_stats_width_spinbutton" + ); + this._diskStatsModeCombobox = this._builder.get_object( + "disk_stats_mode_combobox" + ); + this._diskStatsUnitMeasureCombobox = this._builder.get_object( + "disk_stats_unit_measure_combobox" + ); + this._diskSpaceDisplay = this._builder.get_object("disk_space_display"); + this._diskSpaceWidthSpinbutton = this._builder.get_object( + "disk_space_width_spinbutton" + ); + this._diskSpaceUnitCombobox = this._builder.get_object( + "disk_space_unit_combobox" + ); + this._diskSpaceUnitMeasureCombobox = this._builder.get_object( + "disk_space_unit_measure_combobox" + ); + this._diskSpaceMonitorCombobox = this._builder.get_object( + "disk_space_monitor_combobox" + ); + this._diskDevicesDisplayAll = this._builder.get_object( + "disk_devices_display_all" + ); + this._diskDevicesTreeView = this._builder.get_object( + "disk_devices_treeview" + ); + + this._connectSwitchButton( + this._settings, + DISK_STATS_STATUS, + this._diskStatsDisplay + ); + this._connectSpinButton( + this._settings, + DISK_STATS_WIDTH, + this._diskStatsWidthSpinbutton + ); + this._connectComboBox( + this._settings, + DISK_STATS_MODE, + this._diskStatsModeCombobox + ); + this._connectComboBox( + this._settings, + DISK_STATS_UNIT_MEASURE, + this._diskStatsUnitMeasureCombobox + ); + this._connectSwitchButton( + this._settings, + DISK_SPACE_STATUS, + this._diskSpaceDisplay + ); + this._connectSpinButton( + this._settings, + DISK_SPACE_WIDTH, + this._diskSpaceWidthSpinbutton + ); + this._connectComboBox( + this._settings, + DISK_SPACE_UNIT, + this._diskSpaceUnitCombobox + ); + this._connectComboBox( + this._settings, + DISK_SPACE_UNIT_MEASURE, + this._diskSpaceUnitMeasureCombobox + ); + this._connectComboBox( + this._settings, + DISK_SPACE_MONITOR, + this._diskSpaceMonitorCombobox + ); + this._connectSwitchButton( + this._settings, + DISK_DEVICES_DISPLAY_ALL, + this._diskDevicesDisplayAll + ); + + this._diskStatsDisplay.connect("state-set", (button) => { + this._diskStatsWidthSpinbutton.sensitive = button.active; + this._diskStatsModeCombobox.sensitive = button.active; + this._diskStatsUnitMeasureCombobox.sensitive = button.active; + }); + this._diskStatsWidthSpinbutton.sensitive = this._diskStatsDisplay.active; + this._diskStatsModeCombobox.sensitive = this._diskStatsDisplay.active; + this._diskStatsUnitMeasureCombobox.sensitive = + this._diskStatsDisplay.active; + + this._diskSpaceDisplay.connect("state-set", (button) => { + this._diskSpaceWidthSpinbutton.sensitive = button.active; + this._diskSpaceUnitCombobox.sensitive = button.active; + this._diskSpaceMonitorCombobox.sensitive = button.active; + this._diskSpaceUnitMeasureCombobox.sensitive = button.active; + }); + this._diskSpaceWidthSpinbutton.sensitive = this._diskSpaceDisplay.active; + this._diskSpaceUnitCombobox.sensitive = this._diskSpaceDisplay.active; + this._diskSpaceMonitorCombobox.sensitive = this._diskSpaceDisplay.active; + this._diskSpaceUnitMeasureCombobox.sensitive = + this._diskSpaceDisplay.active; + + // TreeView + this._disk_devices_model = new Gtk.ListStore(); + this._disk_devices_model.set_column_types([ + GObject.TYPE_STRING, + GObject.TYPE_STRING, + GObject.TYPE_BOOLEAN, + GObject.TYPE_BOOLEAN, + ]); + + this._diskDevicesTreeView.set_model(this._disk_devices_model); + + let deviceCol = this._diskDevicesTreeView.get_column(0); + let mountPointCol = this._diskDevicesTreeView.get_column(1); + let statsCol = this._diskDevicesTreeView.get_column(2); + let spaceCol = this._diskDevicesTreeView.get_column(3); + + let empty = new Gtk.TreeViewColumn(); + empty.pack_start(new Gtk.CellRendererText(), true); + this._diskDevicesTreeView.append_column(empty); + + let deviceColText = new Gtk.CellRendererText(); + deviceCol.pack_start(deviceColText, false); + deviceCol.add_attribute(deviceColText, "text", 0); + + let mountPointColText = new Gtk.CellRendererText(); + mountPointCol.pack_start(mountPointColText, false); + mountPointCol.add_attribute(mountPointColText, "text", 1); + + let statsColToggle = new Gtk.CellRendererToggle(); + statsCol.pack_start(statsColToggle, false); + statsCol.add_attribute(statsColToggle, "active", 2); + statsColToggle.connect("toggled", (toggle, row) => { + let treeiter = this._disk_devices_model.get_iter_from_string( + row.toString() + ); // bool, iter + + this._disk_devices_model.set_value(treeiter[1], 2, !toggle.active); + }); + + let spaceColToggle = new Gtk.CellRendererToggle(); + spaceColToggle.connect("toggled", (toggle, row) => { + let treeiter = this._disk_devices_model.get_iter_from_string( + row.toString() + ); // bool, iter + + this._disk_devices_model.set_value(treeiter[1], 3, !toggle.active); + }); + spaceCol.pack_start(spaceColToggle, false); + spaceCol.add_attribute(spaceColToggle, "active", 3); + + this._disk_devices_model.connect("row-changed", (list, path, iter) => { + let row = path.get_indices()[0]; + let disksArray = this._settings.get_strv(DISK_DEVICES_LIST); + disksArray[row] = + list.get_value(iter, 0) + + DISK_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 1) + + DISK_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 2) + + DISK_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 3); + this._settings.set_strv(DISK_DEVICES_LIST, disksArray); + }); + + this._diskDevicesDisplayAll.connect("state-set", (button) => { + // Refresh + this._readDiskDevices( + this._settings, + this._disk_devices_model, + button.active + ); + }); + + this._readDiskDevices( + this._settings, + this._disk_devices_model, + this._diskDevicesDisplayAll.active + ); + } - this._disk_devices_model.set_value(treeiter[1], 3, !toggle.active); - }); - spaceCol.pack_start(spaceColToggle, false); - spaceCol.add_attribute(spaceColToggle, 'active', 3); - - this._disk_devices_model.connect('row-changed', (list, path, iter) => { - let row = path.get_indices()[0]; - let disksArray = this._settings.get_strv(DISK_DEVICES_LIST); - disksArray[row] = list.get_value(iter, 0) + DISK_DEVICES_LIST_SEPARATOR + list.get_value(iter, 1) + DISK_DEVICES_LIST_SEPARATOR + list.get_value(iter, 2) + DISK_DEVICES_LIST_SEPARATOR + list.get_value(iter, 3); - this._settings.set_strv(DISK_DEVICES_LIST, disksArray); - }); + _readDiskDevices(settings, model, all) { + model.clear(); + // Array format + // filesystem mountPoint stats space + // Get current disks settings + let disksArray = settings.get_strv(DISK_DEVICES_LIST); - this._diskDevicesDisplayAll.connect('state-set', button => { - // Refresh - this._readDiskDevices(this._settings, this._disk_devices_model, button.active); - }); + this._executeCommand(["df", "-x", "squashfs", "-x", "tmpfs"]).then( + (output) => { + let lines = output.split("\n"); - this._readDiskDevices(this._settings, this._disk_devices_model, this._diskDevicesDisplayAll.active); - } + // Excludes the first line of output + for (let i = 1; i < lines.length - 1; i++) { + let line = lines[i]; + let entry = line.trim().split(/\s+/); - _readDiskDevices(settings, model, all) { - model.clear(); - // Array format - // filesystem mountPoint stats space - // Get current disks settings - let disksArray = settings.get_strv(DISK_DEVICES_LIST); + let filesystem = entry[0]; + let mountedOn = entry[5]; - this._executeCommand(['df', '-x', 'squashfs', '-x', 'tmpfs']).then(output => { - let lines = output.split('\n'); + let dStButton = false; + let dSpButton = false; - // Excludes the first line of output - for (let i = 1; i < lines.length - 1; i++) { - let line = lines[i]; - let entry = line.trim().split(/\s+/); + // Init gui + for (let i = 0; i < disksArray.length; i++) { + let element = disksArray[i]; - let filesystem = entry[0]; - let mountedOn = entry[5]; + let it = element.split(DISK_DEVICES_LIST_SEPARATOR); - let dStButton = false; - let dSpButton = false; + if (filesystem === it[0]) { + dStButton = it[2] === "true"; + dSpButton = it[3] === "true"; - // Init gui - for (let i = 0; i < disksArray.length; i++) { - let element = disksArray[i]; + break; + } + } - let it = element.split(DISK_DEVICES_LIST_SEPARATOR); + model.set( + model.append(), + [0, 1, 2, 3], + [filesystem, mountedOn, dStButton, dSpButton] + ); + } - if (filesystem === it[0]) { - dStButton = (it[2] === 'true'); - dSpButton = (it[3] === 'true'); + if (all) { + this._loadFile("/proc/diskstats").then((contents) => { + const lines = new TextDecoder().decode(contents).split("\n"); - break; - } - } + for (let i = 0; i < lines.length - 1; i++) { + const line = lines[i]; + const entry = line.trim().split(/\s+/); - model.set(model.append(), [0, 1, 2, 3], [filesystem, mountedOn, dStButton, dSpButton]); + if (entry[2].match(/loop*/)) { + continue; } - if (all) { - this._loadFile('/proc/diskstats').then(contents => { - const lines = ByteArray.toString(contents).split('\n'); + let found = false; + const fs = "/dev/" + entry[2]; + model.foreach((list, path, iter) => { + const filesystem = list.get_value(iter, 0); - for (let i = 0; i < lines.length - 1; i++) { - const line = lines[i]; - const entry = line.trim().split(/\s+/); - - if (entry[2].match(/loop*/)) { - continue; - } + if (fs === filesystem) { + found = true; - let found = false; - const fs = '/dev/' + entry[2]; - model.foreach((list, path, iter) => { - const filesystem = list.get_value(iter, 0); - - if (fs === filesystem) { - found = true; - - return; - } - }); + return; + } + }); - if (found) { - // nothing - } else { - let dStButton = false; - let dSpButton = false; // slways false + if (found) { + // nothing + } else { + let dStButton = false; + let dSpButton = false; // slways false - // Init gui - for (let i = 0; i < disksArray.length; i++) { - let element = disksArray[i]; + // Init gui + for (let i = 0; i < disksArray.length; i++) { + let element = disksArray[i]; - let it = element.split(DISK_DEVICES_LIST_SEPARATOR); + let it = element.split(DISK_DEVICES_LIST_SEPARATOR); - if (fs === it[0]) { - dStButton = (it[2] === 'true'); - dSpButton = (it[3] === 'true'); + if (fs === it[0]) { + dStButton = it[2] === "true"; + dSpButton = it[3] === "true"; - break; - } - } - - model.set(model.append(), [0, 1, 2, 3], [fs, '', dStButton, dSpButton]); - } - } + break; + } + } - // Save new disksArray with the list of new disks (to remove old disks) - disksArray = []; - model.foreach((list, path, iter) => { - disksArray.push(list.get_value(iter, 0) + DISK_DEVICES_LIST_SEPARATOR + list.get_value(iter, 1) + DISK_DEVICES_LIST_SEPARATOR + list.get_value(iter, 2) + DISK_DEVICES_LIST_SEPARATOR + list.get_value(iter, 3)); - }); - settings.set_strv(DISK_DEVICES_LIST, disksArray); - }); - } else { - // Save new disksArray with the list of new disks (to remove old disks) - disksArray = []; - model.foreach((list, path, iter) => { - disksArray.push(list.get_value(iter, 0) + DISK_DEVICES_LIST_SEPARATOR + list.get_value(iter, 1) + DISK_DEVICES_LIST_SEPARATOR + list.get_value(iter, 2) + DISK_DEVICES_LIST_SEPARATOR + list.get_value(iter, 3)); - }); - settings.set_strv(DISK_DEVICES_LIST, disksArray); + model.set( + model.append(), + [0, 1, 2, 3], + [fs, "", dStButton, dSpButton] + ); } + } + + // Save new disksArray with the list of new disks (to remove old disks) + disksArray = []; + model.foreach((list, path, iter) => { + disksArray.push( + list.get_value(iter, 0) + + DISK_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 1) + + DISK_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 2) + + DISK_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 3) + ); + }); + settings.set_strv(DISK_DEVICES_LIST, disksArray); }); - } - - _buildNet() { - this._netAutoHide = this._builder.get_object('net_auto_hide'); - this._netUnitCombobox = this._builder.get_object('net_unit_combobox'); - this._netUnitMeasureCombobox = this._builder.get_object('net_unit_measure_combobox'); - this._netEthDisplay = this._builder.get_object('net_eth_display'); - this._netEthWidthSpinbutton = this._builder.get_object('net_eth_width_spinbutton'); - this._netWlanDisplay = this._builder.get_object('net_wlan_display'); - this._netWlanWidthSpinbutton = this._builder.get_object('net_wlan_width_spinbutton'); - - this._connectSwitchButton(this._settings, NET_AUTO_HIDE_STATUS, this._netAutoHide); - this._connectComboBox(this._settings, NET_UNIT, this._netUnitCombobox); - this._connectComboBox(this._settings, NET_UNIT_MEASURE, this._netUnitMeasureCombobox); - this._connectSwitchButton(this._settings, NET_ETH_STATUS, this._netEthDisplay); - this._connectSpinButton(this._settings, NET_ETH_WIDTH, this._netEthWidthSpinbutton); - this._connectSwitchButton(this._settings, NET_WLAN_STATUS, this._netWlanDisplay); - this._connectSpinButton(this._settings, NET_WLAN_WIDTH, this._netWlanWidthSpinbutton); - - this._netEthDisplay.connect('state-set', button => { - this._netEthWidthSpinbutton.sensitive = button.active; - }); - this._netEthWidthSpinbutton.sensitive = this._netEthDisplay.active; - - this._netWlanDisplay.connect('state-set', button => { - this._netWlanWidthSpinbutton.sensitive = button.active; + } else { + // Save new disksArray with the list of new disks (to remove old disks) + disksArray = []; + model.foreach((list, path, iter) => { + disksArray.push( + list.get_value(iter, 0) + + DISK_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 1) + + DISK_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 2) + + DISK_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 3) + ); }); - this._netWlanWidthSpinbutton.sensitive = this._netWlanDisplay.active; + settings.set_strv(DISK_DEVICES_LIST, disksArray); + } } + ); + } - _buildThermal() { - this._thermalUnitCombobox = this._builder.get_object('thermal_unit_combobox'); - this._thermalCpuDisplay = this._builder.get_object('thermal_cpu_display'); - this._thermalCpuWidthSpinbutton = this._builder.get_object('thermal_cpu_width_spinbutton'); - this._thermalCpuDevicesTreeView = this._builder.get_object('thermal_cpu_devices_treeview'); - this._thermalGpuDisplay = this._builder.get_object('thermal_gpu_display'); - this._thermalGpuWidthSpinbutton = this._builder.get_object('thermal_gpu_width_spinbutton'); - this._thermalGpuDevicesTreeView = this._builder.get_object('thermal_gpu_devices_treeview'); - - this._connectComboBox(this._settings, THERMAL_TEMPERATURE_UNIT, this._thermalUnitCombobox); - this._connectSwitchButton(this._settings, THERMAL_CPU_TEMPERATURE_STATUS, this._thermalCpuDisplay); - this._connectSpinButton(this._settings, THERMAL_CPU_TEMPERATURE_WIDTH, this._thermalCpuWidthSpinbutton); - this._connectSwitchButton(this._settings, THERMAL_GPU_TEMPERATURE_STATUS, this._thermalGpuDisplay); - this._connectSpinButton(this._settings, THERMAL_GPU_TEMPERATURE_WIDTH, this._thermalGpuWidthSpinbutton); - - this._thermalCpuDisplay.connect('state-set', button => { - this._thermalCpuWidthSpinbutton.sensitive = button.active; - }); - this._thermalCpuWidthSpinbutton.sensitive = this._thermalCpuDisplay.active; - - this._thermalGpuDisplay.connect('state-set', button => { - this._thermalGpuWidthSpinbutton.sensitive = button.active; - }); - this._thermalGpuWidthSpinbutton.sensitive = this._thermalGpuDisplay.active; - - // TreeView - this._thermalCpuDevicesModel = new Gtk.ListStore(); - this._thermalCpuDevicesModel.set_column_types([GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_BOOLEAN]); - - this._thermalCpuDevicesTreeView.set_model(this._thermalCpuDevicesModel); - - let cpuDeviceCol = this._thermalCpuDevicesTreeView.get_column(0); - let cpuNameCol = this._thermalCpuDevicesTreeView.get_column(1); - let cpuMonitorCol = this._thermalCpuDevicesTreeView.get_column(2); - - let empty = new Gtk.TreeViewColumn(); - empty.pack_start(new Gtk.CellRendererText(), true); - this._thermalCpuDevicesTreeView.append_column(empty); - - let deviceColText = new Gtk.CellRendererText(); - cpuDeviceCol.pack_start(deviceColText, false); - cpuDeviceCol.add_attribute(deviceColText, 'text', 0); - - let nameColText = new Gtk.CellRendererText(); - cpuNameCol.pack_start(nameColText, false); - cpuNameCol.add_attribute(nameColText, 'text', 1); - - let monitorColToggle = new Gtk.CellRendererToggle(); - cpuMonitorCol.pack_start(monitorColToggle, false); - cpuMonitorCol.add_attribute(monitorColToggle, 'active', 2); - monitorColToggle.connect('toggled', (toggle, row) => { - let treeiter = this._thermalCpuDevicesModel.get_iter_from_string(row.toString()); // bool, iter - - this._thermalCpuDevicesModel.set_value(treeiter[1], 2, !toggle.active); - }); - - this._thermalCpuDevicesModel.connect('row-changed', (list, path, iter) => { - let row = path.get_indices()[0]; - let cpuTempsArray = this._settings.get_strv(THERMAL_CPU_TEMPERATURE_DEVICES_LIST); - cpuTempsArray[row] = list.get_value(iter, 1) + THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR + list.get_value(iter, 2) + THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR + list.get_value(iter, 0); - this._settings.set_strv(THERMAL_CPU_TEMPERATURE_DEVICES_LIST, cpuTempsArray); - }); - - // Array format - // name-status-path - // Get current disks settings - let cpuTempsArray = this._settings.get_strv(THERMAL_CPU_TEMPERATURE_DEVICES_LIST); - - // Detect sensors - //let command = 'for i in /sys/class/hwmon/hwmon*/temp*_input; do echo "$(<$(dirname $i)/name): $(cat ${i%_*}_label 2>/dev/null || echo $(basename ${i%_*})) $(readlink -f $i)"; done'; - - this._executeCommand(['bash', '-c', 'if ls /sys/class/hwmon/hwmon*/temp*_input 1>/dev/null 2>&1; then echo "EXIST"; fi']).then(output => { - let result = output.split('\n')[0]; - if (result === 'EXIST') { - this._executeCommand(['bash', '-c', 'for i in /sys/class/hwmon/hwmon*/temp*_input; do NAME="$(<$(dirname $i)/name)"; if [[ "$NAME" == "coretemp" ]] || [[ "$NAME" == "k10temp" ]]; then echo "$NAME: $(cat ${i%_*}_label 2>/dev/null || echo $(basename ${i%_*}))-$i"; fi done']).then(output => { - let lines = output.split('\n'); - - for (let i = 0; i < lines.length - 1; i++) { - let line = lines[i]; - let entry = line.trim().split(/-/); - - let device = entry[0]; - let path = entry[1]; - - let statusButton = false; - - // Init gui - for (let i = 0; i < cpuTempsArray.length; i++) { - let element = cpuTempsArray[i]; - let it = element.split(THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR); - - if (device === it[0]) { - statusButton = (it[1] === 'true'); - - break; - } - } - - this._thermalCpuDevicesModel.set(this._thermalCpuDevicesModel.append(), [0, 1, 2], [path, device, statusButton]); - } + _buildNet() { + this._netAutoHide = this._builder.get_object("net_auto_hide"); + this._netUnitCombobox = this._builder.get_object("net_unit_combobox"); + this._netUnitMeasureCombobox = this._builder.get_object( + "net_unit_measure_combobox" + ); + this._netEthDisplay = this._builder.get_object("net_eth_display"); + this._netEthWidthSpinbutton = this._builder.get_object( + "net_eth_width_spinbutton" + ); + this._netWlanDisplay = this._builder.get_object("net_wlan_display"); + this._netWlanWidthSpinbutton = this._builder.get_object( + "net_wlan_width_spinbutton" + ); + + this._connectSwitchButton( + this._settings, + NET_AUTO_HIDE_STATUS, + this._netAutoHide + ); + this._connectComboBox(this._settings, NET_UNIT, this._netUnitCombobox); + this._connectComboBox( + this._settings, + NET_UNIT_MEASURE, + this._netUnitMeasureCombobox + ); + this._connectSwitchButton( + this._settings, + NET_ETH_STATUS, + this._netEthDisplay + ); + this._connectSpinButton( + this._settings, + NET_ETH_WIDTH, + this._netEthWidthSpinbutton + ); + this._connectSwitchButton( + this._settings, + NET_WLAN_STATUS, + this._netWlanDisplay + ); + this._connectSpinButton( + this._settings, + NET_WLAN_WIDTH, + this._netWlanWidthSpinbutton + ); + + this._netEthDisplay.connect("state-set", (button) => { + this._netEthWidthSpinbutton.sensitive = button.active; + }); + this._netEthWidthSpinbutton.sensitive = this._netEthDisplay.active; + + this._netWlanDisplay.connect("state-set", (button) => { + this._netWlanWidthSpinbutton.sensitive = button.active; + }); + this._netWlanWidthSpinbutton.sensitive = this._netWlanDisplay.active; + } - // Save new cpuTempsArray with the list of new devices (to remove old devices) - cpuTempsArray = []; - this._thermalCpuDevicesModel.foreach((list, path, iter) => { - cpuTempsArray.push(list.get_value(iter, 1) + THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR + list.get_value(iter, 2) + THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR + list.get_value(iter, 0)); - }); - this._settings.set_strv(THERMAL_CPU_TEMPERATURE_DEVICES_LIST, cpuTempsArray); - }); + _buildThermal() { + this._thermalUnitCombobox = this._builder.get_object( + "thermal_unit_combobox" + ); + this._thermalCpuDisplay = this._builder.get_object("thermal_cpu_display"); + this._thermalCpuWidthSpinbutton = this._builder.get_object( + "thermal_cpu_width_spinbutton" + ); + this._thermalCpuDevicesTreeView = this._builder.get_object( + "thermal_cpu_devices_treeview" + ); + this._thermalGpuDisplay = this._builder.get_object("thermal_gpu_display"); + this._thermalGpuWidthSpinbutton = this._builder.get_object( + "thermal_gpu_width_spinbutton" + ); + this._thermalGpuDevicesTreeView = this._builder.get_object( + "thermal_gpu_devices_treeview" + ); + + this._connectComboBox( + this._settings, + THERMAL_TEMPERATURE_UNIT, + this._thermalUnitCombobox + ); + this._connectSwitchButton( + this._settings, + THERMAL_CPU_TEMPERATURE_STATUS, + this._thermalCpuDisplay + ); + this._connectSpinButton( + this._settings, + THERMAL_CPU_TEMPERATURE_WIDTH, + this._thermalCpuWidthSpinbutton + ); + this._connectSwitchButton( + this._settings, + THERMAL_GPU_TEMPERATURE_STATUS, + this._thermalGpuDisplay + ); + this._connectSpinButton( + this._settings, + THERMAL_GPU_TEMPERATURE_WIDTH, + this._thermalGpuWidthSpinbutton + ); + + this._thermalCpuDisplay.connect("state-set", (button) => { + this._thermalCpuWidthSpinbutton.sensitive = button.active; + }); + this._thermalCpuWidthSpinbutton.sensitive = + this._thermalCpuDisplay.active; + + this._thermalGpuDisplay.connect("state-set", (button) => { + this._thermalGpuWidthSpinbutton.sensitive = button.active; + }); + this._thermalGpuWidthSpinbutton.sensitive = + this._thermalGpuDisplay.active; + + // TreeView + this._thermalCpuDevicesModel = new Gtk.ListStore(); + this._thermalCpuDevicesModel.set_column_types([ + GObject.TYPE_STRING, + GObject.TYPE_STRING, + GObject.TYPE_BOOLEAN, + ]); + + this._thermalCpuDevicesTreeView.set_model(this._thermalCpuDevicesModel); + + let cpuDeviceCol = this._thermalCpuDevicesTreeView.get_column(0); + let cpuNameCol = this._thermalCpuDevicesTreeView.get_column(1); + let cpuMonitorCol = this._thermalCpuDevicesTreeView.get_column(2); + + let empty = new Gtk.TreeViewColumn(); + empty.pack_start(new Gtk.CellRendererText(), true); + this._thermalCpuDevicesTreeView.append_column(empty); + + let deviceColText = new Gtk.CellRendererText(); + cpuDeviceCol.pack_start(deviceColText, false); + cpuDeviceCol.add_attribute(deviceColText, "text", 0); + + let nameColText = new Gtk.CellRendererText(); + cpuNameCol.pack_start(nameColText, false); + cpuNameCol.add_attribute(nameColText, "text", 1); + + let monitorColToggle = new Gtk.CellRendererToggle(); + cpuMonitorCol.pack_start(monitorColToggle, false); + cpuMonitorCol.add_attribute(monitorColToggle, "active", 2); + monitorColToggle.connect("toggled", (toggle, row) => { + let treeiter = this._thermalCpuDevicesModel.get_iter_from_string( + row.toString() + ); // bool, iter + + this._thermalCpuDevicesModel.set_value(treeiter[1], 2, !toggle.active); + }); + + this._thermalCpuDevicesModel.connect( + "row-changed", + (list, path, iter) => { + let row = path.get_indices()[0]; + let cpuTempsArray = this._settings.get_strv( + THERMAL_CPU_TEMPERATURE_DEVICES_LIST + ); + cpuTempsArray[row] = + list.get_value(iter, 1) + + THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 2) + + THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 0); + this._settings.set_strv( + THERMAL_CPU_TEMPERATURE_DEVICES_LIST, + cpuTempsArray + ); + } + ); + + // Array format + // name-status-path + // Get current disks settings + let cpuTempsArray = this._settings.get_strv( + THERMAL_CPU_TEMPERATURE_DEVICES_LIST + ); + + // Detect sensors + //let command = 'for i in /sys/class/hwmon/hwmon*/temp*_input; do echo "$(<$(dirname $i)/name): $(cat ${i%_*}_label 2>/dev/null || echo $(basename ${i%_*})) $(readlink -f $i)"; done'; + + this._executeCommand([ + "bash", + "-c", + 'if ls /sys/class/hwmon/hwmon*/temp*_input 1>/dev/null 2>&1; then echo "EXIST"; fi', + ]).then((output) => { + let result = output.split("\n")[0]; + if (result === "EXIST") { + this._executeCommand([ + "bash", + "-c", + 'for i in /sys/class/hwmon/hwmon*/temp*_input; do NAME="$(<$(dirname $i)/name)"; if [[ "$NAME" == "coretemp" ]] || [[ "$NAME" == "k10temp" ]]; then echo "$NAME: $(cat ${i%_*}_label 2>/dev/null || echo $(basename ${i%_*}))-$i"; fi done', + ]).then((output) => { + let lines = output.split("\n"); + + for (let i = 0; i < lines.length - 1; i++) { + let line = lines[i]; + let entry = line.trim().split(/-/); + + let device = entry[0]; + let path = entry[1]; + + let statusButton = false; + + // Init gui + for (let i = 0; i < cpuTempsArray.length; i++) { + let element = cpuTempsArray[i]; + let it = element.split( + THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR + ); + + if (device === it[0]) { + statusButton = it[1] === "true"; + + break; } - }); - - // GPU - this._thermalGpuDevicesModel = new Gtk.ListStore(); - this._thermalGpuDevicesModel.set_column_types([GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_BOOLEAN]); - - this._thermalGpuDevicesTreeView.set_model(this._thermalGpuDevicesModel); - - let gpuDeviceCol = this._thermalGpuDevicesTreeView.get_column(0); - let gpuNameCol = this._thermalGpuDevicesTreeView.get_column(1); - let gpuMonitorCol = this._thermalGpuDevicesTreeView.get_column(2); - - empty = new Gtk.TreeViewColumn(); - empty.pack_start(new Gtk.CellRendererText(), true); - this._thermalGpuDevicesTreeView.append_column(empty); - - let gpuDeviceColText = new Gtk.CellRendererText(); - gpuDeviceCol.pack_start(gpuDeviceColText, false); - gpuDeviceCol.add_attribute(gpuDeviceColText, 'text', 0); + } - let gpuNameColText = new Gtk.CellRendererText(); - gpuNameCol.pack_start(gpuNameColText, false); - gpuNameCol.add_attribute(gpuNameColText, 'text', 1); - - let gpuMonitorColToggle = new Gtk.CellRendererToggle(); - gpuMonitorCol.pack_start(gpuMonitorColToggle, false); - gpuMonitorCol.add_attribute(gpuMonitorColToggle, 'active', 2); - gpuMonitorColToggle.connect('toggled', (toggle, row) => { - let treeiter = this._thermalGpuDevicesModel.get_iter_from_string(row.toString()); // bool, iter - - this._thermalGpuDevicesModel.set_value(treeiter[1], 2, !toggle.active); - }); + this._thermalCpuDevicesModel.set( + this._thermalCpuDevicesModel.append(), + [0, 1, 2], + [path, device, statusButton] + ); + } - this._thermalGpuDevicesModel.connect('row-changed', (list, path, iter) => { - let row = path.get_indices()[0]; - let gpuTempsArray = this._settings.get_strv(THERMAL_GPU_TEMPERATURE_DEVICES_LIST); - gpuTempsArray[row] = list.get_value(iter, 0) + GPU_DEVICES_LIST_SEPARATOR + list.get_value(iter, 1) + GPU_DEVICES_LIST_SEPARATOR + list.get_value(iter, 2); - this._settings.set_strv(THERMAL_GPU_TEMPERATURE_DEVICES_LIST, gpuTempsArray); + // Save new cpuTempsArray with the list of new devices (to remove old devices) + cpuTempsArray = []; + this._thermalCpuDevicesModel.foreach((list, path, iter) => { + cpuTempsArray.push( + list.get_value(iter, 1) + + THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 2) + + THERMAL_CPU_TEMPERATURE_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 0) + ); }); + this._settings.set_strv( + THERMAL_CPU_TEMPERATURE_DEVICES_LIST, + cpuTempsArray + ); + }); + } + }); + + // GPU + this._thermalGpuDevicesModel = new Gtk.ListStore(); + this._thermalGpuDevicesModel.set_column_types([ + GObject.TYPE_STRING, + GObject.TYPE_STRING, + GObject.TYPE_BOOLEAN, + ]); + + this._thermalGpuDevicesTreeView.set_model(this._thermalGpuDevicesModel); + + let gpuDeviceCol = this._thermalGpuDevicesTreeView.get_column(0); + let gpuNameCol = this._thermalGpuDevicesTreeView.get_column(1); + let gpuMonitorCol = this._thermalGpuDevicesTreeView.get_column(2); + + empty = new Gtk.TreeViewColumn(); + empty.pack_start(new Gtk.CellRendererText(), true); + this._thermalGpuDevicesTreeView.append_column(empty); + + let gpuDeviceColText = new Gtk.CellRendererText(); + gpuDeviceCol.pack_start(gpuDeviceColText, false); + gpuDeviceCol.add_attribute(gpuDeviceColText, "text", 0); + + let gpuNameColText = new Gtk.CellRendererText(); + gpuNameCol.pack_start(gpuNameColText, false); + gpuNameCol.add_attribute(gpuNameColText, "text", 1); + + let gpuMonitorColToggle = new Gtk.CellRendererToggle(); + gpuMonitorCol.pack_start(gpuMonitorColToggle, false); + gpuMonitorCol.add_attribute(gpuMonitorColToggle, "active", 2); + gpuMonitorColToggle.connect("toggled", (toggle, row) => { + let treeiter = this._thermalGpuDevicesModel.get_iter_from_string( + row.toString() + ); // bool, iter + + this._thermalGpuDevicesModel.set_value(treeiter[1], 2, !toggle.active); + }); + + this._thermalGpuDevicesModel.connect( + "row-changed", + (list, path, iter) => { + let row = path.get_indices()[0]; + let gpuTempsArray = this._settings.get_strv( + THERMAL_GPU_TEMPERATURE_DEVICES_LIST + ); + gpuTempsArray[row] = + list.get_value(iter, 0) + + GPU_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 1) + + GPU_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 2); + this._settings.set_strv( + THERMAL_GPU_TEMPERATURE_DEVICES_LIST, + gpuTempsArray + ); + } + ); - // Array format - // uuid:name:status - // Get current disks settings - let gpuTempsArray = this._settings.get_strv(THERMAL_GPU_TEMPERATURE_DEVICES_LIST); - - // NVIDIA - this._executeCommand(['nvidia-smi', '-L']).then(output => { - let lines = output.split('\n'); + // Array format + // uuid:name:status + // Get current disks settings + let gpuTempsArray = this._settings.get_strv( + THERMAL_GPU_TEMPERATURE_DEVICES_LIST + ); - for (let i = 0; i < lines.length - 1; i++) { - let line = lines[i]; - let entry = line.trim().split(/:/); + // NVIDIA + this._executeCommand(["nvidia-smi", "-L"]).then((output) => { + let lines = output.split("\n"); - let device = entry[0]; - let name = entry[1].slice(1, -6); - let uuid = entry[2].slice(1, -1); + for (let i = 0; i < lines.length - 1; i++) { + let line = lines[i]; + let entry = line.trim().split(/:/); - let statusButton = false; + let device = entry[0]; + let name = entry[1].slice(1, -6); + let uuid = entry[2].slice(1, -1); - // Init gui - for (let i = 0; i < gpuTempsArray.length; i++) { - let element = gpuTempsArray[i]; - let it = element.split(GPU_DEVICES_LIST_SEPARATOR); + let statusButton = false; - if (uuid === it[0]) { - statusButton = (it[2] === 'true'); + // Init gui + for (let i = 0; i < gpuTempsArray.length; i++) { + let element = gpuTempsArray[i]; + let it = element.split(GPU_DEVICES_LIST_SEPARATOR); - break; - } - } + if (uuid === it[0]) { + statusButton = it[2] === "true"; - this._thermalGpuDevicesModel.set(this._thermalGpuDevicesModel.append(), [0, 1, 2], [uuid, name, statusButton]); - } + break; + } + } - // Save new gpuTempsArray with the list of new devices (to remove old devices) - gpuTempsArray = []; - this._thermalGpuDevicesModel.foreach((list, path, iter) => { - gpuTempsArray.push(list.get_value(iter, 0) + GPU_DEVICES_LIST_SEPARATOR + list.get_value(iter, 1) + GPU_DEVICES_LIST_SEPARATOR + list.get_value(iter, 2)); - }); - this._settings.set_strv(THERMAL_GPU_TEMPERATURE_DEVICES_LIST, gpuTempsArray); - }); + this._thermalGpuDevicesModel.set( + this._thermalGpuDevicesModel.append(), + [0, 1, 2], + [uuid, name, statusButton] + ); + } - // AMD - //this._executeCommand(['bash', '-c', 'if ls /sys/class/hwmon/hwmon*/temp*_input 1>/dev/null 2>&1; then echo "EXIST"; fi']).then(output => { - // let result = output.split('\n')[0]; - // if (result === 'EXIST') { - // this._executeCommand(['bash', '-c', 'for i in /sys/class/hwmon/hwmon*/temp*_input; do NAME="$(<$(dirname $i)/name)"; if [[ "$NAME" == "amdgpu" ]]; then echo "$NAME: $(cat ${i%_*}_label 2>/dev/null || echo $(basename ${i%_*}))-$i"; fi done']).then(output => { - /* let lines = output.split('\n'); + // Save new gpuTempsArray with the list of new devices (to remove old devices) + gpuTempsArray = []; + this._thermalGpuDevicesModel.foreach((list, path, iter) => { + gpuTempsArray.push( + list.get_value(iter, 0) + + GPU_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 1) + + GPU_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 2) + ); + }); + this._settings.set_strv( + THERMAL_GPU_TEMPERATURE_DEVICES_LIST, + gpuTempsArray + ); + }); + + // AMD + //this._executeCommand(['bash', '-c', 'if ls /sys/class/hwmon/hwmon*/temp*_input 1>/dev/null 2>&1; then echo "EXIST"; fi']).then(output => { + // let result = output.split('\n')[0]; + // if (result === 'EXIST') { + // this._executeCommand(['bash', '-c', 'for i in /sys/class/hwmon/hwmon*/temp*_input; do NAME="$(<$(dirname $i)/name)"; if [[ "$NAME" == "amdgpu" ]]; then echo "$NAME: $(cat ${i%_*}_label 2>/dev/null || echo $(basename ${i%_*}))-$i"; fi done']).then(output => { + /* let lines = output.split('\n'); for (let i = 0; i < lines.length - 1; i++) { let line = lines[i]; @@ -833,191 +1233,260 @@ const ResourceMonitorPrefsWidget = GObject.registerClass( } }); */ - } - - _buildGpu() { - this._gpuDisplay = this._builder.get_object('gpu_display'); - this._gpuWidthSpinbutton = this._builder.get_object('gpu_width_spinbutton'); - this._gpuMemoryUnitCombobox = this._builder.get_object('gpu_memory_unit_combobox'); - this._gpuMemoryUnitMeasureCombobox = this._builder.get_object('gpu_memory_unit_measure_combobox'); - this._gpuMemoryMonitorCombobox = this._builder.get_object('gpu_memory_monitor_combobox'); - this._gpuDisplayDeviceName = this._builder.get_object('gpu_display_device_name'); - this._gpuDevicesTreeView = this._builder.get_object('gpu_devices_treeview'); - - this._connectSwitchButton(this._settings, GPU_STATUS, this._gpuDisplay); - this._connectSpinButton(this._settings, GPU_WIDTH, this._gpuWidthSpinbutton); - this._connectComboBox(this._settings, GPU_MEMORY_UNIT, this._gpuMemoryUnitCombobox); - this._connectComboBox(this._settings, GPU_MEMORY_UNIT_MEASURE, this._gpuMemoryUnitMeasureCombobox); - this._connectComboBox(this._settings, GPU_MEMORY_MONITOR, this._gpuMemoryMonitorCombobox); - this._connectSwitchButton(this._settings, GPU_DISPLAY_DEVICE_NAME, this._gpuDisplayDeviceName); - - this._gpuDisplay.connect('state-set', button => { - this._gpuWidthSpinbutton.sensitive = button.active; - this._gpuMemoryUnitCombobox.sensitive = button.active; - this._gpuMemoryUnitMeasureCombobox.sensitive = button.active; - this._gpuMemoryMonitorCombobox.sensitive = button.active; - this._gpuDisplayDeviceName.sensitive = button.active; - }); - this._gpuWidthSpinbutton.sensitive = this._gpuDisplay.active; - this._gpuMemoryUnitCombobox.sensitive = this._gpuDisplay.active; - this._gpuMemoryUnitMeasureCombobox.sensitive = this._gpuDisplay.active; - this._gpuMemoryMonitorCombobox.sensitive = this._gpuDisplay.active; - this._gpuDisplayDeviceName.sensitive = this._gpuDisplay.active; - - // TreeView - this._gpuDevicesModel = new Gtk.ListStore(); - this._gpuDevicesModel.set_column_types([GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_BOOLEAN, GObject.TYPE_BOOLEAN]); - - this._gpuDevicesTreeView.set_model(this._gpuDevicesModel); - - let gpuDeviceCol = this._gpuDevicesTreeView.get_column(0); - let gpuNameCol = this._gpuDevicesTreeView.get_column(1); - let gpuUsageMonitorCol = this._gpuDevicesTreeView.get_column(2); - let gpuMemoryMonitorCol = this._gpuDevicesTreeView.get_column(3); - - let empty = new Gtk.TreeViewColumn(); - empty.pack_start(new Gtk.CellRendererText(), true); - this._gpuDevicesTreeView.append_column(empty); - - let gpuDeviceColText = new Gtk.CellRendererText(); - gpuDeviceCol.pack_start(gpuDeviceColText, false); - gpuDeviceCol.add_attribute(gpuDeviceColText, 'text', 0); - - let gpuNameColText = new Gtk.CellRendererText(); - gpuNameCol.pack_start(gpuNameColText, false); - gpuNameCol.add_attribute(gpuNameColText, 'text', 1); - - let gpuUsageMonitorColToggle = new Gtk.CellRendererToggle(); - gpuUsageMonitorCol.pack_start(gpuUsageMonitorColToggle, false); - gpuUsageMonitorCol.add_attribute(gpuUsageMonitorColToggle, 'active', 2); - gpuUsageMonitorColToggle.connect('toggled', (toggle, row) => { - let treeiter = this._gpuDevicesModel.get_iter_from_string(row.toString()); // bool, iter - - this._gpuDevicesModel.set_value(treeiter[1], 2, !toggle.active); - }); - - let gpuMemoryMonitorColToggle = new Gtk.CellRendererToggle(); - gpuMemoryMonitorCol.pack_start(gpuMemoryMonitorColToggle, false); - gpuMemoryMonitorCol.add_attribute(gpuMemoryMonitorColToggle, 'active', 3); - gpuMemoryMonitorColToggle.connect('toggled', (toggle, row) => { - let treeiter = this._gpuDevicesModel.get_iter_from_string(row.toString()); // bool, iter - - this._gpuDevicesModel.set_value(treeiter[1], 3, !toggle.active); - }); - - this._gpuDevicesModel.connect('row-changed', (list, path, iter) => { - let row = path.get_indices()[0]; - let gpuDevicesArray = this._settings.get_strv(GPU_DEVICES_LIST); - gpuDevicesArray[row] = list.get_value(iter, 0) + GPU_DEVICES_LIST_SEPARATOR + list.get_value(iter, 1) + GPU_DEVICES_LIST_SEPARATOR + list.get_value(iter, 2) + GPU_DEVICES_LIST_SEPARATOR + list.get_value(iter, 3); - this._settings.set_strv(GPU_DEVICES_LIST, gpuDevicesArray); - }); - - // Array format - // uuid:name:usage:memory - // Get current disks settings - let gpuDevicesArray = this._settings.get_strv(GPU_DEVICES_LIST); - - this._executeCommand(['nvidia-smi', '-L']).then(output => { - let lines = output.split('\n'); - - for (let i = 0; i < lines.length - 1; i++) { - let line = lines[i]; - let entry = line.trim().split(/:/); - - let device = entry[0]; - let name = entry[1].slice(1, -6); - let uuid = entry[2].slice(1, -1); - - let usageButton = false; - let memoryButton = false; - - // Init gui - for (let i = 0; i < gpuDevicesArray.length; i++) { - let element = gpuDevicesArray[i]; - let it = element.split(GPU_DEVICES_LIST_SEPARATOR); - - if (uuid === it[0]) { - usageButton = (it[2] === 'true'); - memoryButton = (it[3] === 'true'); - - break; - } - } - - this._gpuDevicesModel.set(this._gpuDevicesModel.append(), [0, 1, 2, 3], [uuid, name, usageButton, memoryButton]); - } - - // Save new gpuTempsArray with the list of new devices (to remove old devices) - gpuDevicesArray = []; - this._gpuDevicesModel.foreach((list, path, iter) => { - gpuDevicesArray.push(list.get_value(iter, 0) + GPU_DEVICES_LIST_SEPARATOR + list.get_value(iter, 1) + GPU_DEVICES_LIST_SEPARATOR + list.get_value(iter, 2) + GPU_DEVICES_LIST_SEPARATOR + list.get_value(iter, 3)); - }); - this._settings.set_strv(GPU_DEVICES_LIST, gpuDevicesArray); - }); - } + } - _loadContents(file, cancellable = null) { - return new Promise((resolve, reject) => { - file.load_contents_async(cancellable, (source_object, res) => { - try { - const [ok, contents, etag_out] = source_object.load_contents_finish(res); + _buildGpu() { + this._gpuDisplay = this._builder.get_object("gpu_display"); + this._gpuWidthSpinbutton = this._builder.get_object( + "gpu_width_spinbutton" + ); + this._gpuMemoryUnitCombobox = this._builder.get_object( + "gpu_memory_unit_combobox" + ); + this._gpuMemoryUnitMeasureCombobox = this._builder.get_object( + "gpu_memory_unit_measure_combobox" + ); + this._gpuMemoryMonitorCombobox = this._builder.get_object( + "gpu_memory_monitor_combobox" + ); + this._gpuDisplayDeviceName = this._builder.get_object( + "gpu_display_device_name" + ); + this._gpuDevicesTreeView = this._builder.get_object( + "gpu_devices_treeview" + ); + + this._connectSwitchButton(this._settings, GPU_STATUS, this._gpuDisplay); + this._connectSpinButton( + this._settings, + GPU_WIDTH, + this._gpuWidthSpinbutton + ); + this._connectComboBox( + this._settings, + GPU_MEMORY_UNIT, + this._gpuMemoryUnitCombobox + ); + this._connectComboBox( + this._settings, + GPU_MEMORY_UNIT_MEASURE, + this._gpuMemoryUnitMeasureCombobox + ); + this._connectComboBox( + this._settings, + GPU_MEMORY_MONITOR, + this._gpuMemoryMonitorCombobox + ); + this._connectSwitchButton( + this._settings, + GPU_DISPLAY_DEVICE_NAME, + this._gpuDisplayDeviceName + ); + + this._gpuDisplay.connect("state-set", (button) => { + this._gpuWidthSpinbutton.sensitive = button.active; + this._gpuMemoryUnitCombobox.sensitive = button.active; + this._gpuMemoryUnitMeasureCombobox.sensitive = button.active; + this._gpuMemoryMonitorCombobox.sensitive = button.active; + this._gpuDisplayDeviceName.sensitive = button.active; + }); + this._gpuWidthSpinbutton.sensitive = this._gpuDisplay.active; + this._gpuMemoryUnitCombobox.sensitive = this._gpuDisplay.active; + this._gpuMemoryUnitMeasureCombobox.sensitive = this._gpuDisplay.active; + this._gpuMemoryMonitorCombobox.sensitive = this._gpuDisplay.active; + this._gpuDisplayDeviceName.sensitive = this._gpuDisplay.active; + + // TreeView + this._gpuDevicesModel = new Gtk.ListStore(); + this._gpuDevicesModel.set_column_types([ + GObject.TYPE_STRING, + GObject.TYPE_STRING, + GObject.TYPE_BOOLEAN, + GObject.TYPE_BOOLEAN, + ]); + + this._gpuDevicesTreeView.set_model(this._gpuDevicesModel); + + let gpuDeviceCol = this._gpuDevicesTreeView.get_column(0); + let gpuNameCol = this._gpuDevicesTreeView.get_column(1); + let gpuUsageMonitorCol = this._gpuDevicesTreeView.get_column(2); + let gpuMemoryMonitorCol = this._gpuDevicesTreeView.get_column(3); + + let empty = new Gtk.TreeViewColumn(); + empty.pack_start(new Gtk.CellRendererText(), true); + this._gpuDevicesTreeView.append_column(empty); + + let gpuDeviceColText = new Gtk.CellRendererText(); + gpuDeviceCol.pack_start(gpuDeviceColText, false); + gpuDeviceCol.add_attribute(gpuDeviceColText, "text", 0); + + let gpuNameColText = new Gtk.CellRendererText(); + gpuNameCol.pack_start(gpuNameColText, false); + gpuNameCol.add_attribute(gpuNameColText, "text", 1); + + let gpuUsageMonitorColToggle = new Gtk.CellRendererToggle(); + gpuUsageMonitorCol.pack_start(gpuUsageMonitorColToggle, false); + gpuUsageMonitorCol.add_attribute(gpuUsageMonitorColToggle, "active", 2); + gpuUsageMonitorColToggle.connect("toggled", (toggle, row) => { + let treeiter = this._gpuDevicesModel.get_iter_from_string( + row.toString() + ); // bool, iter + + this._gpuDevicesModel.set_value(treeiter[1], 2, !toggle.active); + }); + + let gpuMemoryMonitorColToggle = new Gtk.CellRendererToggle(); + gpuMemoryMonitorCol.pack_start(gpuMemoryMonitorColToggle, false); + gpuMemoryMonitorCol.add_attribute(gpuMemoryMonitorColToggle, "active", 3); + gpuMemoryMonitorColToggle.connect("toggled", (toggle, row) => { + let treeiter = this._gpuDevicesModel.get_iter_from_string( + row.toString() + ); // bool, iter + + this._gpuDevicesModel.set_value(treeiter[1], 3, !toggle.active); + }); + + this._gpuDevicesModel.connect("row-changed", (list, path, iter) => { + let row = path.get_indices()[0]; + let gpuDevicesArray = this._settings.get_strv(GPU_DEVICES_LIST); + gpuDevicesArray[row] = + list.get_value(iter, 0) + + GPU_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 1) + + GPU_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 2) + + GPU_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 3); + this._settings.set_strv(GPU_DEVICES_LIST, gpuDevicesArray); + }); + + // Array format + // uuid:name:usage:memory + // Get current disks settings + let gpuDevicesArray = this._settings.get_strv(GPU_DEVICES_LIST); + + this._executeCommand(["nvidia-smi", "-L"]).then((output) => { + let lines = output.split("\n"); + + for (let i = 0; i < lines.length - 1; i++) { + let line = lines[i]; + let entry = line.trim().split(/:/); + + let device = entry[0]; + let name = entry[1].slice(1, -6); + let uuid = entry[2].slice(1, -1); + + let usageButton = false; + let memoryButton = false; + + // Init gui + for (let i = 0; i < gpuDevicesArray.length; i++) { + let element = gpuDevicesArray[i]; + let it = element.split(GPU_DEVICES_LIST_SEPARATOR); + + if (uuid === it[0]) { + usageButton = it[2] === "true"; + memoryButton = it[3] === "true"; + + break; + } + } - resolve(contents); - } catch (e) { - reject(e); - } - }); - }); + this._gpuDevicesModel.set( + this._gpuDevicesModel.append(), + [0, 1, 2, 3], + [uuid, name, usageButton, memoryButton] + ); } - async _loadFile(path, cancellable = null) { - try { - const file = Gio.File.new_for_path(path); - const contents = await this._loadContents(file, cancellable); + // Save new gpuTempsArray with the list of new devices (to remove old devices) + gpuDevicesArray = []; + this._gpuDevicesModel.foreach((list, path, iter) => { + gpuDevicesArray.push( + list.get_value(iter, 0) + + GPU_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 1) + + GPU_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 2) + + GPU_DEVICES_LIST_SEPARATOR + + list.get_value(iter, 3) + ); + }); + this._settings.set_strv(GPU_DEVICES_LIST, gpuDevicesArray); + }); + } - return contents; - } catch (error) { - log('[Resource_Monitor] Load File Error (' + error + ')'); - } - } + _loadContents(file, cancellable = null) { + return new Promise((resolve, reject) => { + file.load_contents_async(cancellable, (source_object, res) => { + try { + const [ok, contents, etag_out] = + source_object.load_contents_finish(res); + + resolve(contents); + } catch (e) { + reject(e); + } + }); + }); + } - _readOutput(proc, cancellable = null) { - return new Promise((resolve, reject) => { - proc.communicate_utf8_async(null, cancellable, (source_object, res) => { - try { - const [ok, stdout, stderr] = source_object.communicate_utf8_finish(res); + async _loadFile(path, cancellable = null) { + try { + const file = Gio.File.new_for_path(path); + const contents = await this._loadContents(file, cancellable); - if (source_object.get_successful()) { - resolve(stdout); - } else { - throw new Error(stderr); - } - } catch (e) { - reject(e); - } - }); - }); - } - - async _executeCommand(command, cancellable = null) { - try { - const proc = Gio.Subprocess.new(command, Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE); - const output = await this._readOutput(proc, cancellable); + return contents; + } catch (error) { + console.error("[Resource_Monitor] Load File Error (" + error + ")"); + } + } - return output; - } catch (error) { - log('[Resource_Monitor] Execute Command Error (' + error + ')'); + _readOutput(proc, cancellable = null) { + return new Promise((resolve, reject) => { + proc.communicate_utf8_async(null, cancellable, (source_object, res) => { + try { + const [ok, stdout, stderr] = + source_object.communicate_utf8_finish(res); + + if (source_object.get_successful()) { + resolve(stdout); + } else { + throw new Error(stderr); } - } - }); - -function init() { - ExtensionUtils.initTranslations(GETTEXT_DOMAIN); -} + } catch (e) { + reject(e); + } + }); + }); + } -function buildPrefsWidget() { - const widget = new ResourceMonitorPrefsWidget(); + async _executeCommand(command, cancellable = null) { + try { + const proc = Gio.Subprocess.new( + command, + Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE + ); + const output = await this._readOutput(proc, cancellable); + + return output; + } catch (error) { + console.error( + "[Resource_Monitor] Execute Command Error (" + error + ")" + ); + } + } + } +); + +export default class ResourceMonitorExtensionPreferences extends ExtensionPreferences { + getPreferencesWidget() { + const widget = new ResourceMonitorPrefsWidget({ + settings: this.getSettings(), + dir: this.dir, + metadata: this.metadata, + }); return widget.notebook; + } } -