From 666feb799e2a5cd6ebb32ca031c3285ad5ef06de Mon Sep 17 00:00:00 2001 From: c84c <616846+c84c@users.noreply.github.com> Date: Sun, 22 Jan 2023 02:05:54 +0100 Subject: [PATCH] fix: Remove Lang module Fix #139 --- net_speed.js | 21 ++++++++++----------- net_speed_status_icon.js | 7 +++---- prefs.js | 40 +++++++++++++++++++--------------------- 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/net_speed.js b/net_speed.js index 83162ca..db19283 100644 --- a/net_speed.js +++ b/net_speed.js @@ -15,7 +15,6 @@ * along with this program. If not, see . */ -const Lang = imports.lang; const Extension = imports.misc.extensionUtils.getCurrentExtension(); const Lib = Extension.imports.lib; const Gettext = imports.gettext; @@ -324,7 +323,7 @@ var NetSpeed = class NetSpeed { let m_timer = this._setting.get_int('timer'); if (m_timer !== this.timer) { Mainloop.source_remove(this._timerid); - this._timerid = Mainloop.timeout_add(m_timer, Lang.bind(this, this._update)); + this._timerid = Mainloop.timeout_add(m_timer, this._update.bind(this)); // this.timer will be updated within this._load, so no need to update it here } this._load(); @@ -346,12 +345,12 @@ var NetSpeed = class NetSpeed { this._devices = new Array(); this._client = NetworkManager.Client.new(null); this._nm_signals = new Array(); - this._nm_signals.push(this._client.connect('any-device-added', Lang.bind(this, this._nm_device_changed))); - this._nm_signals.push(this._client.connect('any-device-removed', Lang.bind(this, this._nm_device_changed))); - this._nm_signals.push(this._client.connect('connection-added', Lang.bind(this, this._nm_connection_changed))); - this._nm_signals.push(this._client.connect('connection-removed', Lang.bind(this, this._nm_connection_changed))); - this._nm_signals.push(this._client.connect('active-connection-added', Lang.bind(this, this._nm_connection_changed))); - this._nm_signals.push(this._client.connect('active-connection-removed', Lang.bind(this, this._nm_connection_changed))); + this._nm_signals.push(this._client.connect('any-device-added', this._nm_device_changed.bind(this))); + this._nm_signals.push(this._client.connect('any-device-removed', this._nm_device_changed.bind(this))); + this._nm_signals.push(this._client.connect('connection-added', this._nm_connection_changed.bind(this))); + this._nm_signals.push(this._client.connect('connection-removed', this._nm_connection_changed.bind(this))); + this._nm_signals.push(this._client.connect('active-connection-added', this._nm_connection_changed.bind(this))); + this._nm_signals.push(this._client.connect('active-connection-removed', this._nm_connection_changed.bind(this))); // store NM Device 'state-changed' signal bindings to disconnect on disable this._nm_devices_signals_map = new Map(); @@ -365,8 +364,8 @@ var NetSpeed = class NetSpeed { this._saving = 0; this._load(); - this._changed = this._setting.connect('changed', Lang.bind(this, this._reload)); - this._timerid = Mainloop.timeout_add(this.timer, Lang.bind(this, this._update)); + this._changed = this._setting.connect('changed', this._reload.bind(this)); + this._timerid = Mainloop.timeout_add(this.timer, this._update.bind(this)); this._status_icon = new NetSpeedStatusIcon.NetSpeedStatusIcon(this); let placement = this._setting.get_string('placement'); Panel.addToStatusArea('netspeed', this._status_icon, 0, placement); @@ -469,7 +468,7 @@ var NetSpeed = class NetSpeed { */ _connect_nm_device_state_changed(nm_device) { if (!this._nm_devices_signals_map.has(nm_device.get_iface())) { - let signal_id = nm_device.connect('state-changed', Lang.bind(this, this._nm_device_state_changed)); + let signal_id = nm_device.connect('state-changed', this._nm_device_state_changed.bind(this)); this._nm_devices_signals_map.set(nm_device.get_iface(), [nm_device, signal_id]); } } diff --git a/net_speed_status_icon.js b/net_speed_status_icon.js index aece34f..7fcc755 100644 --- a/net_speed_status_icon.js +++ b/net_speed_status_icon.js @@ -18,7 +18,6 @@ const ExtensionUtils = imports.misc.extensionUtils; const Extension = ExtensionUtils.getCurrentExtension(); const Gettext = imports.gettext; -const Lang = imports.lang; const PanelMenu = imports.ui.panelMenu; const PopupMenu = imports.ui.popupMenu; const Clutter = imports.gi.Clutter; @@ -48,7 +47,7 @@ var NetSpeedStatusIcon = GObject.registerClass(class NetSpeedStatusIcon extends // extension button this._box = new St.BoxLayout(); this.add_actor(this._box); - this.connect('button-release-event', Lang.bind(this, this._toggle_showsum)); + this.connect('button-release-event', this._toggle_showsum.bind(this)); // download this._download_box = new St.BoxLayout(); @@ -95,7 +94,7 @@ var NetSpeedStatusIcon = GObject.registerClass(class NetSpeedStatusIcon extends }); this._menu_title = new NetSpeedLayoutMenuItem.NetSpeedLayoutMenuItem(_("Device"), this._pref, this._net_speed.menu_label_size); - this._menu_title.connect("activate", Lang.bind(this, this._change_device, "")); + this._menu_title.connect("activate", this._change_device.bind(this, "")); this._menu_title.update_speeds({ up: _("Up"), down: _("Down") }); this._menu_title.update_ips([_("IP")]); this._menu_title.show_ip(this._net_speed.show_ips); @@ -260,7 +259,7 @@ var NetSpeedStatusIcon = GObject.registerClass(class NetSpeedStatusIcon extends let icon = this._get_icon(types[i]); let layout = new NetSpeedLayoutMenuItem.NetSpeedLayoutMenuItem(devices[i], icon, this._net_speed.menu_label_size); layout.show_ip(this._net_speed.show_ips); - layout.connect("activate", Lang.bind(this, this._change_device, devices[i])); + layout.connect("activate", this._change_device.bind(this, devices[i])); this._layouts.push(layout); this.menu.addMenuItem(layout); } diff --git a/prefs.js b/prefs.js index 837ffc1..6444ed8 100644 --- a/prefs.js +++ b/prefs.js @@ -1,20 +1,19 @@ - /* - * Copyright 2011-2019 Amir Hedayaty < hedayaty AT gmail DOT com > - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - +/* + * Copyright 2011-2019 Amir Hedayaty < hedayaty AT gmail DOT com > + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ const Extension = imports.misc.extensionUtils.getCurrentExtension(); const Lib = Extension.imports.lib; @@ -25,7 +24,6 @@ const Gdk = imports.gi.Gdk; const Gettext = imports.gettext; const Gio = imports.gi.Gio; const Gtk = imports.gi.Gtk; -const Lang = imports.lang; const NM = imports.gi.NM; const _ = Gettext.domain('netspeed').gettext; @@ -309,10 +307,10 @@ const App = class NetSpeed_App { this._pick_dev(); this._factor = Schema.get_int('hi-dpi-factor'); - this.dev.connect('changed', Lang.bind(this, this._put_dev)); - Schema.connect('changed', Lang.bind(this, this._dpi_changed)); + this.dev.connect('changed', this._put_dev.bind(this)); + Schema.connect('changed', this._dpi_changed.bind(this)); - this.placement.connect('changed', Lang.bind(this, this._change_placement)) + this.placement.connect('changed', this._change_placement.bind(this)); } };