How to ensure GNOME Shell panel is fully populated before accessing Main.panel._leftBox, _centerBox, _rightBox?

I’m writing a GNOME Shell extension and I need to inspect or move items inside the panel boxes (_leftBox, _centerBox, _rightBox).

The problem is: if I run my code inside enable(), the panel is sometimes not yet fully populated, so statusArea items (like battery, wifi, keyboard, date menu, etc.) are incomplete.

Here’s a simplified version of what I’m doing:

journal('=== LEFT BOX ===');
Main.panel._leftBox.get_children().forEach((child, index) => {
    journal(`${index}: ${child}`);
});

journal('=== CENTER BOX ===');
Main.panel._centerBox.get_children().forEach((child, index) => {
    journal(`${index}: ${child}`);
});

journal('=== RIGHT BOX ===');
Main.panel._rightBox.get_children().forEach((child, index) => {
    journal(`${index}: ${child}`);
});

I tried GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => { and Main.layoutManager.connect('startup-complete', both does not guarantee the panel is fully populated.

What is the correct way to ensure the GNOME Shell panel is fully built and all indicators are loaded before I run this code?

Is there a reliable, official way to detect when GNOME Shell has finished creating and adding all panel indicators to the panel boxes?

Better to always check when something gets added to the panel. For example, for _centerBox you can use child-added (on 44 and older actor-added):

Main.panel._centerBox.connect('child-added', () => {
    // new widget added to the center box
});
1 Like