Skip to content

Commit

Permalink
Fixed read_line return value handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlynxZhou committed Sep 30, 2021
1 parent bb89d71 commit b4c3ff5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,18 @@ const getCurrentNetSpeed = (refreshInterval) => {
let totalUpBytes = 0;
let line = null;
// See <https://gjs-docs.gnome.org/gio20~2.66p/gio.datainputstream#method-read_line>.
while ((line = dataInputStream.read_line(null)) != null) {
while ((line = dataInputStream.read_line(null)[0]) != null) {
// See <https://github.com/GNOME/gjs/blob/master/doc/ByteArray.md#tostringauint8array-encodingstringstring>.
// 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.
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Net Speed",
"description": "Show current net speed on panel.",
"uuid": "[email protected]",
"version": 1,
"version": 2,
"shell-version": [
"40"
]
Expand Down

0 comments on commit b4c3ff5

Please sign in to comment.