From d52e9c02cbab23507d4cb63ce7c5ffe064bc2fd8 Mon Sep 17 00:00:00 2001 From: Michael Webster Date: Mon, 20 Jan 2025 12:28:50 -0500 Subject: [PATCH] cinnamon-calendar-server.py: Refresh remote calendars when the event list is opened. The applet relies on evolution-data-server being aware of changes and keeping up-to-date. Unfortunately, online accounts aren't polled often unless a real client is launched (like gnome-calendar). Enable client refreshing in the cinnamon-calendar-server process and trigger it when the applet is opened. This should refresh the applet event view with any recent updates, even from remote sources. Fixes #12652. --- calendar-server/cinnamon-calendar-server.py | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/calendar-server/cinnamon-calendar-server.py b/calendar-server/cinnamon-calendar-server.py index 1aa8cac794..9145f6e207 100755 --- a/calendar-server/cinnamon-calendar-server.py +++ b/calendar-server/cinnamon-calendar-server.py @@ -36,10 +36,20 @@ def __init__(self, source, client): self.source = source self.client = client + self.syncing = False + self.extension = source.get_extension(EDataServer.SOURCE_EXTENSION_CALENDAR) self.color = self.extension.get_color() self.color_prop_listener_id = self.extension.connect("notify::color", self.ext_color_prop_changed) + # This process generally won't stay running for more than 30 seconds or so, + # but enabling refresh lets us force a timeout and re-poll. + if self.client.check_capability(ECal.STATIC_CAPABILITY_REFRESH_SUPPORTED): + self.refresh = self.source.get_extension(EDataServer.SOURCE_EXTENSION_REFRESH) + self.refresh.set_enabled(True) + self.refresh.set_interval_minutes(1) + self.source.refresh_add_timeout(None, self.on_refresh_timeout) + self.start = None self.end = None @@ -47,6 +57,24 @@ def __init__(self, source, client): self.view_cancellable = None self.events = [] + def try_sync(self): + if self.syncing: + return + + if self.client.check_capability(ECal.STATIC_CAPABILITY_REFRESH_SUPPORTED): + self.source.refresh_force_timeout() + + def on_refresh_timeout(self, source, data=None): + self.client.refresh(None, self.on_sync_complete) + + def on_sync_complete(self, client, result, data=None): + try: + self.client.refresh_finish(result) + except GLib.Error as e: + print(f"Error refreshing calendar '{self.source.get_display_name()}':", e.message) + + self.syncing = False + def destroy(self): self.extension.disconnect(self.color_prop_listener_id) self.extension = None @@ -223,6 +251,9 @@ def handle_set_time_range(self, iface, inv, time_since, time_until, force_reload self.interface.complete_set_time_range(inv) return True + for calendar in self.calendars.values(): + calendar.try_sync() + self.current_month_start = time_since self.current_month_end = time_until