From b4c3ff5b220cea8c488393eaf25fcc7ac11bb27e Mon Sep 17 00:00:00 2001 From: Alynx Zhou Date: Thu, 30 Sep 2021 15:04:38 +0800 Subject: [PATCH] Fixed read_line return value handling. --- extension.js | 14 ++++---------- metadata.json | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/extension.js b/extension.js index 2c95df7..58eaa09 100644 --- a/extension.js +++ b/extension.js @@ -56,24 +56,18 @@ const getCurrentNetSpeed = (refreshInterval) => { let totalUpBytes = 0; let line = null; // See . - while ((line = dataInputStream.read_line(null)) != null) { + while ((line = dataInputStream.read_line(null)[0]) != null) { // See . - // It seems Uint8Array is only returned at the first time. - if (line instanceof Uint8Array) { - line = ByteArray.toString(line).trim(); - } else { - line = line.toString().trim(); - } - const fields = line.split(/\W+/); + const fields = ByteArray.toString(line).trim().split(/\W+/); if (fields.length <= 2) { - break; + continue; } // Skip virtual interfaces. const interface = fields[0]; const currentInterfaceDownBytes = Number.parseInt(fields[1]); const currentInterfaceUpBytes = Number.parseInt(fields[9]); - if (interface == "lo" || + if (interface === "lo" || // Created by python-based bandwidth manager "traffictoll". interface.match(/^ifb[0-9]+/) || // Created by lxd container manager. diff --git a/metadata.json b/metadata.json index 052b081..a5baf32 100644 --- a/metadata.json +++ b/metadata.json @@ -2,7 +2,7 @@ "name": "Net Speed", "description": "Show current net speed on panel.", "uuid": "netspeed@alynx.one", - "version": 1, + "version": 2, "shell-version": [ "40" ]