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 <jaskiratpal.singh@outlook.com>
This commit is contained in:
Rubin Bhandari
2024-10-21 14:35:49 +05:45
committed by GitHub
parent 604f737182
commit 3bc8c0d2e1
4 changed files with 23 additions and 8 deletions

View File

@@ -25,11 +25,11 @@ export const getNotificationIcon = (app_name: string, app_icon: string, app_entr
return icon; return icon;
}; };
export const closeNotifications = async (notifications: Notification[]): Promise<void> => { export const closeNotifications = async (notifications: Notification[], delay: number): Promise<void> => {
removingNotifications.value = true; removingNotifications.value = true;
for (const notif of notifications) { for (const notif of notifications) {
notif.close(); notif.close();
await new Promise((resolve) => setTimeout(resolve, 100)); await new Promise((resolve) => setTimeout(resolve, delay));
} }
removingNotifications.value = false; removingNotifications.value = false;
}; };

View File

@@ -1,6 +1,9 @@
import { closeNotifications } from 'globals/notification'; import { closeNotifications } from 'globals/notification';
import { BoxWidget } from 'lib/types/widget'; import { BoxWidget } from 'lib/types/widget';
import { Notifications } from 'types/service/notifications'; import { Notifications } from 'types/service/notifications';
import options from 'options';
const { clearDelay } = options.notifications;
const Controls = (notifs: Notifications): BoxWidget => { const Controls = (notifs: Notifications): BoxWidget => {
return Widget.Box({ return Widget.Box({
@@ -44,13 +47,15 @@ const Controls = (notifs: Notifications): BoxWidget => {
Widget.Button({ Widget.Button({
className: 'clear-notifications-button', className: 'clear-notifications-button',
tooltip_text: 'Clear Notifications', tooltip_text: 'Clear Notifications',
on_primary_click: () => { on_primary_click: clearDelay.bind('value').as((delay) => {
if (removingNotifications.value) { return () => {
return; if (removingNotifications.value) {
} return;
}
closeNotifications(notifs.notifications); return closeNotifications(notifs.notifications, delay);
}, };
}),
child: Widget.Label({ child: Widget.Label({
class_name: removingNotifications.bind('value').as((removing: boolean) => { class_name: removingNotifications.bind('value').as((removing: boolean) => {
return removing return removing

View File

@@ -1183,6 +1183,7 @@ const options = mkOptions(OPTIONS, {
active_monitor: opt(true), active_monitor: opt(true),
timeout: opt(7000), timeout: opt(7000),
cache_actions: opt(true), cache_actions: opt(true),
clearDelay: opt(100),
}, },
dummy: opt(true), dummy: opt(true),

View File

@@ -45,6 +45,15 @@ export const NotificationSettings = (): Scrollable<Child, Attribute> => {
subtitle: 'The notification will follow the monitor of your cursor', subtitle: 'The notification will follow the monitor of your cursor',
type: 'boolean', 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({ Option({
opt: options.notifications.timeout, opt: options.notifications.timeout,
title: 'Notification Timeout', title: 'Notification Timeout',