Skip to content

Commit

Permalink
Updates multicore-sys-monitor to work on Fedora (#1646)
Browse files Browse the repository at this point in the history
* Updating the Network Manager imports to use the new NM library instead of the old NMClient and NetworkManager libraries.

* Making detection of which NM libraries to use more robust.

* Making the system even better by uses GIRepository information directly and not needing to spawn a bash shell. This increases the loading speed as well.
  • Loading branch information
coderforlife authored and jaszhix committed Mar 3, 2018
1 parent 8184fdf commit aea7067
Showing 1 changed file with 18 additions and 4 deletions.
@@ -1,7 +1,6 @@
const GTop = imports.gi.GTop;
const NMClient = imports.gi.NMClient;
const Gio = imports.gi.Gio;
const NetworkManager = imports.gi.NetworkManager;
const GIRepository = imports.gi.GIRepository;

let _;
if (typeof require !== 'undefined') {
Expand All @@ -11,6 +10,21 @@ if (typeof require !== 'undefined') {
_ = AppletDir.utils._;
}

let CONNECTED_STATE, NMClient_new;
let nm_index = GIRepository.Repository.get_default().get_loaded_namespaces().indexOf('NetworkManager')
if (nm_index == -1) {
// The NetworkManager repository is not currently loaded so load the NM repo
const NM = imports.gi.NM;
CONNECTED_STATE = NM.DeviceState.Activated;
NMClient_new = () => { return NM.Client.new(null); }
} else {
// The NetworkManager repository is current loaded so load it and the NMClient repos
const NMClient = imports.gi.NMClient;
const NetworkManager = imports.gi.NetworkManager;
CONNECTED_STATE = NetworkManager.DeviceState.CONNECTED;
NMClient_new = () => { return NMClient.Client.new(); }
}

const formatBytes = (bytes, decimals)=>{
if (bytes === 0) {
return '0 Byte';
Expand Down Expand Up @@ -186,7 +200,7 @@ NetDataProvider.prototype = {
this.name = _('NET');
this.isEnabled = true;
this.gtop = new GTop.glibtop_netload();
this.nmClient = NMClient.Client.new();
this.nmClient = NMClient_new();
this.signals = [
this.nmClient.connect('device-added', () => this.getNetDevices()),
this.nmClient.connect('device-removed', () => this.getNetDevices())
Expand Down Expand Up @@ -243,7 +257,7 @@ NetDataProvider.prototype = {
}
for (let i = 0, len = devices.length; i < len; i++) {
if (altMethod) {
if (devices[i].state !== NetworkManager.DeviceState.CONNECTED) {
if (devices[i].state !== CONNECTED_STATE) {
continue;
}
devices[i] = devices[i].get_iface();
Expand Down

0 comments on commit aea7067

Please sign in to comment.