From 3bc8c0d2e117c1ed010f521d2c3431fe5892ea29 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Mon, 21 Oct 2024 14:35:49 +0545 Subject: [PATCH] feature: remove delay when clearing all notifications (#342) * feat: add setting option to control delay * Update widget/settings/pages/config/notifications/index.ts * Update widget/settings/pages/config/notifications/index.ts * Update widget/settings/pages/config/notifications/index.ts --------- Co-authored-by: Jas Singh --- globals/notification.ts | 4 ++-- modules/menus/notifications/controls/index.ts | 17 +++++++++++------ options.ts | 1 + .../pages/config/notifications/index.ts | 9 +++++++++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/globals/notification.ts b/globals/notification.ts index 1564029..f382bc4 100644 --- a/globals/notification.ts +++ b/globals/notification.ts @@ -25,11 +25,11 @@ export const getNotificationIcon = (app_name: string, app_icon: string, app_entr return icon; }; -export const closeNotifications = async (notifications: Notification[]): Promise => { +export const closeNotifications = async (notifications: Notification[], delay: number): Promise => { removingNotifications.value = true; for (const notif of notifications) { notif.close(); - await new Promise((resolve) => setTimeout(resolve, 100)); + await new Promise((resolve) => setTimeout(resolve, delay)); } removingNotifications.value = false; }; diff --git a/modules/menus/notifications/controls/index.ts b/modules/menus/notifications/controls/index.ts index 467bf00..a2964fd 100644 --- a/modules/menus/notifications/controls/index.ts +++ b/modules/menus/notifications/controls/index.ts @@ -1,6 +1,9 @@ import { closeNotifications } from 'globals/notification'; import { BoxWidget } from 'lib/types/widget'; import { Notifications } from 'types/service/notifications'; +import options from 'options'; + +const { clearDelay } = options.notifications; const Controls = (notifs: Notifications): BoxWidget => { return Widget.Box({ @@ -44,13 +47,15 @@ const Controls = (notifs: Notifications): BoxWidget => { Widget.Button({ className: 'clear-notifications-button', tooltip_text: 'Clear Notifications', - on_primary_click: () => { - if (removingNotifications.value) { - return; - } + on_primary_click: clearDelay.bind('value').as((delay) => { + return () => { + if (removingNotifications.value) { + return; + } - closeNotifications(notifs.notifications); - }, + return closeNotifications(notifs.notifications, delay); + }; + }), child: Widget.Label({ class_name: removingNotifications.bind('value').as((removing: boolean) => { return removing diff --git a/options.ts b/options.ts index 33142b6..8902241 100644 --- a/options.ts +++ b/options.ts @@ -1183,6 +1183,7 @@ const options = mkOptions(OPTIONS, { active_monitor: opt(true), timeout: opt(7000), cache_actions: opt(true), + clearDelay: opt(100), }, dummy: opt(true), diff --git a/widget/settings/pages/config/notifications/index.ts b/widget/settings/pages/config/notifications/index.ts index 3d7925e..4191d4f 100644 --- a/widget/settings/pages/config/notifications/index.ts +++ b/widget/settings/pages/config/notifications/index.ts @@ -45,6 +45,15 @@ export const NotificationSettings = (): Scrollable => { subtitle: 'The notification will follow the monitor of your cursor', type: 'boolean', }), + Option({ + opt: options.notifications.clearDelay, + title: 'Clear Delay', + subtitle: + 'The delay in milliseconds before a notification is cleared' + + '\nWARNING: Setting this value too low may crash AGS depending on your system.', + type: 'number', + increment: 20, + }), Option({ opt: options.notifications.timeout, title: 'Notification Timeout',