-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
70 lines (52 loc) · 1.85 KB
/
extension.js
File metadata and controls
70 lines (52 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const St = imports.gi.St;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const GLib = imports.gi.GLib;
let button;
function _showInterfaceInformation() {
button.menu.removeAll();
let [_, out] = GLib.spawn_command_line_sync('ifconfig');
out = out.toString();
let lines = out.split('\n');
for (i=0; i < lines.length; i++) {
let intf_name = lines[i].split(' ')[0];
if (intf_name.length) {
let ipv4_addr = lines[i + 1].match(/\d+.\d+.\d+.\d+/g);
let ipv6_line = lines[i + 2];
ipv6_line = ipv6_line.split(' ');
// Find if interface has ipv6 address
for (j=0; j < ipv6_line.length; j++) {
if (ipv6_line[j] == 'inet6') {
ipv6_addr = ipv6_line[j + 2];
break;
}
}
let ipv4_menu = "\n\tIPv4: " + ipv4_addr[0];
let menu_name = intf_name;
// If ipv6 address exists add to menu
if (ipv6_addr.length) {
let ipv6_menu = "\n\tIPv6: " + ipv6_addr;
menu_name += ipv4_menu + ipv6_menu;
} else {
menu_name += ipv4_menu;
}
let item = new PopupMenu.PopupSwitchMenuItem(menu_name, true);
button.menu.addMenuItem(item);
}
}
}
function init() {
}
function enable() {
button = new PanelMenu.Button(0.0);
let icon = new St.Icon({ icon_name: 'system-run-symbolic',
style_class: 'system-status-icon' });
button.actor.add_actor(icon);
button.actor.add_style_class_name('panel-status-button');
button.actor.connect('button-press-event', _showInterfaceInformation);
Main.panel.addToStatusArea('services', button);
}
function disable() {
button.destroy();
}