network: Update for new APIs
New network manager APIs mean we don't have to do any scanning through the active networks and synchronize state ourselves. https://bugzilla.gnome.org/show_bug.cgi?id=706098
This commit is contained in:
parent
a326f40bbf
commit
e1c4cfd7eb
@ -1172,14 +1172,14 @@ const NMVPNSection = new Lang.Class({
|
|||||||
this._client.deactivate_connection(activeConnection);
|
this._client.deactivate_connection(activeConnection);
|
||||||
},
|
},
|
||||||
|
|
||||||
addActiveConnection: function(activeConnection) {
|
setActiveConnections: function(vpnConnections) {
|
||||||
let item = this._connectionItems.get(activeConnection._connection.get_uuid());
|
this._connectionItems.values().forEach(function(item) {
|
||||||
item.setActiveConnection(activeConnection);
|
item.setActiveConnection(null);
|
||||||
},
|
});
|
||||||
|
vpnConnections.forEach(Lang.bind(this, function(a) {
|
||||||
removeActiveConnection: function(activeConnection) {
|
let item = this._connectionItems.get(a._connection.get_uuid());
|
||||||
let item = this._connectionItems.get(activeConnection._connection.get_uuid());
|
item.setActiveConnection(a);
|
||||||
item.setActiveConnection(null);
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
_makeConnectionItem: function(connection) {
|
_makeConnectionItem: function(connection) {
|
||||||
@ -1277,7 +1277,8 @@ const NMApplet = new Lang.Class({
|
|||||||
this._client.connect('notify::manager-running', Lang.bind(this, this._syncNMState));
|
this._client.connect('notify::manager-running', Lang.bind(this, this._syncNMState));
|
||||||
this._client.connect('notify::networking-enabled', Lang.bind(this, this._syncNMState));
|
this._client.connect('notify::networking-enabled', Lang.bind(this, this._syncNMState));
|
||||||
this._client.connect('notify::state', Lang.bind(this, this._syncNMState));
|
this._client.connect('notify::state', Lang.bind(this, this._syncNMState));
|
||||||
this._client.connect('notify::active-connections', Lang.bind(this, this._syncActiveConnections));
|
this._client.connect('notify::physical-connection', Lang.bind(this, this._syncMainConnection));
|
||||||
|
this._client.connect('notify::active-connections', Lang.bind(this, this._syncVPNConnections));
|
||||||
this._client.connect('device-added', Lang.bind(this, this._deviceAdded));
|
this._client.connect('device-added', Lang.bind(this, this._deviceAdded));
|
||||||
this._client.connect('device-removed', Lang.bind(this, this._deviceRemoved));
|
this._client.connect('device-removed', Lang.bind(this, this._deviceRemoved));
|
||||||
this._settings.connect('new-connection', Lang.bind(this, this._newConnection));
|
this._settings.connect('new-connection', Lang.bind(this, this._newConnection));
|
||||||
@ -1410,136 +1411,77 @@ const NMApplet = new Lang.Class({
|
|||||||
devices.splice(pos, 1);
|
devices.splice(pos, 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
_getSupportedActiveConnections: function() {
|
_ensureActiveConnectionProps: function(a) {
|
||||||
let activeConnections = this._client.get_active_connections() || [ ];
|
if (!a._connection) {
|
||||||
let supportedConnections = [];
|
a._connection = this._settings.get_connection_by_path(a.connection);
|
||||||
|
|
||||||
for (let i = 0; i < activeConnections.length; i++) {
|
// This list is guaranteed to have only one device in it.
|
||||||
let devices = activeConnections[i].get_devices();
|
let device = a.get_devices()[0]._delegate;
|
||||||
if (!devices || !devices[0])
|
a._primaryDevice = device;
|
||||||
continue;
|
|
||||||
// Ignore connections via unrecognized device types
|
|
||||||
if (!this._dtypes[devices[0].device_type])
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Ignore slave connections
|
|
||||||
let connectionPath = activeConnections[i].connection;
|
|
||||||
let connection = this._settings.get_connection_by_path(connectionPath);
|
|
||||||
|
|
||||||
// connection might be null, if libnm-glib fails to create
|
|
||||||
// the object due to version incompatibility, or if the
|
|
||||||
// connection is not visible to the current user
|
|
||||||
if (connection && this._ignoreConnection(connection))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
supportedConnections.push(activeConnections[i]);
|
|
||||||
}
|
}
|
||||||
return supportedConnections;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_syncActiveConnections: function() {
|
_getMainConnection: function() {
|
||||||
let closedConnections = [ ];
|
let connection;
|
||||||
let newActiveConnections = this._getSupportedActiveConnections();
|
|
||||||
for (let i = 0; i < this._activeConnections.length; i++) {
|
connection = this._client.get_physical_connection();
|
||||||
let a = this._activeConnections[i];
|
if (connection) {
|
||||||
if (newActiveConnections.indexOf(a) == -1) // connection is removed
|
this._ensureActiveConnectionProps(connection);
|
||||||
closedConnections.push(a);
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < closedConnections.length; i++) {
|
connection = this._client.get_activating_connection();
|
||||||
let a = closedConnections[i];
|
if (connection) {
|
||||||
if (a._type == NetworkManager.SETTING_VPN_SETTING_NAME)
|
this._ensureActiveConnectionProps(connection);
|
||||||
this._vpnSection.removeActiveConnection(a);
|
return connection;
|
||||||
if (a._inited) {
|
|
||||||
a.disconnect(a._notifyStateId);
|
|
||||||
a.disconnect(a._notifyDefaultId);
|
|
||||||
a.disconnect(a._notifyDefault6Id);
|
|
||||||
a._inited = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
_syncMainConnection: function() {
|
||||||
if (this._mainConnectionIconChangedId > 0) {
|
if (this._mainConnectionIconChangedId > 0) {
|
||||||
this._mainConnection._primaryDevice.disconnect(this._mainConnectionIconChangedId);
|
this._mainConnection._primaryDevice.disconnect(this._mainConnectionIconChangedId);
|
||||||
this._mainConnectionIconChangedId = 0;
|
this._mainConnectionIconChangedId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._activeConnections = newActiveConnections;
|
if (this._mainConnectionStateChangedId > 0) {
|
||||||
this._mainConnection = null;
|
this._mainConnection.disconnect(this._mainConnectionStateChangedId);
|
||||||
|
this._mainConnectionStateChangedId = 0;
|
||||||
let activating = null;
|
|
||||||
let default_ip4 = null;
|
|
||||||
let default_ip6 = null;
|
|
||||||
let active_any = null;
|
|
||||||
for (let i = 0; i < this._activeConnections.length; i++) {
|
|
||||||
let a = this._activeConnections[i];
|
|
||||||
|
|
||||||
if (!a._inited) {
|
|
||||||
a._notifyDefaultId = a.connect('notify::default', Lang.bind(this, this._syncActiveConnections));
|
|
||||||
a._notifyDefault6Id = a.connect('notify::default6', Lang.bind(this, this._syncActiveConnections));
|
|
||||||
a._notifyStateId = a.connect('notify::state', Lang.bind(this, this._notifyActivated));
|
|
||||||
|
|
||||||
a._inited = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!a._connection) {
|
|
||||||
a._connection = this._settings.get_connection_by_path(a.connection);
|
|
||||||
|
|
||||||
if (a._connection) {
|
|
||||||
a._type = a._connection._type;
|
|
||||||
a._section = this._ctypes[a._type];
|
|
||||||
} else {
|
|
||||||
a._connection = null;
|
|
||||||
a._type = null;
|
|
||||||
a._section = null;
|
|
||||||
log('Cannot find connection for active (or connection cannot be read)');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a['default'])
|
|
||||||
default_ip4 = a;
|
|
||||||
if (a.default6)
|
|
||||||
default_ip6 = a;
|
|
||||||
|
|
||||||
if (a.state == NetworkManager.ActiveConnectionState.ACTIVATING)
|
|
||||||
activating = a;
|
|
||||||
else if (a.state == NetworkManager.ActiveConnectionState.ACTIVATED)
|
|
||||||
active_any = a;
|
|
||||||
|
|
||||||
if (!a._primaryDevice) {
|
|
||||||
if (a._type != NetworkManager.SETTING_VPN_SETTING_NAME) {
|
|
||||||
// This list is guaranteed to have one device in it.
|
|
||||||
a._primaryDevice = a.get_devices()[0]._delegate;
|
|
||||||
} else {
|
|
||||||
a._primaryDevice = this._vpnSection;
|
|
||||||
this._vpnSection.addActiveConnection(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.state == NetworkManager.ActiveConnectionState.ACTIVATED
|
|
||||||
&& a._primaryDevice && a._primaryDevice._notification) {
|
|
||||||
a._primaryDevice._notification.destroy();
|
|
||||||
a._primaryDevice._notification = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._mainConnection = default_ip4 || default_ip6 || active_any || activating || null;
|
this._mainConnection = this._getMainConnection();
|
||||||
|
|
||||||
if (this._mainConnection) {
|
if (this._mainConnection) {
|
||||||
let dev = this._mainConnection._primaryDevice;
|
if (this._mainConnection._primaryDevice)
|
||||||
this._mainConnectionIconChangedId = dev.connect('icon-changed', Lang.bind(this, this._updateIcon));
|
this._mainConnectionIconChangedId = this._mainConnection._primaryDevice.connect('icon-changed', Lang.bind(this, this._updateIcon));
|
||||||
|
this._mainConnectionStateChangedId = this._mainConnection.connect('notify::state', Lang.bind(this, this._mainConnectionStateChanged));
|
||||||
|
this._mainConnectionStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._updateIcon();
|
this._updateIcon();
|
||||||
},
|
},
|
||||||
|
|
||||||
_notifyActivated: function(activeConnection) {
|
_syncVPNConnections: function() {
|
||||||
if (activeConnection.state == NetworkManager.ActiveConnectionState.ACTIVATED
|
let activeConnections = this._client.get_active_connections() || [];
|
||||||
&& activeConnection._primaryDevice && activeConnection._primaryDevice._notification) {
|
let vpnConnections = activeConnections.filter(function(a) {
|
||||||
activeConnection._primaryDevice._notification.destroy();
|
return (a instanceof NMClient.VPNConnection);
|
||||||
activeConnection._primaryDevice._notification = null;
|
});
|
||||||
}
|
vpnConnections.forEach(Lang.bind(this, function(a) {
|
||||||
|
this._ensureActiveConnectionProps(a);
|
||||||
|
}));
|
||||||
|
this._vpnSection.setActiveConnections(vpnConnections);
|
||||||
|
|
||||||
this._syncActiveConnections();
|
this._updateIcon();
|
||||||
|
},
|
||||||
|
|
||||||
|
_mainConnectionStateChanged: function() {
|
||||||
|
let a = this._mainConnection;
|
||||||
|
let dev = a._primaryDevice;
|
||||||
|
if (a.state == NetworkManager.ActiveConnectionState.ACTIVATED && dev && dev._notification) {
|
||||||
|
dev._notification.destroy();
|
||||||
|
dev._notification = null;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_ignoreConnection: function(connection) {
|
_ignoreConnection: function(connection) {
|
||||||
@ -1576,7 +1518,6 @@ const NMApplet = new Lang.Class({
|
|||||||
|
|
||||||
_newConnection: function(settings, connection) {
|
_newConnection: function(settings, connection) {
|
||||||
this._addConnection(connection);
|
this._addConnection(connection);
|
||||||
this._syncActiveConnections();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_connectionRemoved: function(connection) {
|
_connectionRemoved: function(connection) {
|
||||||
@ -1627,24 +1568,18 @@ const NMApplet = new Lang.Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_syncNMState: function() {
|
_syncNMState: function() {
|
||||||
this._syncActiveConnections();
|
|
||||||
|
|
||||||
this.indicators.visible = this._client.manager_running;
|
this.indicators.visible = this._client.manager_running;
|
||||||
this.menu.actor.visible = this._client.networking_enabled;
|
this.menu.actor.visible = this._client.networking_enabled;
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateIcon: function() {
|
_updateIcon: function() {
|
||||||
let mc = this._mainConnection;
|
if (!this._client.networking_enabled || !this._mainConnection) {
|
||||||
|
|
||||||
if (!this._client.networking_enabled || !mc) {
|
|
||||||
this._primaryIndicator.icon_name = 'network-offline-symbolic';
|
this._primaryIndicator.icon_name = 'network-offline-symbolic';
|
||||||
} else {
|
} else {
|
||||||
let dev = this._mainConnection._primaryDevice;
|
let dev = this._mainConnection._primaryDevice;
|
||||||
if (!dev) {
|
this._primaryIndicator.visible = (dev != null);
|
||||||
log('Active connection with no primary device?');
|
if (dev)
|
||||||
return;
|
this._primaryIndicator.icon_name = dev.getIndicatorIcon();
|
||||||
}
|
|
||||||
this._primaryIndicator.icon_name = dev.getIndicatorIcon(mc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._vpnIndicator.icon_name = this._vpnSection.getIndicatorIcon();
|
this._vpnIndicator.icon_name = this._vpnSection.getIndicatorIcon();
|
||||||
|
Loading…
Reference in New Issue
Block a user