From ec3be1cad8425b6d27005f60c54ac950e1ba25cf Mon Sep 17 00:00:00 2001 From: Jas Singh Date: Tue, 5 Nov 2024 21:11:50 -0800 Subject: [PATCH] Provide a cli command to clear notifications. (#444) --- globals.d.ts | 2 ++ globals/notification.ts | 11 ++++++++++- modules/menus/notifications/controls/index.ts | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/globals.d.ts b/globals.d.ts index 62636c6..d33c59c 100644 --- a/globals.d.ts +++ b/globals.d.ts @@ -7,6 +7,8 @@ declare global { var useTheme: (filePath: string) => void; var getSystrayItems: () => string; var isWindowVisible: (windowName: string) => boolean; + var clearAllNotifications: () => Promise; + var globalWeatherVar: VariableType; var options: Options; var removingNotifications: VariableType; diff --git a/globals/notification.ts b/globals/notification.ts index f382bc4..9019f5f 100644 --- a/globals/notification.ts +++ b/globals/notification.ts @@ -1,6 +1,10 @@ +const notifs = await Service.import('notifications'); import icons from 'modules/icons/index'; +import options from 'options'; import { Notification } from 'types/service/notifications'; +const { clearDelay } = options.notifications; + export const removingNotifications = Variable(false); export const getNotificationIcon = (app_name: string, app_icon: string, app_entry: string): string => { @@ -25,7 +29,7 @@ export const getNotificationIcon = (app_name: string, app_icon: string, app_entr return icon; }; -export const closeNotifications = async (notifications: Notification[], delay: number): Promise => { +export const clearNotifications = async (notifications: Notification[], delay: number): Promise => { removingNotifications.value = true; for (const notif of notifications) { notif.close(); @@ -34,4 +38,9 @@ export const closeNotifications = async (notifications: Notification[], delay: n removingNotifications.value = false; }; +const clearAllNotifications = async (): Promise => { + clearNotifications(notifs.notifications, clearDelay.value); +}; + globalThis['removingNotifications'] = removingNotifications; +globalThis['clearAllNotifications'] = clearAllNotifications; diff --git a/modules/menus/notifications/controls/index.ts b/modules/menus/notifications/controls/index.ts index a2964fd..de4492d 100644 --- a/modules/menus/notifications/controls/index.ts +++ b/modules/menus/notifications/controls/index.ts @@ -1,4 +1,4 @@ -import { closeNotifications } from 'globals/notification'; +import { clearNotifications } from 'globals/notification'; import { BoxWidget } from 'lib/types/widget'; import { Notifications } from 'types/service/notifications'; import options from 'options'; @@ -53,7 +53,7 @@ const Controls = (notifs: Notifications): BoxWidget => { return; } - return closeNotifications(notifs.notifications, delay); + return clearNotifications(notifs.notifications, delay); }; }), child: Widget.Label({