weather: notify when no api key
This commit is contained in:
parent
fee7bf492e
commit
708b4bed32
1 changed files with 19 additions and 7 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { execAsync, GLib, GObject, interval, property, readFileAsync, register, writeFileAsync } from "astal";
|
import { execAsync, GLib, GObject, interval, property, readFileAsync, register, writeFileAsync } from "astal";
|
||||||
import { weather as config } from "../../config";
|
import { weather as config } from "../../config";
|
||||||
|
import { notify } from "../utils/system";
|
||||||
|
|
||||||
export interface WeatherCondition {
|
export interface WeatherCondition {
|
||||||
text: string;
|
text: string;
|
||||||
|
|
@ -399,12 +400,23 @@ export default class Weather extends GObject.Object {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
if (GLib.file_test(config.key, GLib.FileTest.EXISTS))
|
||||||
readFileAsync(config.key)
|
readFileAsync(config.key)
|
||||||
.then(k => {
|
.then(k => {
|
||||||
this.#key = k;
|
this.#key = k.trim();
|
||||||
this.updateWeather().catch(console.error);
|
this.updateWeather().catch(console.error);
|
||||||
interval(config.interval, () => this.updateWeather().catch(console.error));
|
interval(config.interval, () => this.updateWeather().catch(console.error));
|
||||||
})
|
})
|
||||||
.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),
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue