Update notification dismissal system a bit

This commit is contained in:
JeremyStar™ 2024-10-15 04:05:37 +02:00
parent 8a52e991fd
commit cdde093b31
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
3 changed files with 37 additions and 3 deletions

View file

@ -105,8 +105,9 @@ public final class NotificationManager {
* Does nothing if it is already dismissed. * Does nothing if it is already dismissed.
* <p> * <p>
* Note: Dismissing a notification does not * Note: Dismissing a notification does not
* necessarily mean it removes it. Depending * necessarily mean removing it. Check
* on the {@link Notification#} * {@link Notification#getDismissalAction()}
* first or you might get a surprise.
* *
* @param notification notification to update * @param notification notification to update
* @since v1-alpha6 * @since v1-alpha6
@ -119,13 +120,37 @@ public final class NotificationManager {
case UNREGISTER -> updateNotification(notification, notifications.get(notification), true); case UNREGISTER -> updateNotification(notification, notifications.get(notification), true);
case EXECUTE -> notification.dismiss(); case EXECUTE -> notification.dismiss();
case EXECUTE_UNREGISTER -> { case EXECUTE_UNREGISTER -> {
updateNotification(notification, NotificationState.DISMISSED_ACTIVE, false);
notification.dismiss(); notification.dismiss();
updateNotification(notification, notifications.get(notification), true); updateNotification(notification, NotificationState.DISMISSED, true);
} }
} }
} }
} }
/**
* Frees the specified notification,
* or all if {@code notifications} is empty.
* <p>
* Only works for dismissed notifications
* which require manual freeing. See
* {@link #dismiss(Notification)} for more information.
*
* @param notifications notifications to free, or all if empty
* @since v1-alpha6
*/
public static void freeDismissed(@NotNull Notification @NotNull... notifications) {
if (notifications.length == 0)
notifications = NotificationManager.getNotifications().keySet().toArray(new Notification[0]);
for (Notification notification : notifications)
if (
NotificationManager.getNotifications().containsKey(notification)
&& NotificationManager.getNotifications().get(notification) == NotificationState.DISMISSED
)
updateNotification(notification, NotificationState.DISMISSED, true);
}
/** /**
* Adds or updates the specified notification * Adds or updates the specified notification
* in the {@link #notifications} map. * in the {@link #notifications} map.

View file

@ -237,6 +237,7 @@ public class Notification {
* @return linked button map * @return linked button map
* @since v1-alpha6 * @since v1-alpha6
*/ */
@Setter(value = AccessLevel.NONE)
private @NotNull LinkedHashMap<@NotNull String, @NotNull Runnable> buttons = new LinkedHashMap<>(); private @NotNull LinkedHashMap<@NotNull String, @NotNull Runnable> buttons = new LinkedHashMap<>();
/** /**

View file

@ -39,6 +39,14 @@ public enum NotificationState {
*/ */
HIDDEN, HIDDEN,
/**
* A dismissed notification which
* is still executing code.
*
* @since v1-alpha6
*/
DISMISSED_ACTIVE,
/** /**
* A dismissed notification. * A dismissed notification.
* *