Add support for default notification time (icon without specified time)

This commit is contained in:
2025-02-25 15:53:15 +01:00
parent 0b3fda4beb
commit 1fabb32fb6
3 changed files with 22 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
import dayjs from "dayjs";
import { NotificationDatabase } from "../types/notification";
import { Notification, NotificationDatabase } from "../types/notification";
import { Config } from "../types/config";
import { NtfySH } from "./ntfy";
import { Debug } from "./debug";
@@ -14,9 +14,20 @@ const backends = [
* and triggers the notification using specified backends in the config.
*/
export async function remind(config: Config, db: NotificationDatabase) {
const now = dayjs().format("HH:mm");
const notifications = db[now] ?? [];
const now = dayjs().format("HH:mm");
await run(config, db, db[now]);
if(config?.defaultTime && config?.defaultTime === now) {
run(config, db, db.default);
}
}
async function run(config: Config, db: NotificationDatabase, notifications?: Notification[]) {
if(!notifications) {
return;
}
for (const notification of notifications) {
console.info(`Dispatching a notification: [${notification.text}]`)
for (const backend of backends) {