Skip to content

Commit

Permalink
if more than 6 peers add scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
joaophi committed Nov 28, 2023
1 parent a5ce530 commit 298aee5
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ const TailscaleIndicator = GObject.registerClass(
}
);

const PopupScrollableSubMenuMenuItem = GObject.registerClass(
class PopupScrollableSubMenuMenuItem extends PopupMenu.PopupSubMenuMenuItem {
_init(props) {
super._init(props);

this.menu._needsScrollbar = () => true;
this.menu.box.height = 200;
}
}
)

const TailscaleDeviceItem = GObject.registerClass(
class TailscaleDeviceItem extends PopupMenu.PopupBaseMenuItem {
_init(icon_name, text, subtitle, onClick, onLongClick) {
Expand Down Expand Up @@ -142,9 +153,19 @@ const TailscaleMenuToggle = GObject.registerClass(
const nodes = new PopupMenu.PopupMenuSection();
const update_nodes = (obj) => {
nodes.removeAll();
const mullvad = new PopupMenu.PopupSubMenuMenuItem("Mullvad", false, {});

// Prepare menu sections for non-Mullvad and Mullvad nodes
const peers = new PopupScrollableSubMenuMenuItem("Nodes", false, {});
const mullvad = new PopupScrollableSubMenuMenuItem("Mullvad", false, {});

const useSubmenu = obj.nodes.filter(node => !node.mullvad).length > 6;

for (const node of obj.nodes) {
const menu = (node.mullvad && !node.exit_node) ? mullvad.menu : nodes;
const menu = (node.mullvad && !node.exit_node)
? mullvad.menu
: (useSubmenu && !node.exit_node)
? peers.menu
: nodes;
const device_icon = !node.online
? "network-offline-symbolic"
: ((node.os == "android" || node.os == "iOS")
Expand All @@ -166,6 +187,11 @@ const TailscaleMenuToggle = GObject.registerClass(

menu.addMenuItem(new TailscaleDeviceItem(device_icon, node.name, subtitle, onClick, onLongClick));
}
if (peers.menu.isEmpty()) {
peers.destroy();
} else {
nodes.addMenuItem(peers);
}
if (mullvad.menu.isEmpty()) {
mullvad.destroy();
} else {
Expand Down

0 comments on commit 298aee5

Please sign in to comment.