Skip to content

Commit

Permalink
Merge pull request #10 from hamiller/main
Browse files Browse the repository at this point in the history
Updated to gnome 45
  • Loading branch information
phavekes authored Sep 22, 2023
2 parents f2f14de + 6701ae5 commit a82fd3b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 55 deletions.
84 changes: 39 additions & 45 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';

const Main = imports.ui.main;
const Mainloop = imports.mainloop;

const St = imports.gi.St;
const PanelMenu = imports.ui.panelMenu;
const Clutter = imports.gi.Clutter;
const GLib = imports.gi.GLib;
const ShellToolkit = imports.gi.St;
const GObject = imports.gi.GObject;
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
import St from 'gi://St';
import Clutter from 'gi://Clutter';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';

// Start with WAN address as default
var type=4;
Expand Down Expand Up @@ -119,7 +117,11 @@ function _get_wan_ip4() {
return wanIpAddress;
}

var AllIPAddressIndicator = class AllIPAddressIndicator extends PanelMenu.Button{
class AllIPAddressIndicator extends PanelMenu.Button{

static {
GObject.registerClass(this);
}

_init() {
// Chaining up to the super-class
Expand All @@ -133,14 +135,28 @@ var AllIPAddressIndicator = class AllIPAddressIndicator extends PanelMenu.Button
this._updateLabel();
}

_toggleView(){
console.log("Updating label for all-ip extension")
if (type===4) {
type=6;
} else if (type===6) {
type=0;
} else if (type===0){
type=1;
} else if (type===1){
type=4
}
this._updateLabel();
}

_updateLabel(){
const refreshTime = 20 // in seconds

if (this._timeout) {
Mainloop.source_remove(this._timeout);
GLib.source_remove(this._timeout);
this._timeout = null;
}
this._timeout = Mainloop.timeout_add_seconds(refreshTime, () => {this._updateLabel();});
this._timeout = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, refreshTime, () => {this._updateLabel();});
// Show the right format. 0 = WAN, 4 = IPv4, 6=IPv6
if (type===4) {
this.buttonText.set_text("LAN: "+_get_lan_ip4());
Expand All @@ -161,47 +177,25 @@ var AllIPAddressIndicator = class AllIPAddressIndicator extends PanelMenu.Button

stop() {
if (this._timeout) {
Mainloop.source_remove(this._timeout);
GLib.source_remove(this._timeout);
}
this._timeout = undefined;

this.menu.removeAll();
}
}
// In gnome-shell >= 3.32 this class and several others became GObject
// subclasses. We can account for this change simply by re-wrapping our
// subclass in `GObject.registerClass()`
AllIPAddressIndicator = GObject.registerClass(
{GTypeName: 'AllIPAddressIndicator'},
AllIPAddressIndicator
);

let _indicator;

function init() {
}

function enable() {
_indicator = new AllIPAddressIndicator();
Main.panel.addToStatusArea('all-ip-addresses-indicator', _indicator);
_indicator.connect('button-press-event', _toggle);
}
export default class AllIPAddressExtension extends Extension {

function disable() {
_indicator.stop();
_indicator.destroy();
_indicator = null;
}
enable() {
this._indicator = new AllIPAddressIndicator();
Main.panel.addToStatusArea('all-ip-addresses-indicator', this._indicator);
this._indicator.connect('button-press-event', () => this._indicator._toggleView());
}

function _toggle() {
if (type===4) {
type=6;
} else if (type===6) {
type=0;
} else if (type===0){
type=1;
} else if (type===1){
type=4
disable() {
this._indicator.stop();
this._indicator.destroy();
this._indicator = null;
}
_indicator._updateLabel();
}
12 changes: 2 additions & 10 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@
"description": "Show IP addresses for LAN, WAN IPv6 and VPN in the GNOME panel. Click on the address to cycle trough different interfaces.",
"name": "All IP Addresses",
"shell-version": [
"3.32",
"3.34",
"3.36",
"3.38",
"40",
"41",
"42",
"43",
"44"
"45"
],
"url": "https://github.com/phavekes/gnome-extension-all-ip-addresses",
"uuid": "[email protected]",
"version": 12
"version": 13
}

0 comments on commit a82fd3b

Please sign in to comment.