Skip to content

Commit

Permalink
Merge pull request #42 from Isopolito/v16_merge
Browse files Browse the repository at this point in the history
V16 merge
  • Loading branch information
Isopolito authored Dec 4, 2022
2 parents f4d5090 + 638fdfb commit 4a44389
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 116 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.swp
.idea
*.orig
2 changes: 0 additions & 2 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const VpnIndicator = GObject.registerClass({

let status = this._vpn.getStatus();
status.loggedin = this.loggedin;

status.currentState = this._vpn.isNordVpnRunning()
? this.stateManager.resolveState(status)
: this.stateManager.resolveState(null);
Expand Down Expand Up @@ -308,7 +307,6 @@ const VpnIndicator = GObject.registerClass({

this._vpn.applySettingsToNord();
this._buildIndicatorMenu();

this._refresh();
}

Expand Down
6 changes: 2 additions & 4 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
"description": "A Gnome extension that shows the NordVPN status in the top bar and provides the ability to configure certain aspects of the connection.",
"name": "gNordVPN-Local",
"shell-version": [
"40",
"41",
"42"
"43"
],
"url": "https://github.com/Isopolito/gNordVPN-Local",
"uuid": "gnordvpn-local@isopolito",
"version": 15
"version": 16
}
15 changes: 8 additions & 7 deletions modules/CommonFavorite.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ var CommonFavorite = class CommonFavorite extends MenuBase {
this._signals = new Signals();
}

disable() {
this._isBuilt = false;
this._destroyMap = {};
this.favList = {};
this.itemList = {};
}

updateFavorite() {

let newFav = {};

Object.keys(Constants.favorites).forEach(key => {
Expand Down Expand Up @@ -174,11 +182,4 @@ var CommonFavorite = class CommonFavorite extends MenuBase {
this._favoriteMenu.show();
}
}

disable() {
this._isBuilt = false;
this._destroyMap = {};
this.favList = {};
this.itemList = {};
}
}
23 changes: 13 additions & 10 deletions modules/StateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,26 @@ var StateManager = class StateManager {
this.stateOverrideCounter += 1;

let overrideFromKey = (this.stateOverride.overrideKeys && (
(this.stateOverride.overrideKeys[0] === 'countries' && this.stateOverride.overrideKeys[1].replace(/_/g, " ") === status.country) ||
(this.stateOverride.overrideKeys[0] === 'cities' && this.stateOverride.overrideKeys[1].replace(/_/g, " ") === status.city) ||
(this.stateOverride.overrideKeys[0] === 'servers' && this.stateOverride.overrideKeys[1] === status.currentServer.replace('.nordvpn.com',''))))
(this.stateOverride.overrideKeys[0] === 'countries' && this.stateOverride.overrideKeys[1].replace(/_/g, " ") === status.country) ||
(this.stateOverride.overrideKeys[0] === 'cities' && this.stateOverride.overrideKeys[1].replace(/_/g, " ") === status.city) ||
(this.stateOverride.overrideKeys[0] === 'servers' && this.stateOverride.overrideKeys[1] === status.currentServer.replace('.nordvpn.com', ''))))

if (this.stateOverrideCounter > this.STATE_OVERRIDE_DURATION ||
(vpnState.clearsOverrideId == this.stateOverride.overrideId) || overrideFromKey) {
if (this.stateOverrideCounter > this.STATE_OVERRIDE_DURATION ||
(vpnState.clearsOverrideId == this.stateOverride.overrideId) || overrideFromKey) {
// State override expired or cleared by current state, remove it
this.stateOverride = undefined;
this.stateOverrideCounter = 0;

} else {
// State override still active
} else {
// State override still active
vpnState = this.stateOverride;
}
}

return {...vpnState, 'refreshTimeout': this.quickRefresh ? this.QUICK_REFRESH_TIMEOUT : vpnState['refreshTimeout'] };
}

return {
...vpnState,
'refreshTimeout': this.quickRefresh ? this.QUICK_REFRESH_TIMEOUT : vpnState['refreshTimeout']
};
}
}

12 changes: 5 additions & 7 deletions modules/Vpn.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const ExtensionUtils = imports.misc.extensionUtils;
const Soup = imports.gi.Soup;

const CMD_VPNSTATUS = `nordvpn status`;
const CMD_VPNACCOUNT = `nordvpn account`;
const CMD_COUNTRIES = `nordvpn countries`;
Expand All @@ -20,7 +21,7 @@ var Vpn = class Vpn {
this.executeCommandAsync = GLib.spawn_command_line_async;
this.settings = ExtensionUtils.getSettings(`org.gnome.shell.extensions.gnordvpn-local`);
this.session = Soup.Session.new();
this.soupVersion = Soup.get_major_version();
this.soupVersion = Soup.get_major_version();
}

_httpGet = (url) => {
Expand All @@ -35,7 +36,7 @@ var Vpn = class Vpn {
}
return JSON.parse(this._getString(msg.response_body_data.get_data()));
}

// Remove the junk that shows up from messages in the nordvpn output
_processCityCountryOutput = (input) => {
const match = input.match(/(^\w+?,\s(\w+?,\s)+?(\w+?$)|^\s*?\w+?\s*?$)/gm);
Expand Down Expand Up @@ -111,7 +112,6 @@ var Vpn = class Vpn {
}
}


applySettingsToNord() {
if (!this.isNordVpnRunning()) return;

Expand All @@ -134,7 +134,6 @@ var Vpn = class Vpn {
}

getAccount() {
// Read the VPN status from the command line
const standardOut = this._executeCommand(CMD_VPNACCOUNT);
const allAccountMessages = standardOut.split(`\n`);

Expand All @@ -153,7 +152,6 @@ var Vpn = class Vpn {
return standardOut.replace(/\s+/g, ` `).includes('You are already logged in.');
}


getStatus() {
const standardOut = this._executeCommand(CMD_VPNSTATUS);
const allStatusMessages = standardOut.split(`\n`);
Expand Down Expand Up @@ -273,8 +271,8 @@ var Vpn = class Vpn {
let processedCities = {};

for (let i = 0; i < citiesSaved.length; i++) {
const standardOut = this._executeCommand(`${CMD_CITIES} ${citiesSaved[i]}`);
const cities = this._processCityCountryOutput(standardOut);
const [ok, standardOut, standardError, exitStatus] = this.executeCommandSync(`${CMD_CITIES} ${citiesSaved[i]}`);
const cities = this._processCityCountryOutput(this._getString(standardOut));

for (let j = 0; j < cities.length; j++) {
if (j > citiesMax) break;
Expand Down
Loading

0 comments on commit 4a44389

Please sign in to comment.