Files
Nebula-Auth/NebulaAuth/Core/SnackbarController.cs
T
achiez 8ff960189e 1.5.6 Bug fixes and code clean-ups
- Update: Added "Copy Password" to Mafile context menu (if available)
- Update: "Save Password" now pre-fills the current password in the "Login Again" dialog when encryption is enabled
- Fix: Prevented overlapping confirmation cycles in AutoConfirmer
- Fix: Added a Snackbar notification when a confirmation cycle is skipped due to a too frequent timer interval
- Fix: Fixed a rare bug where the previous proxy was used instead of the current one during session refresh
- Fix: Corrected "Session Permanently Expired" message showing on unrelated errors (e.g. network issues)
- UI-Fix: Fixed visual glitch where proxy input appeared non-empty when switching to a mafile-specific proxy
- Cleanup: Refactored and cleaned up codebase, improved styling and formatting via ReSharper
2025-05-02 23:29:24 +03:00

55 lines
1.6 KiB
C#

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};
/// <summary>
/// </summary>
/// <param name="text"></param>
/// <param name="duration">Default duration is 1 second</param>
public static void SendSnackbar(string text, TimeSpan? duration = null)
{
duration ??= GetSnackbarTime(text);
MessageQueue.Enqueue(text, null, null, null, false, false, duration.Value);
}
/// <summary>
/// </summary>
/// <param name="text"></param>
/// <param name="action"></param>
/// <param name="duration">Default duration is 1 second</param>
/// <param name="actionText">Default: 'OK'</param>
public static void SendSnackbarWithButton(string text, string actionText = "OK", Action? action = null,
TimeSpan? duration = null)
{
duration ??= GetSnackbarTime(text);
Action<object?> 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.03;
if (duration < MIN_SNACKBAR_TIME)
{
duration = MIN_SNACKBAR_TIME;
}
return TimeSpan.FromMilliseconds(duration);
}
}