@@ -3,15 +3,14 @@ const St = imports.gi.St;
3
3
const Main = imports . ui . main ;
4
4
// const Tweener = imports.ui.tweener;
5
5
const Gio = imports . gi . Gio ;
6
- const Mainloop = imports . mainloop ;
7
- // const GLib = imports.gi.GLib;
6
+ const GLib = imports . gi . GLib ;
8
7
9
8
const ExtensionUtils = imports . misc . extensionUtils ;
10
9
const Me = ExtensionUtils . getCurrentExtension ( ) ;
11
10
const Convenience = Me . imports . convenience ;
12
11
13
12
const PREFS_SCHEMA = 'org.gnome.shell.extensions.simplenetspeed' ;
14
- const refreshTime = 3.0 ;
13
+ const refreshTime = 3 ;
15
14
16
15
let settings ;
17
16
let button , timeout ;
@@ -25,40 +24,6 @@ let resetNextCount = false, resetCount = 0;
25
24
function init ( ) {
26
25
27
26
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 ) ;
62
27
}
63
28
64
29
function changeMode ( widget , event ) {
@@ -187,7 +152,7 @@ function parseStat() {
187
152
diskstats = curDiskstats;
188
153
}*/
189
154
190
- return true ;
155
+ return GLib . SOURCE_CONTINUE ;
191
156
}
192
157
193
158
function speedToString ( amount ) {
@@ -224,11 +189,50 @@ function speedToString(amount) {
224
189
}
225
190
226
191
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
+
227
226
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
+ } ) ;
229
230
}
230
231
231
232
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
+ }
234
238
}
0 commit comments