using System; using MaterialDesignThemes.Wpf; namespace NebulaAuth.Core; public class SnackbarController { private const int MIN_SNACKBAR_TIME = 1200; public static SnackbarMessageQueue MessageQueue { get; } = new() {DiscardDuplicates = true}; /// /// /// /// Default duration is 1 second public static void SendSnackbar(string text, TimeSpan? duration = null) { duration ??= GetSnackbarTime(text); MessageQueue.Enqueue(text, null, null, null, false, false, duration.Value); } /// /// /// /// /// Default duration is 1 second /// Default: 'OK' public static void SendSnackbarWithButton(string text, string actionText = "OK", Action? action = null, TimeSpan? duration = null) { duration ??= GetSnackbarTime(text); Action argAction; if (action == null) { argAction = _ => { }; } else { argAction = _ => action(); } MessageQueue.Enqueue(text, actionText, argAction, null, false, false, duration); } private static TimeSpan GetSnackbarTime(string str) { var duration = str.Length / 0.022; if (duration < MIN_SNACKBAR_TIME) { duration = MIN_SNACKBAR_TIME; } return TimeSpan.FromMilliseconds(duration); } }