Skip to content

Commit 8b488a0

Browse files
committed
move to enable(), use GLib
1 parent 37e1760 commit 8b488a0

File tree

5 files changed

+52
-70
lines changed

5 files changed

+52
-70
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

extension.js

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ const St = imports.gi.St;
33
const Main = imports.ui.main;
44
// const Tweener = imports.ui.tweener;
55
const Gio = imports.gi.Gio;
6-
const Mainloop = imports.mainloop;
7-
// const GLib = imports.gi.GLib;
6+
const GLib = imports.gi.GLib;
87

98
const ExtensionUtils = imports.misc.extensionUtils;
109
const Me = ExtensionUtils.getCurrentExtension();
1110
const Convenience = Me.imports.convenience;
1211

1312
const PREFS_SCHEMA = 'org.gnome.shell.extensions.simplenetspeed';
14-
const refreshTime = 3.0;
13+
const refreshTime = 3;
1514

1615
let settings;
1716
let button, timeout;
@@ -25,40 +24,6 @@ let resetNextCount = false, resetCount = 0;
2524
function init() {
2625

2726
settings = Convenience.getSettings(PREFS_SCHEMA);
28-
29-
mode = settings.get_int('mode'); // default mode using bit (bps, kbps)
30-
fontmode = settings.get_int('fontmode');
31-
32-
button = new St.Bin({
33-
style_class: 'panel-button',
34-
reactive: true,
35-
can_focus: true,
36-
x_expand: true,
37-
y_expand: false,
38-
track_hover: true
39-
});
40-
41-
/*
42-
icon = new St.Icon({
43-
gicon: Gio.icon_new_for_string(Me.path + "/icons/harddisk.svg")
44-
});
45-
iconDark = new St.Icon({
46-
gicon: Gio.icon_new_for_string(Me.path + "/icons/harddisk-dark.svg")
47-
});*/
48-
49-
ioSpeed = new St.Label({
50-
text: '---',
51-
y_align: Clutter.ActorAlign.CENTER,
52-
style_class: 'simplenetspeed-label'
53-
});
54-
55-
// ioSpeedStaticIcon = new St.Label({
56-
// text: '💾',
57-
// style_class: 'simplenetspeed-static-icon'
58-
// });
59-
60-
button.set_child(chooseLabel());
61-
button.connect('button-press-event', changeMode);
6227
}
6328

6429
function changeMode(widget, event) {
@@ -187,7 +152,7 @@ function parseStat() {
187152
diskstats = curDiskstats;
188153
}*/
189154

190-
return true;
155+
return GLib.SOURCE_CONTINUE;
191156
}
192157

193158
function speedToString(amount) {
@@ -224,11 +189,50 @@ function speedToString(amount) {
224189
}
225190

226191
function enable() {
192+
mode = settings.get_int('mode'); // default mode using bit (bps, kbps)
193+
fontmode = settings.get_int('fontmode');
194+
195+
button = new St.Bin({
196+
style_class: 'panel-button',
197+
reactive: true,
198+
can_focus: true,
199+
x_expand: true,
200+
y_expand: false,
201+
track_hover: true
202+
});
203+
204+
/*
205+
icon = new St.Icon({
206+
gicon: Gio.icon_new_for_string(Me.path + "/icons/harddisk.svg")
207+
});
208+
iconDark = new St.Icon({
209+
gicon: Gio.icon_new_for_string(Me.path + "/icons/harddisk-dark.svg")
210+
});*/
211+
212+
ioSpeed = new St.Label({
213+
text: '---',
214+
y_align: Clutter.ActorAlign.CENTER,
215+
style_class: 'simplenetspeed-label'
216+
});
217+
218+
// ioSpeedStaticIcon = new St.Label({
219+
// text: '💾',
220+
// style_class: 'simplenetspeed-static-icon'
221+
// });
222+
223+
button.set_child(chooseLabel());
224+
button.connect('button-press-event', changeMode);
225+
227226
Main.panel._rightBox.insert_child_at_index(button, 0);
228-
timeout = Mainloop.timeout_add_seconds(refreshTime, parseStat);
227+
timeout = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, refreshTime, () => {
228+
return parseStat();
229+
});
229230
}
230231

231232
function disable() {
232-
Mainloop.source_remove(timeout);
233-
Main.panel._rightBox.remove_child(button);
233+
if (timeout) {
234+
GLib.source_remove(timeout);
235+
timeout = null;
236+
Main.panel._rightBox.remove_child(button);
237+
}
234238
}

metadata.json

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,9 @@
2525
"3.36",
2626
"3.38",
2727
"40",
28-
"41",
29-
"42",
30-
"43",
31-
"44",
32-
"45",
33-
"46",
34-
"47",
35-
"48",
36-
"49",
37-
"50",
38-
"51",
39-
"52",
40-
"53",
41-
"54",
42-
"55",
43-
"56",
44-
"57",
45-
"58",
46-
"59",
47-
"60"
28+
"41"
4829
],
4930
"url": "https://github.com/biji/simplenetspeed",
5031
"uuid": "simplenetspeed@biji.extension",
51-
"version": 22
32+
"version": 23
5233
}

notes.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

stylesheet.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}
88

99
.simplenetspeed-label-w {
10-
width: 11em;
10+
width: 12em;
1111
text-align: right;
1212
margin-left: 1px;
1313
margin-right: 1px;
@@ -23,7 +23,7 @@
2323
}
2424

2525
.simplenetspeed-label-w-1 {
26-
width: 11em;
26+
width: 12em;
2727
text-align: right;
2828
margin-left: 1px;
2929
margin-right: 1px;
@@ -39,7 +39,7 @@
3939
}
4040

4141
.simplenetspeed-label-w-2 {
42-
width: 11em;
42+
width: 12em;
4343
text-align: right;
4444
margin-left: 1px;
4545
margin-right: 1px;
@@ -55,7 +55,7 @@
5555
}
5656

5757
.simplenetspeed-label-w-3 {
58-
width: 11em;
58+
width: 12em;
5959
text-align: right;
6060
margin-left: 1px;
6161
margin-right: 1px;
@@ -71,7 +71,7 @@
7171
}
7272

7373
.simplenetspeed-label-w-4 {
74-
width: 11em;
74+
width: 12em;
7575
text-align: right;
7676
margin-left: 1px;
7777
margin-right: 1px;

0 commit comments

Comments
 (0)