summaryrefslogtreecommitdiff
path: root/src/services/calendar.ts
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-09 15:27:05 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-09 15:27:05 +1000
commit1cc7e12a57e207517334f3526757382dd7978b9d (patch)
tree448b5a9ac782207ed121a580904f4d9ef91a2516 /src/services/calendar.ts
parentfeat: news headlines for alerts pane (diff)
downloadcaelestia-shell-1cc7e12a57e207517334f3526757382dd7978b9d.tar.gz
caelestia-shell-1cc7e12a57e207517334f3526757382dd7978b9d.tar.bz2
caelestia-shell-1cc7e12a57e207517334f3526757382dd7978b9d.zip
feat: load news and calendars from cache on startup
Also check calendars for cache before trying to load
Diffstat (limited to 'src/services/calendar.ts')
-rw-r--r--src/services/calendar.ts20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/services/calendar.ts b/src/services/calendar.ts
index a2cdd30..d5e0329 100644
--- a/src/services/calendar.ts
+++ b/src/services/calendar.ts
@@ -134,7 +134,8 @@ export default class Calendar extends GObject.Object {
icalStr = cal.value;
} else {
console.error(`Failed to get calendar from ${config.webcals.get()[i]}:\n${cal.reason}`);
- icalStr = await readFileAsync(`${this.#cacheDir}/${webcal}`);
+ if (GLib.file_test(`${this.#cacheDir}/${webcal}`, GLib.FileTest.EXISTS))
+ icalStr = await readFileAsync(`${this.#cacheDir}/${webcal}`);
}
if (icalStr) {
@@ -202,6 +203,23 @@ export default class Calendar extends GObject.Object {
GLib.mkdir_with_parents(this.#cacheDir, 0o755);
+ const cals = config.webcals.get().map(async c => {
+ const webcal = pathToFileName(c);
+
+ if (GLib.file_test(`${this.#cacheDir}/${webcal}`, GLib.FileTest.EXISTS)) {
+ const data = await readFileAsync(`${this.#cacheDir}/${webcal}`);
+ const comp = new ical.Component(ical.parse(data));
+ const name = (comp.getFirstPropertyValue("x-wr-calname") ?? `Calendar ${this.#calCount++}`) as string;
+ this.#calendars[name] = comp;
+ }
+ });
+ Promise.allSettled(cals).then(() => {
+ this.#cachedEvents = {};
+ this.#cachedMonths.clear();
+ this.notify("calendars");
+ this.updateUpcoming();
+ });
+
this.updateCalendars().catch(console.error);
config.webcals.subscribe(() => this.updateCalendars().catch(console.error));
config.upcomingDays.subscribe(() => this.updateUpcoming());