From 8b488a06b3d12f447436691b4572798cb6cfbdfd Mon Sep 17 00:00:00 2001 From: biji Date: Thu, 10 Jun 2021 17:07:07 +0700 Subject: [PATCH] move to enable(), use GLib --- .gitignore | 1 - extension.js | 86 ++++++++++++++++++++++++++------------------------ metadata.json | 23 ++------------ notes.md | 2 -- stylesheet.css | 10 +++--- 5 files changed, 52 insertions(+), 70 deletions(-) delete mode 100644 .gitignore delete mode 100644 notes.md diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 849ddff..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -dist/ diff --git a/extension.js b/extension.js index 65439db..172baf3 100644 --- a/extension.js +++ b/extension.js @@ -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; @@ -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) { @@ -187,7 +152,7 @@ function parseStat() { diskstats = curDiskstats; }*/ - return true; + return GLib.SOURCE_CONTINUE; } function speedToString(amount) { @@ -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); + } } diff --git a/metadata.json b/metadata.json index 84020c2..6064611 100644 --- a/metadata.json +++ b/metadata.json @@ -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": "simplenetspeed@biji.extension", - "version": 22 + "version": 23 } diff --git a/notes.md b/notes.md deleted file mode 100644 index 62553d4..0000000 --- a/notes.md +++ /dev/null @@ -1,2 +0,0 @@ -geu build -geu publish diff --git a/stylesheet.css b/stylesheet.css index 6f13803..f16ab15 100644 --- a/stylesheet.css +++ b/stylesheet.css @@ -7,7 +7,7 @@ } .simplenetspeed-label-w { - width: 11em; + width: 12em; text-align: right; margin-left: 1px; margin-right: 1px; @@ -23,7 +23,7 @@ } .simplenetspeed-label-w-1 { - width: 11em; + width: 12em; text-align: right; margin-left: 1px; margin-right: 1px; @@ -39,7 +39,7 @@ } .simplenetspeed-label-w-2 { - width: 11em; + width: 12em; text-align: right; margin-left: 1px; margin-right: 1px; @@ -55,7 +55,7 @@ } .simplenetspeed-label-w-3 { - width: 11em; + width: 12em; text-align: right; margin-left: 1px; margin-right: 1px; @@ -71,7 +71,7 @@ } .simplenetspeed-label-w-4 { - width: 11em; + width: 12em; text-align: right; margin-left: 1px; margin-right: 1px;