Skip to content

Commit

Permalink
Merge pull request #84 from Isopolito/Gnome45
Browse files Browse the repository at this point in the history
Gnome45
  • Loading branch information
Isopolito authored Jan 6, 2024
2 parents 16a817c + e337701 commit ca92b6a
Show file tree
Hide file tree
Showing 18 changed files with 1,206 additions and 1,228 deletions.
395 changes: 19 additions & 376 deletions extension.js

Large diffs are not rendered by default.

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": [
"42",
"43",
"44"
"45"
],
"url": "https://github.com/Isopolito/gNordVPN-Local",
"uuid": "gnordvpn-local@isopolito",
"version": 23
"version": 25
}
38 changes: 17 additions & 21 deletions modules/CommonFavorite.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
'use strict';
const PopupMenu = imports.ui.popupMenu;

// gNordVpn-Local modules
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Vpn = Me.imports.modules.Vpn.Vpn;
const Constants = Me.imports.modules.constants;
const Signals = Me.imports.modules.Signals.Signals;
const MenuBase = Me.imports.modules.MenuBase.MenuBase;
const Favorites = Me.imports.modules.Favorites.Favorites;

var CommonFavorite = class CommonFavorite extends MenuBase {
constructor(connectionCallback) {
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';

import Vpn from './Vpn.js';
import Signals from './Signals.js';
import Favorites from './Favorites.js';
import MenuBase from './MenuBase.js';
import * as Constants from './constants.js';

export default class CommonFavorite extends MenuBase {
constructor(connectionCallback, settings) {
super();
this._connectionCallback = connectionCallback;
this._isBuilt = false;
Expand All @@ -20,8 +16,8 @@ var CommonFavorite = class CommonFavorite extends MenuBase {
this._destroyMap = {};
this.prevShowHide = true;

this._favorites = new Favorites();
this._vpn = new Vpn();
this._favorites = new Favorites(settings);
this._vpn = new Vpn(settings);
this._signals = new Signals();
}

Expand Down Expand Up @@ -85,11 +81,11 @@ var CommonFavorite = class CommonFavorite extends MenuBase {
}

_toggleFavoriteMenuItem(favorite, toAdd) {
let d = this._destroyMap[favorite];
if (d) {
this._signals.disconnect([d.menuItemClickId, d.menuItem.favoritePressId]);
d.icofavBtn.destroy();
d.menuItem.destroy();
let menuItemElements = this._destroyMap[favorite];
if (menuItemElements) {
this._signals.disconnect([menuItemElements.menuItemClickId, menuItemElements.menuItem.favoritePressId]);
menuItemElements.icofavBtn.destroy();
menuItemElements.menuItem.destroy();
}

if (toAdd) {
Expand Down
30 changes: 13 additions & 17 deletions modules/ConnectionMenu.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
'use strict';
const PopupMenu = imports.ui.popupMenu;

// gNordVpn-Local modules
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Vpn = Me.imports.modules.Vpn.Vpn;
const Constants = Me.imports.modules.constants;
const Signals = Me.imports.modules.Signals.Signals;
const MenuBase = Me.imports.modules.MenuBase.MenuBase;
const Favorites = Me.imports.modules.Favorites.Favorites;
const Common = Me.imports.modules.common;

var ConnectionMenu = class ConnectionMenu extends MenuBase {
constructor(connectionLabel, connectionType, favoritesKey, connectionCallback) {
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';

import Vpn from './Vpn.js';
import Signals from './Signals.js';
import Favorites from './Favorites.js';
import MenuBase from './MenuBase.js';
import * as Common from './common.js';
import * as Constants from './constants.js';

export default class ConnectionMenu extends MenuBase {
constructor(connectionLabel, connectionType, favoritesKey, connectionCallback, settings) {
super();
this._connectionCallback = connectionCallback;
this._connectionMenu = null;
Expand All @@ -22,8 +18,8 @@ var ConnectionMenu = class ConnectionMenu extends MenuBase {
this._menuSeperator = null;
this._destroyMap = {};

this._favorites = new Favorites();
this._vpn = new Vpn();
this._favorites = new Favorites(settings);
this._vpn = new Vpn(settings);
this._signals = new Signals();

this._connectionLabel = connectionLabel;
Expand Down
8 changes: 3 additions & 5 deletions modules/Favorites.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const ExtensionUtils = imports.misc.extensionUtils;

var Favorites = class Favorites {
constructor() {
this._settings = ExtensionUtils.getSettings(`org.gnome.shell.extensions.gnordvpn-local`);
export default class Favorites {
constructor(settings) {
this._settings = settings;
}

_getData(a) { return this._settings.get_string(a); }
Expand Down
9 changes: 6 additions & 3 deletions modules/MenuBase.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const St = imports.gi.St;
const Clutter = imports.gi.Clutter;
import St from 'gi://St';
import Clutter from 'gi://Clutter';

export default class MenuBase {
constructor() {
}

var MenuBase = class MenuBase {
buildFavIcon(isFavorite) {
const icon_name = isFavorite ? `starred-symbolic` : `non-starred-symbolic`;
const iconfav = new St.Icon({
Expand Down
19 changes: 9 additions & 10 deletions modules/PanelIcon.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
const St = imports.gi.St;
const ExtensionUtils = imports.misc.extensionUtils;
import St from 'gi://St';
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';

const Me = ExtensionUtils.getCurrentExtension();
const Constants = Me.imports.modules.constants;
import * as Constants from './constants.js';

var PanelIcon = class PanelIcon {
constructor() {
this.settings = ExtensionUtils.getSettings(`org.gnome.shell.extensions.gnordvpn-local`);
export default class PanelIcon {
constructor(settings) {
this._settings = settings;

this.uiMap = {};
this.commonStyle = "";
this.updateStyle();
}

updateStyle() {
let savedStyle = this.settings.get_value('panel-styles').deep_unpack();
let savedStyle = this._settings.get_value('panel-styles').deep_unpack();

this.uiMap = {};
Object.keys(savedStyle).forEach(key => {
this.uiMap[Constants.states[key]] = savedStyle[key];
});

this.commonStyle = this.settings.get_string(`common-panel-style`);
this.commonStyle = this._settings.get_string(`common-panel-style`);
}

update(status) {
if (!status || this._label.isDisposed) return;

let config = this.uiMap[status.currentState.stateName];
let msg = config.panelText
if (status.currentState.stateName == 'Status: Connected')
if (status.currentState.stateName === 'Status: Connected')
msg = msg.replaceAll('{country}', status.country)
.replaceAll('{COUNTRY}', status.country.toUpperCase())
.replaceAll('{ctry}', status.currentServer.replace(/(\d|.nordvpn.com)/g, '').toUpperCase())
Expand Down
25 changes: 25 additions & 0 deletions modules/ProcCom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';

export default class ProcCom {
constructor(props) {
Gio._promisify(Gio.Subprocess.prototype, 'communicate_utf8_async');
}

async execCommunicateAsync(command, input = null) {
let argv = command.split(/\s+/);
try {
const proc = Gio.Subprocess.new(argv, Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE);
const [stdout, stderr] = await proc.communicate_utf8_async(null, null);

if (proc.get_successful()) return stdout;
else throw new Error(stderr);
} catch (e) {
logError(e, `gnordvpn`);
}
}

execCommunicateSync(command) {
return GLib.spawn_command_line_sync(command);
}
}
2 changes: 1 addition & 1 deletion modules/Signals.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Signals = class Signals {
export default class Signals {
constructor() {
this._ids = {};
}
Expand Down
9 changes: 2 additions & 7 deletions modules/StateManager.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// noinspection ES6ConvertVarToLetConst
'use strict';
const ExtensionUtils = imports.misc.extensionUtils;
import * as Constants from './constants.js';

const Me = ExtensionUtils.getCurrentExtension();
const Constants = Me.imports.modules.constants;

var StateManager = class StateManager {
export default class StateManager {
constructor() {
this.STATE_OVERRIDE_UNSET = -1;
this.stateOverride = undefined;
Expand Down
Loading

0 comments on commit ca92b6a

Please sign in to comment.