Add support for default notification time (icon without specified time)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { NotificationDatabase } from "../types/notification";
|
import { Notification, NotificationDatabase } from "../types/notification";
|
||||||
import { Config } from "../types/config";
|
import { Config } from "../types/config";
|
||||||
import { NtfySH } from "./ntfy";
|
import { NtfySH } from "./ntfy";
|
||||||
import { Debug } from "./debug";
|
import { Debug } from "./debug";
|
||||||
@@ -14,9 +14,20 @@ const backends = [
|
|||||||
* and triggers the notification using specified backends in the config.
|
* and triggers the notification using specified backends in the config.
|
||||||
*/
|
*/
|
||||||
export async function remind(config: Config, db: NotificationDatabase) {
|
export async function remind(config: Config, db: NotificationDatabase) {
|
||||||
const now = dayjs().format("HH:mm");
|
const now = dayjs().format("HH:mm");
|
||||||
const notifications = db[now] ?? [];
|
|
||||||
|
|
||||||
|
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) {
|
for (const notification of notifications) {
|
||||||
console.info(`Dispatching a notification: [${notification.text}]`)
|
console.info(`Dispatching a notification: [${notification.text}]`)
|
||||||
for (const backend of backends) {
|
for (const backend of backends) {
|
||||||
|
|||||||
@@ -119,7 +119,13 @@ export class LazyTask implements Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get reminder(): string|undefined {
|
get reminder(): string|undefined {
|
||||||
return this.#parsed.meta.find(x => x.feature === 'reminder')?.time;
|
const feature = this.#parsed.meta.find(x => x.feature === 'reminder');
|
||||||
|
|
||||||
|
if (feature) {
|
||||||
|
return feature.time || "default";
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export type Config = {
|
|||||||
sources: string[];
|
sources: string[];
|
||||||
query?: string;
|
query?: string;
|
||||||
mapper?: string;
|
mapper?: string;
|
||||||
|
defaultTime?: string;
|
||||||
databaseFile: string;
|
databaseFile: string;
|
||||||
backend: Record<string, unknown>;
|
backend: Record<string, unknown>;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user