From 6d36da1ce66820754d41277f82f7d1b53b803f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 13 Mar 2024 00:00:10 +0100 Subject: [PATCH] system-monitor: Fix net speed We use different formats for values above and below 10, to only include a fraction for the latter. However we use the same factor to determine the format and to compute the number to format, with the result that values above 10 are off by a factor of 10. Address this by adding a separate "unitFactor" value for computing the value. Spotted by Yannick Daveluy. Closes https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/issues/494 Part-of: --- extensions/system-monitor/extension.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/extensions/system-monitor/extension.js b/extensions/system-monitor/extension.js index 0d8f5d5d..37d2eb18 100644 --- a/extensions/system-monitor/extension.js +++ b/extensions/system-monitor/extension.js @@ -193,6 +193,7 @@ class NetStatSection extends StatSection { #formats = [{ factor: 1000, + unitFactor: 1000, formatter: new Intl.NumberFormat(undefined, { style: 'unit', unit: 'kilobyte', @@ -201,6 +202,7 @@ class NetStatSection extends StatSection { }), }, { factor: 1000 * 10, + unitFactor: 1000, formatter: new Intl.NumberFormat(undefined, { style: 'unit', unit: 'kilobyte', @@ -208,6 +210,7 @@ class NetStatSection extends StatSection { }), }, { factor: 1000 * 1000, + unitFactor: 1000 * 1000, formatter: new Intl.NumberFormat(undefined, { style: 'unit', unit: 'megabyte', @@ -216,6 +219,7 @@ class NetStatSection extends StatSection { }), }, { factor: 1000 * 1000 * 10, + unitFactor: 1000 * 1000, formatter: new Intl.NumberFormat(undefined, { style: 'unit', unit: 'megabyte', @@ -223,6 +227,7 @@ class NetStatSection extends StatSection { }), }, { factor: 1000 * 1000 * 1000, + unitFactor: 1000 * 1000 * 1000, formatter: new Intl.NumberFormat(undefined, { style: 'unit', unit: 'gigabyte', @@ -231,6 +236,7 @@ class NetStatSection extends StatSection { }), }, { factor: 1000 * 1000 * 1000 * 10, + unitFactor: 1000 * 1000 * 1000, formatter: new Intl.NumberFormat(undefined, { style: 'unit', unit: 'gigabyte', @@ -238,6 +244,7 @@ class NetStatSection extends StatSection { }), }, { factor: 1000 * 1000 * 1000 * 1000, + unitFactor: 1000 * 1000 * 1000 * 1000, formatter: new Intl.NumberFormat(undefined, { style: 'unit', unit: 'terabyte', @@ -246,6 +253,7 @@ class NetStatSection extends StatSection { }), }, { factor: 1000 * 1000 * 1000 * 1000 * 10, + unitFactor: 1000 * 1000 * 1000 * 1000, formatter: new Intl.NumberFormat(undefined, { style: 'unit', unit: 'terabyte', @@ -253,6 +261,7 @@ class NetStatSection extends StatSection { }), }, { factor: 1000 * 1000 * 1000 * 1000 * 1000, + unitFactor: 1000 * 1000 * 1000 * 1000 * 1000, formatter: new Intl.NumberFormat(undefined, { style: 'unit', unit: 'petabyte', @@ -313,8 +322,8 @@ class NetStatSection extends StatSection { this.#lastTime = time; this.#lastHash = hash; - const {factor, formatter} = this._getFormat(dbytes); - this.label.text = formatter.format(dbytes / factor); + const {unitFactor, formatter} = this._getFormat(dbytes); + this.label.text = formatter.format(dbytes / unitFactor); } }