Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: remove delay when clearing all notifications #342

Merged
merged 7 commits into from
Oct 21, 2024
4 changes: 2 additions & 2 deletions globals/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
17 changes: 11 additions & 6 deletions modules/menus/notifications/controls/index.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
9 changes: 9 additions & 0 deletions widget/settings/pages/config/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Jas-SinghFSU marked this conversation as resolved.
Show resolved Hide resolved
increment: 20,
}),
Option({
opt: options.notifications.timeout,
title: 'Notification Timeout',
Expand Down
Loading