Skip to content

Commit

Permalink
cinnamon-calendar-server.py: Refresh remote calendars when the
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mtwebster committed Jan 20, 2025
1 parent 5ea1203 commit d52e9c0
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions calendar-server/cinnamon-calendar-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,45 @@ 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

self.view = None
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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d52e9c0

Please sign in to comment.