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:
@@ -25,11 +25,11 @@ export const getNotificationIcon = (app_name: string, app_icon: string, app_entr
|
||||
return icon;
|
||||
};
|
||||
|
||||
export const closeNotifications = async (notifications: Notification[]): Promise<void> => {
|
||||
export const closeNotifications = async (notifications: Notification[], delay: number): Promise<void> => {
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -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: () => {
|
||||
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
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -45,6 +45,15 @@ export const NotificationSettings = (): Scrollable<Child, Attribute> => {
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user