Skip to content

Commit

Permalink
add exitnode as subtitle
Browse files Browse the repository at this point in the history
Co-authored-by: rjocoleman <[email protected]>
  • Loading branch information
joaophi and rjocoleman committed Nov 28, 2023
1 parent c7a7f5e commit b3f8b01
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
7 changes: 6 additions & 1 deletion [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,18 @@ const TailscaleMenuToggle = GObject.registerClass(
toggleMode: true,
menuEnabled: true,
});

this.title = "Tailscale";
tailscale.bind_property("running", this, "checked", GObject.BindingFlags.SYNC_CREATE | GObject.BindingFlags.BIDIRECTIONAL);

// This function is unique to this class. It adds a nice header with an
// icon, title and optional subtitle. It's recommended you do so for
// consistency with other menus.
this.menu.setHeader(icon, this.title);
tailscale.connect("notify::exit-node", () => {
this.subtitle = tailscale.exit_node_name;
this.menu.setHeader(icon, this.title, this.subtitle);
});
this.menu.setHeader(icon, this.title, tailscale.exit_node_name);

// NODES
const nodes = new PopupMenu.PopupMenuSection();
Expand Down
38 changes: 28 additions & 10 deletions [email protected]/tailscale.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export const Tailscale = GObject.registerClass(
GObject.ParamFlags.READWRITE,
""
),
"exit-node-name": GObject.ParamSpec.string(
"exit-node", "", "",
GObject.ParamFlags.READABLE,
""
),
"nodes": GObject.ParamSpec.jsobject(
"nodes", "", "",
GObject.ParamFlags.READABLE,
Expand All @@ -111,6 +116,7 @@ export const Tailscale = GObject.registerClass(
this._shields_up = false;
this._ssh = false;
this._exit_node = "";
this._exit_node_name = null;
this._nodes = [];
this._cancelable = new Gio.Cancellable();
this._listen();
Expand All @@ -130,16 +136,20 @@ export const Tailscale = GObject.registerClass(

_process_nodes(prefs, peers) {
const nodes = peers
.map(peer => ({
id: peer.ID,
name: peer.DNSName.split(".")[0],
os: peer.OS,
exit_node: peer.ID == prefs.ExitNodeID,
exit_node_option: peer.ExitNodeOption,
online: peer.Online,
ips: peer.TailscaleIPs,
mullvad: peer.Tags?.includes("tag:mullvad-exit-node") || false,
}))
.map(peer => {
const node = {
id: peer.ID,
name: peer.DNSName.split(".")[0],
os: peer.OS,
exit_node: peer.ID == prefs.ExitNodeID,
exit_node_option: peer.ExitNodeOption,
online: peer.Online,
ips: peer.TailscaleIPs,
mullvad: peer.Tags?.includes("tag:mullvad-exit-node") || false,
location: peer.Location,
};
return node;
})
.sort((a, b) =>
(b.exit_node - a.exit_node)
|| (b.online - a.online)
Expand All @@ -158,6 +168,9 @@ export const Tailscale = GObject.registerClass(
if (exit_node_id != this._exit_node) {
this._exit_node = exit_node_id;
this.notify("exit-node");
const exitNodePeer = this._peers.find(peer => peer.ID === exit_node_id);
this._exit_node_name = exitNodePeer ? exitNodePeer.DNSName.split(".")[0] : null;
this.notify("exit-node-name");
}
}

Expand Down Expand Up @@ -278,6 +291,10 @@ export const Tailscale = GObject.registerClass(
this._update_prefs({ ExitNodeID: value });
}

get exit_node_name() {
return this._exit_node_name;
}

get nodes() {
return this._nodes;
}
Expand Down Expand Up @@ -307,6 +324,7 @@ export const Tailscale = GObject.registerClass(
Online: peer.Online,
TailscaleIPs: peer.Addresses.map(address => address.split("/")[0]),
Tags: peer.Tags,
Location: peer.Hostinfo.Location
}));
should_update = true;
}
Expand Down

0 comments on commit b3f8b01

Please sign in to comment.