[Newbie question] Login event

I’m working on extending an extension, and am finding the docs a bit impenetrable on this issue.

The extension I’m working on is a battery time indicator, but it doesn’t seem to display immediately after login. Instead, it requires a mouse-hover and then shows up. Would it be possible (or reasonable) to listen to a login event, or rework the indicator, so that it displays without requiring the mouse hover?

Could you show some code? It’s hard to give advice without knowing what you’ve tried.

There is a short example of an extension with a panel indicator on gjs.guide:

const St = imports.gi.St;
const Gio = imports.gi.Gio;

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;

class Extension {
    constructor() {
        this._indicator = null;
    enable() {
        log(`enabling ${Me.metadata.name}`);

        let indicatorName = `${Me.metadata.name} Indicator`;
        // Create a panel button
        this._indicator = new PanelMenu.Button(0.0, indicatorName, false);
        // Add an icon
        let icon = new St.Icon({
            gicon: new Gio.ThemedIcon({name: 'face-laugh-symbolic'}),
            style_class: 'system-status-icon'

        // `Main.panel` is the actual panel you see at the top of the screen,
        // not a class constructor.
        Main.panel.addToStatusArea(indicatorName, this._indicator);
    // REMINDER: It's required for extensions to clean up after themselves when
    // they are disabled. This is required for approval during review!
    disable() {
        log(`disabling ${Me.metadata.name}`);

        this._indicator = null;

function init() {
    log(`initializing ${Me.metadata.name}`);
    return new Extension();

Thanks very much, this pointed me in the right direction. By “a bit impenetrable” I meant that I didn’t even know where to start!

The extension I was working on was lacking an init() function in extension.js, so that couldn’t be called to be properly initialized. Adding this function fixed the issue.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.