summaryrefslogtreecommitdiff
path: root/src/services/news.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/news.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/news.ts')
-rw-r--r--src/services/news.ts19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/services/news.ts b/src/services/news.ts
index 3d56186..8db280a 100644
--- a/src/services/news.ts
+++ b/src/services/news.ts
@@ -106,6 +106,13 @@ export default class News extends GObject.Object {
}
this.notify("articles");
+ this.updateCategories();
+
+ this.#loading = false;
+ this.notify("loading");
+ }
+
+ updateCategories() {
this.#categories = {};
for (const article of this.#articles) {
for (const category of article.category) {
@@ -114,14 +121,20 @@ export default class News extends GObject.Object {
}
}
this.notify("categories");
-
- this.#loading = false;
- this.notify("loading");
}
constructor() {
super();
+ if (GLib.file_test(this.#cachePath, GLib.FileTest.EXISTS))
+ readFileAsync(this.#cachePath)
+ .then(data => {
+ this.#articles = JSON.parse(data);
+ this.notify("articles");
+ this.updateCategories();
+ })
+ .catch(console.error);
+
this.getNews().catch(console.error);
config.apiKey.subscribe(() => this.getNews().catch(console.error));
config.countries.subscribe(() => this.getNews().catch(console.error));