Skip to content
91 changes: 70 additions & 21 deletions files/usr/share/cinnamon/applets/network@cinnamon.org/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ NMNetworkMenuItem.prototype = {
accessPoints = sortAccessPoints(accessPoints);
this.bestAP = accessPoints[0];
this._accessPoints = [ ];
for (let i = 0; i < accessPoints; i++) {
for (let i = 0; i < accessPoints.length; i++) {
let ap = accessPoints[i];
let apObj = {
ap: ap,
Expand Down Expand Up @@ -1041,7 +1041,8 @@ NMDeviceVPN.prototype = {
for (let obj of this._connections) {
if (!obj.item) {
obj.item = new PopupMenu.PopupMenuItem(obj.name);
this._updateConnectionItemView(obj.item, obj.connection);
this._updateConnectionItemView(obj.item, obj.connection,
this._activeConnections.some(ac => ac.connection == obj.connection));
obj.item.connect('activate', Lang.bind(this, function() {
let activeConnection = this._activeConnections.find(ac => ac.connection === obj.connection);
if (activeConnection) {
Expand Down Expand Up @@ -1072,6 +1073,8 @@ NMDeviceWIREGUARD.prototype = {
this.category = NMConnectionCategory.WIREGUARD;
this._type = NM.SETTING_WIREGUARD_SETTING_NAME;

this._activeConnections = [];

NMDevice.prototype._init.call(this, client, null, [ ]);

// Tests:
Expand All @@ -1088,25 +1091,63 @@ NMDeviceWIREGUARD.prototype = {
},

get connected() {
return !!this._activeConnection;
return this._activeConnections.length > 0;
},

setActiveConnection: function(activeConnection) {
if (activeConnection) {
activeConnection._type = NM.SETTING_WIREGUARD_SETTING_NAME;
}
NMDevice.prototype.setActiveConnection.call(this, activeConnection);
setActiveConnections: function(activeConnections) {
this._activeConnections = activeConnections || [];

this.emit('active-connection-changed');
this._createSection();
this.emit('active-connections-changed');
},

_shouldShowConnectionList: function() {
return true;
},

deactivate: function() {
if (this._activeConnection)
this._client.deactivate_connection(this._activeConnection, null);
for (let ac of this._activeConnections)
this._client.deactivate_connection(ac, null);

this._activeConnections = [];
},

_clearSection: function() {
if (this.section && this.section.removeAll)
this.section.removeAll();

this._autoConnectionItem = null;
this._overflowItem = null;

for (let i = 0; i < this._connections.length; i++) {
if (this._connections[i].item && this._connections[i].item.destroy)
this._connections[i].item.destroy();

this._connections[i].item = null;
}
},

/* A switch per tunnel: WireGuard connections are independent of one another,
so they are not a pick-one list. */
_createSection: function() {
for (let obj of this._connections) {
let active = this._activeConnections.some(ac => ac.connection == obj.connection);

if (!obj.item) {
obj.item = new PopupMenu.PopupSwitchMenuItem(obj.name, active);
obj.item.connect('toggled', (item, state) => {
let activeConnection = this._activeConnections.find(ac => ac.connection === obj.connection);

if (!state && activeConnection)
this._client.deactivate_connection(activeConnection, null);
else if (state && !activeConnection)
this._client.activate_connection_async(obj.connection, this.device, null, null, null);
});
this.section.addMenuItem(obj.item);
} else {
obj.item.setToggleState(active);
}
}
},

statusLabel: null,
Expand Down Expand Up @@ -1904,9 +1945,9 @@ CinnamonNetworkApplet.prototype = {
device: new NMDeviceWIREGUARD(this._client),
item: new NMWiredSectionTitleMenuItem(_("WIREGUARD Connections"))
};
this._devices.wireguard.device.connect('active-connection-changed', Lang.bind(this, function() {
this._devices.wireguard.device.connect('active-connections-changed', () => {
this._devices.wireguard.item.updateForDevice(this._devices.wireguard.device);
}));
});
this._devices.wireguard.item.updateForDevice(this._devices.wireguard.device);
this._devices.wireguard.section.addMenuItem(this._devices.wireguard.item);
this._devices.wireguard.section.addMenuItem(this._devices.wireguard.device.section);
Expand Down Expand Up @@ -2148,6 +2189,8 @@ CinnamonNetworkApplet.prototype = {
if (active._primaryDevice) {
if (active._type == NM.SETTING_VPN_SETTING_NAME)
this._devices.vpn.device.setActiveConnections([]);
else if (active._type == NM.SETTING_WIREGUARD_SETTING_NAME)
this._devices.wireguard.device.setActiveConnections([]);
else
active._primaryDevice.setActiveConnection(null);

Expand All @@ -2169,6 +2212,7 @@ CinnamonNetworkApplet.prototype = {
let default_ip6 = null;

let vpnConnections = [];
let wireguardConnections = [];

for (let a of this._activeConnections) {
if (!a._inited) {
Expand Down Expand Up @@ -2245,17 +2289,21 @@ CinnamonNetworkApplet.prototype = {
}

if (a._primaryDevice) {
if (a._type == NM.SETTING_VPN_SETTING_NAME) {
if (a._type == NM.SETTING_VPN_SETTING_NAME)
vpnConnections.push(a);
} else {
else if (a._type == NM.SETTING_WIREGUARD_SETTING_NAME)
wireguardConnections.push(a);
else
a._primaryDevice.setActiveConnection(a);
}
}
}

if (this._devices.vpn && this._devices.vpn.device)
this._devices.vpn.device.setActiveConnections(vpnConnections);

if (this._devices.wireguard && this._devices.wireguard.device)
this._devices.wireguard.device.setActiveConnections(wireguardConnections);

this._mainConnection = activated || activating || default_ip4 || default_ip6 || null;
},

Expand Down Expand Up @@ -2301,7 +2349,7 @@ CinnamonNetworkApplet.prototype = {
_connectionRemoved: function(client, connection) {
let pos = this._connections.indexOf(connection);
if (pos != -1)
this._connections.splice(pos);
this._connections.splice(pos, 1);

let section = connection._section;

Expand Down Expand Up @@ -2532,10 +2580,9 @@ CinnamonNetworkApplet.prototype = {
let iconName = 'xsi-network-vpn';
if (mc._section == NMConnectionCategory.WIRELESS) {
const dev = mc._primaryDevice;
if (dev) {
const ap = dev.device.active_access_point;
iconName = 'xsi-network-wireless-signal-' + signalToIcon(ap.strength) + '-secure-symbolic';
}
const ap = dev ? dev.device.active_access_point : null;
if (ap)
iconName = 'xsi-network-wireless-signal-' + signalToIcon(ap.strength) + '-secure';
}
this._setIcon(iconName);
this.set_applet_tooltip(_("Connected to the VPN"));
Expand Down Expand Up @@ -2605,6 +2652,8 @@ CinnamonNetworkApplet.prototype = {
if (this._activeConnections.some(con => con.get_connection_type() === "wireguard")) {
return NM.ConnectivityState.FULL;
}

return state;
},

_proxyConnectivityCheckCallback(new_state) {
Expand Down
Loading