Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add clipboard countdown bar component (#881)

Leendert de Borst4498833b4efb
diff --git a/apps/server/AliasVault.Client/Main/Components/ClipboardCountdownBar.razor b/apps/server/AliasVault.Client/Main/Components/ClipboardCountdownBar.razor
new file mode 100644
index 000000000..4684dc2f6
--- /dev/null
+++ b/apps/server/AliasVault.Client/Main/Components/ClipboardCountdownBar.razor
@@ -0,0 +1,34 @@
+@inject ClipboardCopyService ClipboardCopyService
+@implements IDisposable
+
+@if (IsVisible)
+{
+ <div class="fixed top-0 left-0 right-0 z-50 h-1 bg-gray-200 dark:bg-gray-700">
+ <div class="h-full bg-orange-500 dark:bg-orange-400 transition-all duration-100 ease-linear"
+ style="width: @(Progress * 100)%"></div>
+ </div>
+}
+
+@code {
+ private bool IsVisible { get; set; }
+ private double Progress { get; set; }
+
+ /// <inheritdoc />
+ protected override void OnInitialized()
+ {
+ ClipboardCopyService.OnTimerProgress += HandleTimerProgress;
+ }
+
+ private void HandleTimerProgress(double progress)
+ {
+ Progress = progress;
+ IsVisible = progress > 0;
+ InvokeAsync(StateHasChanged);
+ }
+
+ /// <inheritdoc />
+ public void Dispose()
+ {
+ ClipboardCopyService.OnTimerProgress -= HandleTimerProgress;
+ }
+}
diff --git a/apps/server/AliasVault.Client/Main/Layout/MainLayout.razor b/apps/server/AliasVault.Client/Main/Layout/MainLayout.razor
index 2ecdafdec..007f93bdd 100644
--- a/apps/server/AliasVault.Client/Main/Layout/MainLayout.razor
+++ b/apps/server/AliasVault.Client/Main/Layout/MainLayout.razor
@@ -7,6 +7,7 @@
<Authorized>
<ConfirmModal />
<FullScreenLoadingIndicator @ref="LoadingIndicator" />
+ <ClipboardCountdownBar />
<TopMenu />
<div class="flex pt-16 mb-4 lg:mb-16 overflow-hidden bg-gray-100 dark:bg-gray-900 relative">
<div id="main-content" class="relative w-full max-w-screen-2xl mx-auto h-full overflow-y-auto bg-gray-100 dark:bg-gray-900">
diff --git a/apps/server/AliasVault.Client/Services/ClipboardCopyService.cs b/apps/server/AliasVault.Client/Services/ClipboardCopyService.cs
index f0da10eb0..9c07f10cd 100644
--- a/apps/server/AliasVault.Client/Services/ClipboardCopyService.cs
+++ b/apps/server/AliasVault.Client/Services/ClipboardCopyService.cs
@@ -7,12 +7,18 @@
namespace AliasVault.Client.Services;
+using System.Timers;
+using Timer = System.Timers.Timer;
+
/// <summary>
-/// Service to manage the clipboard copy operations across the application.
+/// Service to manage the clipboard copy UI state across the application.
/// </summary>
-public sealed class ClipboardCopyService
+public sealed class ClipboardCopyService : IDisposable
{
private string _currentCopiedId = string.Empty;
+ private Timer? _progressTimer;
+ private DateTime _clearTime;
+ private int _clearDurationSeconds = 5;
/// <summary>
/// Event to notify the application that an item has been copied.
@@ -20,13 +26,41 @@ public sealed class ClipboardCopyService
public event Action<string>? OnCopy;
/// <summary>
- /// Keep track of the last copied item.
+ /// Event to notify the application about timer progress for UI updates.
+ /// </summary>
+ public event Action<double>? OnTimerProgress;
+
+ /// <summary>
+ /// Gets or sets the duration in seconds before clipboard is cleared.
+ /// </summary>
+ public int ClearDurationSeconds
+ {
+ get => _clearDurationSeconds;
+ set => _clearDurationSeconds = value > 0 ? value : 5;
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether there is an active progress timer.
+ /// </summary>
+ public bool IsTimerActive => _progressTimer?.Enabled ?? false;
+
+ /// <summary>
+ /// Keep track of the last copied item and start progress timer for UI.
/// </summary>
/// <param name="id">Id of the last copied item.</param>
public void SetCopied(string id)
{
_currentCopiedId = id;
OnCopy?.Invoke(_currentCopiedId);
+
+ if (!string.IsNullOrEmpty(id))
+ {
+ StartProgressTimer();
+ }
+ else
+ {
+ StopProgressTimer();
+ }
}
/// <summary>
@@ -34,4 +68,68 @@ public sealed class ClipboardCopyService
/// </summary>
/// <returns>Id of last copied item.</returns>
public string GetCopiedId() => _currentCopiedId;
+
+ /// <summary>
+ /// Gets the remaining time in seconds for UI display.
+ /// </summary>
+ /// <returns>The remaining seconds until clipboard is cleared.</returns>
+ public double GetRemainingSeconds()
+ {
+ if (!IsTimerActive)
+ {
+ return 0;
+ }
+
+ var remaining = (_clearTime - DateTime.UtcNow).TotalSeconds;
+ return Math.Max(0, remaining);
+ }
+
+ /// <inheritdoc />
+ public void Dispose()
+ {
+ StopProgressTimer();
+ }
+
+ private void StartProgressTimer()
+ {
+ StopProgressTimer();
+
+ _clearTime = DateTime.UtcNow.AddSeconds(_clearDurationSeconds);
+
+ // Progress timer for UI updates only (every 100ms)
+ _progressTimer = new Timer(100);
+ _progressTimer.Elapsed += UpdateProgress;
+ _progressTimer.AutoReset = true;
+ _progressTimer.Start();
+
+ // Initial progress update
+ UpdateProgress(null, null);
+ }
+
+ private void StopProgressTimer()
+ {
+ _progressTimer?.Stop();
+ _progressTimer?.Dispose();
+ _progressTimer = null;
+
+ OnTimerProgress?.Invoke(0);
+ }
+
+ private void UpdateProgress(object? sender, ElapsedEventArgs? e)
+ {
+ var remaining = GetRemainingSeconds();
+ var progress = remaining / _clearDurationSeconds;
+
+ if (progress <= 0)
+ {
+ // Timer finished, reset UI state
+ StopProgressTimer();
+ _currentCopiedId = string.Empty;
+ OnCopy?.Invoke(_currentCopiedId);
+ }
+ else
+ {
+ OnTimerProgress?.Invoke(progress);
+ }
+ }
}
diff --git a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
index a64616dd8..fded904cd 100644
--- a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
+++ b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
@@ -674,6 +674,10 @@ video {
top: 40px;
}
+.top-0 {
+ top: 0px;
+}
+
.-z-10 {
z-index: -10;
}
@@ -962,6 +966,10 @@ video {
height: 1px;
}
+.h-1 {
+ height: 0.25rem;
+}
+
.max-h-32 {
max-height: 8rem;
}
@@ -1717,6 +1725,11 @@ video {
background-color: rgb(234 179 8 / var(--tw-bg-opacity));
}
+.bg-orange-500 {
+ --tw-bg-opacity: 1;
+ background-color: rgb(249 115 22 / var(--tw-bg-opacity));
+}
+
.bg-opacity-50 {
--tw-bg-opacity: 0.5;
}
@@ -2289,10 +2302,18 @@ video {
transition-duration: 300ms;
}
+.duration-100 {
+ transition-duration: 100ms;
+}
+
.ease-in-out {
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}
+.ease-linear {
+ transition-timing-function: linear;
+}
+
.file\:mr-4::file-selector-button {
margin-right: 1rem;
}
@@ -2851,6 +2872,16 @@ video {
background-color: rgb(133 77 14 / var(--tw-bg-opacity));
}
+.dark\:bg-blue-400:is(.dark *) {
+ --tw-bg-opacity: 1;
+ background-color: rgb(96 165 250 / var(--tw-bg-opacity));
+}
+
+.dark\:bg-orange-400:is(.dark *) {
+ --tw-bg-opacity: 1;
+ background-color: rgb(251 146 60 / var(--tw-bg-opacity));
+}
+
.dark\:bg-opacity-80:is(.dark *) {
--tw-bg-opacity: 0.8;
}