From 708b4bed32e9c71c0baf45792ad393840f19d9be Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:37:32 +1100 Subject: weather: notify when no api key --- src/services/weather.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/services/weather.ts b/src/services/weather.ts index 0de8ca5..e57e7c4 100644 --- a/src/services/weather.ts +++ b/src/services/weather.ts @@ -1,5 +1,6 @@ import { execAsync, GLib, GObject, interval, property, readFileAsync, register, writeFileAsync } from "astal"; import { weather as config } from "../../config"; +import { notify } from "../utils/system"; export interface WeatherCondition { text: string; @@ -399,12 +400,23 @@ export default class Weather extends GObject.Object { constructor() { super(); - readFileAsync(config.key) - .then(k => { - this.#key = k; - this.updateWeather().catch(console.error); - interval(config.interval, () => this.updateWeather().catch(console.error)); - }) - .catch(console.error); + if (GLib.file_test(config.key, GLib.FileTest.EXISTS)) + readFileAsync(config.key) + .then(k => { + this.#key = k.trim(); + this.updateWeather().catch(console.error); + interval(config.interval, () => this.updateWeather().catch(console.error)); + }) + .catch(console.error); + else + notify({ + summary: "Weather API key required", + body: `A weather API key is required to get weather data. Get one from https://www.weatherapi.com and put it in ${config.key}.`, + icon: "dialog-warning-symbolic", + urgency: "critical", + actions: { + "Get API key": () => execAsync(["xdg-open", "https://www.weatherapi.com"]).catch(print), + }, + }); } } -- cgit v1.2.3-freya