Skip to content

Commit

Permalink
feat: prepare for release (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekmedia authored Oct 13, 2023
1 parent 40eb4bf commit b68347f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 93 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</td>
</table>

***Supports GNOME 43, for GNOME SHELL < 40 you can use the previous versions of this extension***
***Supports GNOME 45, for GNOME SHELL < 45 you can use the previous versions of this extension***

**Note** : Full CHANGELOG can be found on [github releases](https://github.com/prateekmedia/netspeedsimplified/releases) page

Expand Down Expand Up @@ -71,6 +71,7 @@ If you faced an **issue** then you can **[file an issue here](https://github.com
#### *Special Thanks to*
- [biji](https://github.com/biji) for Creating [simplenetspeed](https://github.com/biji/simplenetspeed)
- [m0hithreddy](https://github.com/m0hithreddy) for his support in rewriting extension.js with Clutter and rewriting readme.md, Adopting Make build system and more..
- [remisiki](https://github.com/remisiki) for adding support for GNOME 45
[Know More](https://github.com/prateekmedia/netspeedsimplified/graphs/contributors)

### Troubleshooting
Expand Down
134 changes: 67 additions & 67 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
import { Extension, gettext as _ } from 'resource:///org/gnome/shell/extensions/extension.js';
const schema = 'org.gnome.shell.extensions.netspeedsimplified',
ButtonName = "ShowNetSpeedButton",
rCConst = 4; //Right Click 4 times to toggle Vertical Alignment
Expand All @@ -20,10 +20,10 @@ let settings, timeout,
B_UNITS;

// Settings
var crStng; //Initialized in enable()
var currentSettings; //Initialized in enable()

function fetchSettings() {
crStng = {
currentSettings = {
refreshTime: settings.get_double('refreshtime'),
mode: settings.get_int('mode'),
fontmode: settings.get_int('fontmode'),
Expand All @@ -48,16 +48,16 @@ function fetchSettings() {
tdColor: settings.get_string('tdcolor')
};

B_UNITS = (crStng.shortenUnits) ? ['B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z'] : [' B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'];
B_UNITS = (currentSettings.shortenUnits) ? ['B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z'] : [' B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'];

initNs();
}

function pushSettings() {
settings.set_int('mode', crStng.mode);
settings.set_int('fontmode', crStng.fontmode);
settings.set_boolean('togglebool', crStng.showTotalDwnld);
settings.set_boolean('isvertical', crStng.isVertical);
settings.set_int('mode', currentSettings.mode);
settings.set_int('fontmode', currentSettings.fontmode);
settings.set_boolean('togglebool', currentSettings.showTotalDwnld);
settings.set_boolean('isvertical', currentSettings.isVertical);

initNs();
}
Expand All @@ -68,39 +68,39 @@ function DIcons(iNum) {
["⬇", "⬆"],
["🡳", "🡱"],
["↓", "↑"]
][crStng.chooseIconSet][iNum];
][currentSettings.chooseIconSet][iNum];
}

function nsPos() {
return ["right", "left", "center"][crStng.nsPos];
return ["right", "left", "center"][currentSettings.nsPos];
}

function nsPosAdv() {
return [3, 0][crStng.nsPosAdv];
return [3, 0][currentSettings.nsPosAdv];
}

function speedToString(amount, rMode = 0) {

let speed_map = B_UNITS.map(
(rMode == 1 && (crStng.mode == 1 || crStng.mode == 3 || crStng.mode == 4)) ? v => v : //KB
(rMode == 1 && (crStng.mode == 0 || crStng.mode == 2)) ? v => v.toLowerCase() : //kb
(crStng.mode == 0 || crStng.mode == 2) ? v => v.toLowerCase() + "/s" : //kb/s
(crStng.mode == 1 || crStng.mode == 3) ? v => v + "/s" : //KB/s
(rMode == 1 && (currentSettings.mode == 1 || currentSettings.mode == 3 || currentSettings.mode == 4)) ? v => v : //KB
(rMode == 1 && (currentSettings.mode == 0 || currentSettings.mode == 2)) ? v => v.toLowerCase() : //kb
(currentSettings.mode == 0 || currentSettings.mode == 2) ? v => v.toLowerCase() + "/s" : //kb/s
(currentSettings.mode == 1 || currentSettings.mode == 3) ? v => v + "/s" : //KB/s
v => v); // Others

if (amount === 0) return " 0.0 " + speed_map[0];
if (crStng.mode == 0 || crStng.mode == 2) amount = amount * 8;
if (currentSettings.mode == 0 || currentSettings.mode == 2) amount = amount * 8;

let unit = 0;
while (amount >= 1000) { // 1M=1024K, 1MB/s=1000MB/s
if (crStng.limitunit != 0 && unit >= crStng.limitunit) {
if (currentSettings.limitunit != 0 && unit >= currentSettings.limitunit) {
break;
}
amount /= 1000;
unit++;
}

let digits = (crStng.mode == 4 || rMode != 0) ? 2 /* For floats like 21.11 and total speed mode */ : 1 //For floats like 21.2
let digits = (currentSettings.mode == 4 || rMode != 0) ? 2 /* For floats like 21.11 and total speed mode */ : 1 //For floats like 21.2

let spaceNum = 3 - Math.ceil(Math.log10(amount + 1));
spaceNum < 0 ? spaceNum = 0 : null
Expand All @@ -112,7 +112,7 @@ function speedToString(amount, rMode = 0) {
var usLabel, dsLabel, tsLabel, tdLabel, usIcon, dsIcon, tsIcon, tdIcon;

function getStyle(isIcon = false) {
return (isIcon) ? 'size-' + (String(crStng.fontmode)) : ('forall size-' + String(crStng.fontmode))
return (isIcon) ? 'size-' + (String(currentSettings.fontmode)) : ('forall size-' + String(currentSettings.fontmode))
}

function byteArrayToString(bytes) {
Expand All @@ -124,64 +124,64 @@ function byteArrayToString(bytes) {
}

function initNsLabels() {
let extraInfo = crStng.cusFont ? "font-family: " + crStng.cusFont + "; " : "";
let extraLabelInfo = extraInfo + "min-width: " + crStng.minWidth + "em; ";
extraLabelInfo += "text-align: " + ["left", "right", "center"][crStng.textAlign] + "; ";
let extraInfo = currentSettings.cusFont ? "font-family: " + currentSettings.cusFont + "; " : "";
let extraLabelInfo = extraInfo + "min-width: " + currentSettings.minWidth + "em; ";
extraLabelInfo += "text-align: " + ["left", "right", "center"][currentSettings.textAlign] + "; ";


usLabel = new St.Label({
text: '--',
y_align: Clutter.ActorAlign.CENTER,
style_class: getStyle(),
style: extraLabelInfo + (crStng.systemColr ? "" : "color: " + crStng.usColor)
style: extraLabelInfo + (currentSettings.systemColr ? "" : "color: " + currentSettings.usColor)
});

dsLabel = new St.Label({
text: '--',
y_align: Clutter.ActorAlign.CENTER,
style_class: getStyle(),
style: extraLabelInfo + (crStng.systemColr ? "" : "color: " + crStng.dsColor)
style: extraLabelInfo + (currentSettings.systemColr ? "" : "color: " + currentSettings.dsColor)
});

tsLabel = new St.Label({
text: '--',
y_align: Clutter.ActorAlign.CENTER,
style_class: getStyle(),
style: extraLabelInfo + (crStng.systemColr ? "" : "color: " + crStng.tsColor)
style: extraLabelInfo + (currentSettings.systemColr ? "" : "color: " + currentSettings.tsColor)
});

tdLabel = new St.Label({
text: '--',
y_align: Clutter.ActorAlign.CENTER,
style_class: getStyle(),
style: extraLabelInfo + (crStng.systemColr ? "" : "color: " + crStng.tdColor)
style: extraLabelInfo + (currentSettings.systemColr ? "" : "color: " + currentSettings.tdColor)
});
usIcon = new St.Label({
text: DIcons(1),
y_align: Clutter.ActorAlign.CENTER,
style_class: getStyle(true),
style: extraInfo + (crStng.systemColr ? "" : "color: " + crStng.usColor)
style: extraInfo + (currentSettings.systemColr ? "" : "color: " + currentSettings.usColor)
});

dsIcon = new St.Label({
text: DIcons(0),
y_align: Clutter.ActorAlign.CENTER,
style_class: getStyle(true),
style: extraInfo + (crStng.systemColr ? "" : "color: " + crStng.dsColor)
style: extraInfo + (currentSettings.systemColr ? "" : "color: " + currentSettings.dsColor)
});

tsIcon = new St.Label({
text: "⇅",
y_align: Clutter.ActorAlign.CENTER,
style_class: getStyle(true),
style: extraInfo + (crStng.systemColr ? "" : "color: " + crStng.tsColor)
style: extraInfo + (currentSettings.systemColr ? "" : "color: " + currentSettings.tsColor)
});

tdIcon = new St.Label({
text: "Σ",
y_align: Clutter.ActorAlign.CENTER,
style_class: getStyle(true),
style: extraInfo + (crStng.systemColr ? "" : "color: " + crStng.tdColor)
style: extraInfo + (currentSettings.systemColr ? "" : "color: " + currentSettings.tdColor)
});
}

Expand Down Expand Up @@ -217,45 +217,45 @@ function initNs() {
y_align: Clutter.ActorAlign.CENTER
})

let verticalConstant = (crStng.isVertical) ? 1 : 0;
let verticalConstant = (currentSettings.isVertical) ? 1 : 0;
let heightConstant = 1 + verticalConstant;
let widthConstant = 2 * (1 - verticalConstant);

//Attach the components to the grid.
if (crStng.mode == 0 || crStng.mode == 1) {
nsLayout.attach(!crStng.iconsToRight ? tsIcon : tsLabel, 0, 1, 1, 1);
nsLayout.attach(!crStng.iconsToRight ? tsLabel : tsIcon, 1, 1, 1, 1);
if (currentSettings.mode == 0 || currentSettings.mode == 1) {
nsLayout.attach(!currentSettings.iconsToRight ? tsIcon : tsLabel, 0, 1, 1, 1);
nsLayout.attach(!currentSettings.iconsToRight ? tsLabel : tsIcon, 1, 1, 1, 1);

if (crStng.showTotalDwnld) {
nsLayout.attach(!crStng.iconsToRight ? tdIcon : tdLabel, widthConstant, heightConstant, 1, 1);
nsLayout.attach(!crStng.iconsToRight ? tdLabel : tdIcon, 1 + widthConstant, heightConstant, 1, 1);
if (currentSettings.showTotalDwnld) {
nsLayout.attach(!currentSettings.iconsToRight ? tdIcon : tdLabel, widthConstant, heightConstant, 1, 1);
nsLayout.attach(!currentSettings.iconsToRight ? tdLabel : tdIcon, 1 + widthConstant, heightConstant, 1, 1);
}
} else if (crStng.mode == 2 || crStng.mode == 3) {
if (crStng.revIndicator) {
nsLayout.attach(!crStng.iconsToRight ? usIcon : usLabel, 0, 1, 1, 1);
nsLayout.attach(!crStng.iconsToRight ? usLabel : usIcon, 1, 1, 1, 1);
nsLayout.attach(!crStng.iconsToRight ? dsIcon : dsLabel, widthConstant, heightConstant, 1, 1);
nsLayout.attach(!crStng.iconsToRight ? dsLabel : dsIcon, 1 + widthConstant, heightConstant, 1, 1);
} else if (currentSettings.mode == 2 || currentSettings.mode == 3) {
if (currentSettings.revIndicator) {
nsLayout.attach(!currentSettings.iconsToRight ? usIcon : usLabel, 0, 1, 1, 1);
nsLayout.attach(!currentSettings.iconsToRight ? usLabel : usIcon, 1, 1, 1, 1);
nsLayout.attach(!currentSettings.iconsToRight ? dsIcon : dsLabel, widthConstant, heightConstant, 1, 1);
nsLayout.attach(!currentSettings.iconsToRight ? dsLabel : dsIcon, 1 + widthConstant, heightConstant, 1, 1);
} else {
nsLayout.attach(!crStng.iconsToRight ? dsIcon : dsLabel, 0, 1, 1, 1);
nsLayout.attach(!crStng.iconsToRight ? dsLabel : dsIcon, 1, 1, 1, 1);
nsLayout.attach(!crStng.iconsToRight ? usIcon : usLabel, widthConstant, heightConstant, 1, 1);
nsLayout.attach(!crStng.iconsToRight ? usLabel : usIcon, 1 + widthConstant, heightConstant, 1, 1);
nsLayout.attach(!currentSettings.iconsToRight ? dsIcon : dsLabel, 0, 1, 1, 1);
nsLayout.attach(!currentSettings.iconsToRight ? dsLabel : dsIcon, 1, 1, 1, 1);
nsLayout.attach(!currentSettings.iconsToRight ? usIcon : usLabel, widthConstant, heightConstant, 1, 1);
nsLayout.attach(!currentSettings.iconsToRight ? usLabel : usIcon, 1 + widthConstant, heightConstant, 1, 1);
}

if (crStng.showTotalDwnld) {
nsLayout.attach(!crStng.iconsToRight ? tdIcon : tdLabel, 2 + widthConstant, heightConstant, 1, 1);
nsLayout.attach(!crStng.iconsToRight ? tdLabel : tdIcon, 3 + widthConstant, heightConstant, 1, 1);
if (currentSettings.showTotalDwnld) {
nsLayout.attach(!currentSettings.iconsToRight ? tdIcon : tdLabel, 2 + widthConstant, heightConstant, 1, 1);
nsLayout.attach(!currentSettings.iconsToRight ? tdLabel : tdIcon, 3 + widthConstant, heightConstant, 1, 1);
}
} else {
nsLayout.attach(!crStng.iconsToRight ? tdIcon : tdLabel, 0, 1, 1, 1);
nsLayout.attach(!crStng.iconsToRight ? tdLabel : tdIcon, 1, 1, 1, 1);
nsLayout.attach(!currentSettings.iconsToRight ? tdIcon : tdLabel, 0, 1, 1, 1);
nsLayout.attach(!currentSettings.iconsToRight ? tdLabel : tdIcon, 1, 1, 1, 1);
}

//Create the button and add to Main.panel
nsButton = new PanelMenu.Button(0.0, ButtonName);

(!crStng.lckMuseAct) ? nsButton.connect('button-press-event', mouseEventHandler) : null;
(!currentSettings.lckMuseAct) ? nsButton.connect('button-press-event', mouseEventHandler) : null;
nsButton.add_child(nsActor);

Main.panel.addToStatusArea(ButtonName, nsButton, nsPosAdv(), nsPos());
Expand All @@ -272,19 +272,19 @@ var startTime = null,

function mouseEventHandler(widget, event) {
if (event.get_button() == 3) {
if (crStng.mode == 4)
if (currentSettings.mode == 4)
resetNextCount = true; // right click: reset downloaded sum
else
crStng.showTotalDwnld = !(crStng.showTotalDwnld); // right click on other modes brings total downloaded sum
currentSettings.showTotalDwnld = !(currentSettings.showTotalDwnld); // right click on other modes brings total downloaded sum

// Logic to toggle crStng.isVertical after rCConstant consequent right clicks.
if (startTime == null) {
startTime = new Date();
}

if (((new Date() - startTime) / 1000) <= crStng.refreshTime * 2) {
if (((new Date() - startTime) / 1000) <= currentSettings.refreshTime * 2) {
if (rClickCount == rCConst - 1) {
crStng.isVertical = !(crStng.isVertical);
currentSettings.isVertical = !(currentSettings.isVertical);
startTime = null;
rClickCount = 0;
} else rClickCount++;
Expand All @@ -293,11 +293,11 @@ function mouseEventHandler(widget, event) {
rClickCount = 1;
}
} else if (event.get_button() == 2) { // change font
crStng.fontmode++;
if (crStng.fontmode > 4) crStng.fontmode = 0;
currentSettings.fontmode++;
if (currentSettings.fontmode > 4) currentSettings.fontmode = 0;
} else if (event.get_button() == 1) {
crStng.mode++;
if (crStng.mode > 4) crStng.mode = 0;
currentSettings.mode++;
if (currentSettings.mode > 4) currentSettings.mode = 0;
}

pushSettings();
Expand All @@ -315,7 +315,7 @@ function parseStat() {
let countUp = 0;
let line;

for (let i=0;i<lines.length;i++) {
for (let i = 0; i < lines.length; i++) {
line = lines[i];
line = line.trim();
let fields = line.split(/\W+/);
Expand All @@ -342,8 +342,8 @@ function parseStat() {
if (lastCount === 0) lastCount = count;
if (lastCountUp === 0) lastCountUp = countUp;

let speed = (count - lastCount) / crStng.refreshTime,
speedUp = (countUp - lastCountUp) / crStng.refreshTime;
let speed = (count - lastCount) / currentSettings.refreshTime,
speedUp = (countUp - lastCountUp) / currentSettings.refreshTime;

if (resetNextCount == true) {
resetNextCount = false;
Expand All @@ -360,7 +360,7 @@ function parseStat() {
" " + speedToString(speed),
" " + speedToString(count - resetCount, 1));
} else {
if (crStng.hideInd) {
if (currentSettings.hideInd) {
nsDestroy();
} else {
nsButton == null ? initNs() : null
Expand Down Expand Up @@ -399,11 +399,11 @@ export default class NetSpeedSimplifiedExtension extends Extension {
parseStat();

//Run infinite loop.
timeout = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, crStng.refreshTime, parseStat);
timeout = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, currentSettings.refreshTime, parseStat);
}

disable() {
crStng = null;
currentSettings = null;
settings = null;

GLib.source_remove(timeout);
Expand Down
8 changes: 2 additions & 6 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
"description": "A Net Speed extension With Loads of Customization. Fork of simplenetspeed\n\nFull CHANGELOG can be found on github releases page\n\nFeatures \n1. Clean UI \n2. Adjustable Refresh rate \n3. Preferences to manage extension \n4. Vertical Alignment Support \n5. Two Icon sets for Indicators \n\nFeature Highlights for Preferences \n1. Lock Mouse Actions option \n2. Advance Position options to pinpoint where to place the indicator on the Panel. \n3. Refresh time option by which you can change refresh rate value between 1.0 and 10.0 seconds. \n4. Option to show upload speed first \n5. Color Customizations for speed indicators \n6. Option to Hide when Disconnected \n7. Option to use shorter units like K/s instead of KB/s \n8. Limit Unit option and more... \n\nModes \n1. Total net speed in terms of bits per second \n2. Total net speed in terms of bytes per second \n3. Combined Up & down speed in terms of bits per second \n4. Combined Up & down speed in terms of bytes per second \n5. Total transferred data in terms of bytes (Right click to reset counter) \n\nMouse Events \n- Left click to change modes \n- Right click(in 1-4 modes): Toggle the visibility of total transfer data. \n- Right click(in 5th mode): Reset total transfer data. \n- Right Click(Four consecutive times): Toggle through horizontal/vertical alignment. \n- Middle click: Cycle through the font sizes.",
"name": "Net speed Simplified",
"shell-version": [
"40",
"41",
"42",
"43",
"44"
"45"
],
"url": "https://github.com/prateekmedia/netspeedsimplified",
"uuid": "[email protected]",
"version": 39
"version": 40
}
Loading

0 comments on commit b68347f

Please sign in to comment.