Skip to content

Commit

Permalink
move to enable(), use GLib
Browse files Browse the repository at this point in the history
  • Loading branch information
biji committed Jun 10, 2021
1 parent 37e1760 commit 8b488a0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 70 deletions.
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

86 changes: 45 additions & 41 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ const St = imports.gi.St;
const Main = imports.ui.main;
// const Tweener = imports.ui.tweener;
const Gio = imports.gi.Gio;
const Mainloop = imports.mainloop;
// const GLib = imports.gi.GLib;
const GLib = imports.gi.GLib;

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;

const PREFS_SCHEMA = 'org.gnome.shell.extensions.simplenetspeed';
const refreshTime = 3.0;
const refreshTime = 3;

let settings;
let button, timeout;
Expand All @@ -25,40 +24,6 @@ let resetNextCount = false, resetCount = 0;
function init() {

settings = Convenience.getSettings(PREFS_SCHEMA);

mode = settings.get_int('mode'); // default mode using bit (bps, kbps)
fontmode = settings.get_int('fontmode');

button = new St.Bin({
style_class: 'panel-button',
reactive: true,
can_focus: true,
x_expand: true,
y_expand: false,
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: '---',
y_align: Clutter.ActorAlign.CENTER,
style_class: 'simplenetspeed-label'
});

// ioSpeedStaticIcon = new St.Label({
// text: '💾',
// style_class: 'simplenetspeed-static-icon'
// });

button.set_child(chooseLabel());
button.connect('button-press-event', changeMode);
}

function changeMode(widget, event) {
Expand Down Expand Up @@ -187,7 +152,7 @@ function parseStat() {
diskstats = curDiskstats;
}*/

return true;
return GLib.SOURCE_CONTINUE;
}

function speedToString(amount) {
Expand Down Expand Up @@ -224,11 +189,50 @@ function speedToString(amount) {
}

function enable() {
mode = settings.get_int('mode'); // default mode using bit (bps, kbps)
fontmode = settings.get_int('fontmode');

button = new St.Bin({
style_class: 'panel-button',
reactive: true,
can_focus: true,
x_expand: true,
y_expand: false,
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: '---',
y_align: Clutter.ActorAlign.CENTER,
style_class: 'simplenetspeed-label'
});

// ioSpeedStaticIcon = new St.Label({
// text: '💾',
// style_class: 'simplenetspeed-static-icon'
// });

button.set_child(chooseLabel());
button.connect('button-press-event', changeMode);

Main.panel._rightBox.insert_child_at_index(button, 0);
timeout = Mainloop.timeout_add_seconds(refreshTime, parseStat);
timeout = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, refreshTime, () => {
return parseStat();
});
}

function disable() {
Mainloop.source_remove(timeout);
Main.panel._rightBox.remove_child(button);
if (timeout) {
GLib.source_remove(timeout);
timeout = null;
Main.panel._rightBox.remove_child(button);
}
}
23 changes: 2 additions & 21 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,9 @@
"3.36",
"3.38",
"40",
"41",
"42",
"43",
"44",
"45",
"46",
"47",
"48",
"49",
"50",
"51",
"52",
"53",
"54",
"55",
"56",
"57",
"58",
"59",
"60"
"41"
],
"url": "https://github.com/biji/simplenetspeed",
"uuid": "[email protected]",
"version": 22
"version": 23
}
2 changes: 0 additions & 2 deletions notes.md

This file was deleted.

10 changes: 5 additions & 5 deletions stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}

.simplenetspeed-label-w {
width: 11em;
width: 12em;
text-align: right;
margin-left: 1px;
margin-right: 1px;
Expand All @@ -23,7 +23,7 @@
}

.simplenetspeed-label-w-1 {
width: 11em;
width: 12em;
text-align: right;
margin-left: 1px;
margin-right: 1px;
Expand All @@ -39,7 +39,7 @@
}

.simplenetspeed-label-w-2 {
width: 11em;
width: 12em;
text-align: right;
margin-left: 1px;
margin-right: 1px;
Expand All @@ -55,7 +55,7 @@
}

.simplenetspeed-label-w-3 {
width: 11em;
width: 12em;
text-align: right;
margin-left: 1px;
margin-right: 1px;
Expand All @@ -71,7 +71,7 @@
}

.simplenetspeed-label-w-4 {
width: 11em;
width: 12em;
text-align: right;
margin-left: 1px;
margin-right: 1px;
Expand Down

0 comments on commit 8b488a0

Please sign in to comment.