From 7ea9da877caf69b5f1a2303120743c8cfd00e53e Mon Sep 17 00:00:00 2001 From: mirkol Date: Fri, 15 Dec 2017 19:36:21 +0100 Subject: [PATCH 1/2] New modes (total uploaded and total transferred), font-size and width fix and some slight performance improvement --- README.md | 6 ++- extension.js | 111 +++++++++++++++++++------------------------------- metadata.json | 40 ++++++++---------- 3 files changed, 63 insertions(+), 94 deletions(-) diff --git a/README.md b/README.md index e9bdd80..d07e1a8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# Simple net speed -Gnome extension to show network speed +# Simple net speed +Gnome extension to show network speed, version forked from https://github.com/biji/simplenetspeed, added last 2 functions, adjusted font-size and width and slight performance improvement. https://extensions.gnome.org/extension/1085/simple-net-speed/ @@ -10,5 +10,7 @@ Simply showing network speed. Left click to change modes: 1. Up & down speed in bits per second 1. Up & down speed in Bytes per second 1. Total of downloaded in Bytes (Right click to reset counter) +1. Total of uploaded bytes (Right click to reset all counters) +1. Total bytes transferred (Right click to reset all counters) Middle click to change font size diff --git a/extension.js b/extension.js index dd07669..e587ae2 100644 --- a/extension.js +++ b/extension.js @@ -9,24 +9,28 @@ const ExtensionUtils = imports.misc.extensionUtils; const Me = ExtensionUtils.getCurrentExtension(); const Convenience = Me.imports.convenience; +const PanelMenu = imports.ui.panelMenu; +const PopupMenu = imports.ui.popupMenu; +const Slider = imports.ui.slider; + const PREFS_SCHEMA = 'org.gnome.shell.extensions.simplenetspeed'; const refreshTime = 3.0; let settings; let button, timeout; -// let icon, iconDark; let ioSpeed; let lastCount = 0, lastSpeed = 0, lastCountUp = 0; let mode; // 0: kbps 1: K/s 2: U:kbps D:kbps 3: U:K/s D:K/s 4: Total KB let fontmode; -let resetNextCount = false, resetCount = 0; +let resetNextCount = false, resetCount = 0, resetCountUp = 0; +let speed_map; function init() { settings = Convenience.getSettings(PREFS_SCHEMA); mode = settings.get_int('mode'); // default mode using bit (bps, kbps) - fontmode = settings.get_int('fontmode'); + fontmode = settings.get_int('fontmode'); button = new St.Bin({ style_class: 'panel-button', @@ -37,31 +41,37 @@ function init() { track_hover: true }); - /* - icon = new St.Icon({ - gicon: Gio.icon_new_for_string(Me.path + "/icons/harddisk.svg") - }); - iconDark = new St.Icon({ - gicon: Gio.icon_new_for_string(Me.path + "/icons/harddisk-dark.svg") - });*/ - ioSpeed = new St.Label({ text: '---', - style_class: 'simplenetspeed-label' + style_class: 'simplenetspeed' }); - // ioSpeedStaticIcon = new St.Label({ - // text: '💾', - // style_class: 'simplenetspeed-static-icon' - // }); - - button.set_child(chooseLabel()); + button.set_child(ioSpeed); button.connect('button-press-event', changeMode); + updateSpeedMap(); + updateStyle(); +} + +function updateStyle(){ + style = "font-size: " + (0.15*fontmode + 0.65) + "em;"; // parenthesis needed: math inside, strcat outside + ioSpeed.set_style(style); +} + +function updateSpeedMap(){ + if (mode == 0 || mode == 2) { + speed_map = ["bps", "Kbps", "Mbps", "Gbps"]; + } + else if (mode == 1 || mode == 3) { + speed_map = ["B/s", "K/s", "M/s", "G/s"]; + } + else if (mode >= 4 && mode <= 6) { + speed_map = ["B", "KB", "MB", "GB"]; + } } function changeMode(widget, event) { // log(event.get_button()); - if (event.get_button() == 3 && mode == 4) { // right click: reset downloaded sum + if (event.get_button() == 3 && mode >= 4 && mode <= 6) { // right click: reset downloaded sum resetNextCount = true; parseStat(); } @@ -71,37 +81,21 @@ function changeMode(widget, event) { fontmode=0; } settings.set_int('fontmode', fontmode); - button.set_child(chooseLabel()); + updateStyle(); parseStat(); } else if (event.get_button() == 1) { mode++; - if (mode > 4) { + if (mode > 6) { mode = 0; } + updateSpeedMap(); settings.set_int('mode', mode); - button.set_child(chooseLabel()); parseStat(); } log('mode:' + mode + ' font:' + fontmode); } -function chooseLabel() { - if (mode == 0 || mode == 1 || mode == 4) { - styleName = 'simplenetspeed-label'; - } - else { - styleName = 'simplenetspeed-label-w'; - } - - if (fontmode > 0) { - styleName = styleName + '-' + fontmode; - } - - ioSpeed.set_style_class_name(styleName); - return ioSpeed; -} - function parseStat() { try { let input_file = Gio.file_new_for_path('/proc/net/dev'); @@ -146,18 +140,25 @@ function parseStat() { dot = "⇅"; } - if (mode >= 0 && mode <= 1) { + if (mode == 0 || mode == 1) { ioSpeed.set_text(dot + speedToString(speed)); } - else if (mode >= 2 && mode <= 3) { + else if (mode == 2 || mode == 3) { ioSpeed.set_text("↓" + speedToString(speed - speedUp) + " ↑" + speedToString(speedUp)); } - else if (mode == 4) { + else if (mode >= 4 && mode <= 6) { if (resetNextCount == true) { resetNextCount = false; resetCount = count; + resetCountUp = countUp; + } + if(mode == 4){ + ioSpeed.set_text("∑ ↓ " + speedToString(count - resetCount)); + } else if (mode == 5) { + ioSpeed.set_text("∑ ↑ " + speedToString(countUp - resetCountUp)); + } else { + ioSpeed.set_text("∑ ↑↓ " + speedToString(count - resetCount + countUp - resetCountUp)); } - ioSpeed.set_text("∑ " + speedToString(count - resetCount)); } lastCount = count; @@ -167,37 +168,11 @@ function parseStat() { ioSpeed.set_text(e.message); } - /* - let curDiskstats = GLib.file_get_contents('/proc/diskstats'); - - if (diskstats == curDiskstats) { - if (cur !== 0) { - button.set_child(iconDark); - cur = 0; - } - } else { - if (cur != 1) { - button.set_child(icon); - cur = 1; - } - diskstats = curDiskstats; - }*/ - return true; } function speedToString(amount) { let digits; - let speed_map; - if (mode == 0 || mode == 2) { - speed_map = ["bps", "Kbps", "Mbps", "Gbps"]; - } - else if (mode == 1 || mode == 3) { - speed_map = ["B/s", "K/s", "M/s", "G/s"]; - } - else if (mode == 4) { - speed_map = ["B", "KB", "MB", "GB"]; - } if (amount === 0) return "0" + speed_map[0]; diff --git a/metadata.json b/metadata.json index 254ec77..769afa3 100644 --- a/metadata.json +++ b/metadata.json @@ -1,27 +1,19 @@ { - "_generated": "Generated by SweetTooth, do not edit", - "description": "Simply showing network speed. Left click to change modes:\n\n1. Total net speed in bits per second\n2. Total net speed in Bytes per second\n3. Up & down speed in bits per second\n4. Up & down speed in Bytes per second\n5. Total of downloaded in Bytes (Right click to reset counter)\n\nMiddle click to change font size", - "name": "Simple net speed", + "_generated": "Generated by SweetTooth, do not edit", + "description": "Simply showing network speed. Left click to change modes:\n\n1. Total net speed in bits per second\n2. Total net speed in Bytes per second\n3. Up & down speed in bits per second\n4. Up & down speed in Bytes per second\n5. Total of downloaded in Bytes (Right click to reset all counters)\n6. Total of uploaded bytes (Right click to reset all counters)\n7. Total bytes transferred (Right click to reset all counters)\n\nMiddle click to change font size", + "name": "Simple net speed", "shell-version": [ - "3.14", - "3.15", - "3.16", - "3.17", - "3.18", - "3.19", - "3.20", - "3.21", - "3.22", - "3.23", - "3.24", - "3.25", - "3.26", - "3.27", - "3.28", - "3.29", + "3.14", + "3.16", + "3.18", + "3.20", + "3.22", + "3.24", + "3.26", + "3.28", "3.30" - ], - "url": "https://github.com/biji/simplenetspeed", - "uuid": "simplenetspeed@biji.extension", - "version": 5 -} + ], + "url": "https://github.com/mirko-laruina/simplenetspeed", + "uuid": "simplenetspeed@biji.extension", + "version": 16 +} \ No newline at end of file From 7b59378b10c087ed13183ccbe6f4f73011270679 Mon Sep 17 00:00:00 2001 From: Mirko Date: Sun, 16 Dec 2018 22:05:03 +0100 Subject: [PATCH 2/2] Right click on the current speed will switch to total transferred --- extension.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/extension.js b/extension.js index e587ae2..1a46953 100644 --- a/extension.js +++ b/extension.js @@ -71,8 +71,14 @@ function updateSpeedMap(){ function changeMode(widget, event) { // log(event.get_button()); - if (event.get_button() == 3 && mode >= 4 && mode <= 6) { // right click: reset downloaded sum - resetNextCount = true; + if (event.get_button() == 3) { // right click: reset downloaded sum + if (mode < 4){ + mode = 6; + updateSpeedMap(); + settings.set_int('mode', mode); + } else { + resetNextCount = true; + } parseStat(); } else if (event.get_button() == 2) { // change font