[QUESTION] EventsSection Gnome 3.38

Hey guys!

Im newbie here at the forum, but I was thinking on building some gnome extensions…
Right now, all I want to do is get the events from the calendar of the topbar section (AKA dateMenu.EventsSection);

but everytime I enable my extension, EventsSection returns:
[0x5646e42f9490 StLabel.event-placeholder:first-child last-child (“No events”)]

Can anybody help me?
My code is:

const gsMain = imports.ui.main;


const Events = class Events {
    constructor() {
        this._dateMenu = null
        this._eventsSection = null
    }

    enable() {
        this._dateMenu = gsMain.panel.statusArea.dateMenu;
        this._eventsSection = this._dateMenu._eventsItem;
    }

    reloadEvents() {
        log("[RELOADEVENTS] started");

        [...this._eventsSection._eventsList].forEach((message) => {
            log(`[RELOADEVENTS] ${message}`)
            // message.destroy();
        });
      }
}

Thanks!

Maybe try calling EventsSection._reload() before trying to enumerate the events? If you actually have events in your calendar, I would guess that when your extension in loaded the EventSource simple hasn’t settled yet.

That being said, I think you’d probably be better off using the event source directly to query for events, unless you plan on modifying those widgets in some way.

Hey, thank you so much for the reply :stuck_out_tongue:
Good Idea,

But I tried the
EventsSection._reload()

And other things, every time I get an empty result;

Do you have any idea What I did wrong?

const gsMain = imports.ui.main;
const Calendar = imports.ui.calendar;

const Events = class Events {
    constructor() {
        this._dateMenu = null
        this._eventsSection = null
    }

    enable() {
        this._dateMenu = gsMain.panel.statusArea.dateMenu;
        this._eventsSection = this._dateMenu._eventsItem;
        this._calendarSource = new Calendar.DBusEventSource();
    }

    reloadEvents() {
        log(`[RELOADEVENTS 11] started and is ${this._calendarSource.isLoading}`);
        let events = []
        this._calendarSource._loadEvents(true);
        events =
        this._calendarSource.getEvents(new Date('2020-03-03'), new Date('2020-03-05'));
        if(events === undefined) events = []

        log(`RELOADEVENTS 11=SIZE:${events.length}`)

        // for (let event of events) {
        //     log(`RELOADEVENTS 11=${event}`)
        // }
    
        // this._eventsSection._reloadEvents();
        events =
        this._calendarSource.getEvents(new Date('2020-03-04'), new Date('2020-03-05'));
        log(`RELOADEVENTS 11=SIZE:${events.length}`)
        if(events === undefined) events = []
        for (let event of events) {
            log(`RELOADEVENTS 11=${event}`)
        }

        // WITH CALENDARSOURCE I GET EMPTY TOO
        this._eventsSection._eventSource.connect('changed', () => {
            log(`RELOADEVENTS 12 CALENDAR CHANGED`)
            this._eventsSection._eventSource.requestRange(new Date('2020-03-04'), new Date('2020-03-05'));
            events = this._eventsSection._eventSource.getEvents(new Date('2020-03-04'), new Date('2020-03-05'));
            if(events === undefined) events = []

            log(`RELOADEVENTS 11=SIZE:${events.length}`)

            for (let event of events) {
                log(`RELOADEVENTS 11=${event}`)
            }   
        });
        // events =
        // this._calendarSource.requestRange(new Date('2020-03-04'), new Date('2020-03-05'));
        // if(events === undefined) events = []

        // log(`RELOADEVENTS 11=SIZE:${events.length}`)

        // for (let event of events) {
        //     log(`RELOADEVENTS 11=${event}`)
        // }
    
        // [...this._eventsSection._eventsList].forEach((message) => {
        //     log(`[RELOADEVENTS 11] ${message}`)
        //     // message.destroy();
        // });
        // log("[RELOADEVENTS 11] ended");
      }
}

I tried connecting to wait for the “emits” on the calendarSource too. But same result.

mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 11=SIZE:0
mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 11=SIZE:0
mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 12 CALENDAR CHANGED
mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 11=SIZE:0
mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 11=SIZE:0
mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 12 CALENDAR CHANGED
mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 11=SIZE:0
mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 11=SIZE:0
mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 12 CALENDAR CHANGED
mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 11=SIZE:0
mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 11=SIZE:0
mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 12 CALENDAR CHANGED
mar 05 07:47:41 pop-os gnome-shell[4329]: RELOADEVENTS 11=SIZE:0

Can you confirm that when you open the calendar menu you actually have events there?

@andyholmes

Yep, I do have the events there:

image

Did you mean to write 2021 instead of 2020? :smiley_cat:

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