Skip to content

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

Add manual clipboard clear button if automatic clipboard clear fails (#1301)

Leendert de Borst5a6d317e31ab
diff --git a/apps/server/AliasVault.Client/Main/Components/ClipboardCountdownBar.razor b/apps/server/AliasVault.Client/Main/Components/ClipboardCountdownBar.razor
index d6860680b..bef34600d 100644
--- a/apps/server/AliasVault.Client/Main/Components/ClipboardCountdownBar.razor
+++ b/apps/server/AliasVault.Client/Main/Components/ClipboardCountdownBar.razor
@@ -1,5 +1,7 @@
@inject ClipboardCopyService ClipboardCopyService
@inject JsInteropService JsInteropService
+@inject IStringLocalizerFactory LocalizerFactory
+@using Microsoft.Extensions.Localization
@implements IDisposable
@using Microsoft.JSInterop
@@ -9,9 +11,19 @@
<div class="h-full @GetBarColorClass() transition-all duration-100 ease-linear @GetAnimationClass()"
style="width: @(Progress * 100)%">
</div>
+
+ @if (CurrentStatus == "manual_clear_required")
+ {
+ <div class="fixed top-2 left-1/2 transform -translate-x-1/2 z-50 bg-blue-500 dark:bg-blue-600 text-white px-4 py-2 rounded-md shadow-lg flex items-center gap-3">
+ <button @onclick="HandleManualClear"
+ class="px-3 py-1 bg-white dark:bg-gray-800 text-blue-600 dark:text-blue-400 rounded text-sm font-medium hover:bg-gray-100 dark:hover:bg-gray-700">
+ @Localizer["ClearClipboardButton"]
+ </button>
+ </div>
+ }
</div>
- @if (CurrentStatus == "pending")
+ @if (CurrentStatus == "pending" || CurrentStatus == "manual_clear_required")
{
<style>
@@keyframes custom-pulse {
@@ -30,6 +42,58 @@
private double Progress { get; set; }
private string CurrentStatus { get; set; } = "active";
private DotNetObjectReference<ClipboardCountdownBar>? _objRef;
+ private IStringLocalizer Localizer => LocalizerFactory.Create("Components.Main.ClipboardCountdownBar", "AliasVault.Client");
+
+ /// <summary>
+ /// Called from JavaScript when clipboard status changes.
+ /// </summary>
+ [JSInvokable]
+ public async Task OnClipboardStatusChange(string status)
+ {
+ // Ignore the test 'registered' status
+ if (status == "registered")
+ {
+ return;
+ }
+
+ // Ensure UI updates happen on the UI thread
+ await InvokeAsync(() =>
+ {
+ CurrentStatus = status;
+
+ // Hide the bar when clipboard is cleared
+ if (status == "cleared")
+ {
+ IsVisible = false;
+ Progress = 0;
+ }
+ // Update pending state properly
+ else if (status == "pending")
+ {
+ IsVisible = true;
+ Progress = 1.0;
+ }
+ // Handle active state
+ else if (status == "active")
+ {
+ // Let timer handle active state, but ensure we're visible if we should be
+ }
+
+ StateHasChanged();
+ });
+ }
+
+ /// <inheritdoc />
+ public async void Dispose()
+ {
+ ClipboardCopyService.OnTimerProgress -= HandleTimerProgress;
+
+ if (_objRef != null)
+ {
+ await JsInteropService.UnregisterClipboardStatusCallback();
+ _objRef.Dispose();
+ }
+ }
/// <inheritdoc />
protected override async void OnInitialized()
@@ -66,42 +130,15 @@
}
/// <summary>
- /// Called from JavaScript when clipboard status changes.
+ /// Handles the manual clear of the clipboard.
/// </summary>
- [JSInvokable]
- public async Task OnClipboardStatusChange(string status)
+ private async Task HandleManualClear()
{
- // Ignore the test 'registered' status
- if (status == "registered")
- {
- return;
- }
-
- // Ensure UI updates happen on the UI thread
- await InvokeAsync(() =>
- {
- CurrentStatus = status;
-
- // Hide the bar when clipboard is cleared
- if (status == "cleared")
- {
- IsVisible = false;
- Progress = 0;
- }
- // Update pending state properly
- else if (status == "pending")
- {
- IsVisible = true;
- Progress = 1.0;
- }
- // Handle active state
- else if (status == "active")
- {
- // Let timer handle active state, but ensure we're visible if we should be
- }
-
- StateHasChanged();
- });
+ await JsInteropService.ClearClipboard();
+ CurrentStatus = "active";
+ IsVisible = true;
+ Progress = 0;
+ StateHasChanged();
}
private string GetBarColorClass()
@@ -109,6 +146,7 @@
return CurrentStatus switch
{
"pending" => "bg-blue-500 dark:bg-blue-400", // Blue when pending (waiting for focus)
+ "manual_clear_required" => "bg-blue-500 dark:bg-blue-400", // Blue when manual clear required
_ => "bg-orange-500 dark:bg-orange-400" // Orange when actively counting down or cleared
};
}
@@ -118,16 +156,4 @@
// Add pulse animation when pending to draw attention
return CurrentStatus == "pending" ? "custom-pulse-animation" : "";
}
-
- /// <inheritdoc />
- public async void Dispose()
- {
- ClipboardCopyService.OnTimerProgress -= HandleTimerProgress;
-
- if (_objRef != null)
- {
- await JsInteropService.UnregisterClipboardStatusCallback();
- _objRef.Dispose();
- }
- }
}
diff --git a/apps/server/AliasVault.Client/Resources/Components/Main/ClipboardCountdownBar.en.resx b/apps/server/AliasVault.Client/Resources/Components/Main/ClipboardCountdownBar.en.resx
new file mode 100644
index 000000000..2f4b1a7e4
--- /dev/null
+++ b/apps/server/AliasVault.Client/Resources/Components/Main/ClipboardCountdownBar.en.resx
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="xml:space" use="preserve" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="ClearClipboardButton" xml:space="preserve">
+ <value>Clear Clipboard</value>
+ <comment>Button text to manually clear clipboard immediately</comment>
+ </data>
+</root>
diff --git a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
index ea2386bbf..df4a67037 100644
--- a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
+++ b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
@@ -682,6 +682,14 @@ video {
top: 100%;
}
+.left-1\/2 {
+ left: 50%;
+}
+
+.top-2 {
+ top: 0.5rem;
+}
+
.-z-10 {
z-index: -10;
}
@@ -1174,6 +1182,11 @@ video {
transform-origin: top right;
}
+.-translate-x-1\/2 {
+ --tw-translate-x: -50%;
+ transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
+}
+
.rotate-180 {
--tw-rotate: 180deg;
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
diff --git a/apps/server/AliasVault.Client/wwwroot/js/utilities.js b/apps/server/AliasVault.Client/wwwroot/js/utilities.js
index f1874a5a8..6e47cc429 100644
--- a/apps/server/AliasVault.Client/wwwroot/js/utilities.js
+++ b/apps/server/AliasVault.Client/wwwroot/js/utilities.js
@@ -47,6 +47,7 @@ window.clipboardManager = {
copiedValue: null,
clearPending: false, // Track if clear is pending due to focus issues
statusCallback: null, // Callback to notify Blazor of status changes
+ failedAttempts: 0, // Track consecutive failed clear attempts
// Set up a new clipboard clear schedule
scheduleClipboardClear: function(seconds) {
@@ -56,8 +57,9 @@ window.clipboardManager = {
this.clearTimer = null;
}
- // Reset pending state
+ // Reset pending state and failed attempts counter
this.clearPending = false;
+ this.failedAttempts = 0;
this.notifyStatusChange('active');
// Set the clear by time
@@ -101,6 +103,7 @@ window.clipboardManager = {
this.clearByTime = null;
this.copiedValue = null;
this.clearPending = false;
+ this.failedAttempts = 0;
if (this.clearTimer) {
clearTimeout(this.clearTimer);
this.clearTimer = null;
@@ -110,21 +113,30 @@ window.clipboardManager = {
})
.catch((error) => {
if (error.name === 'NotAllowedError' || error.message.includes('Document is not focused')) {
- // Don't clear the clearByTime, we'll retry when we get focus
- this.clearPending = true;
- this.notifyStatusChange('pending');
+ // Browser blocked clipboard clear - increment failed attempts
+ this.failedAttempts++;
+
+ // Only show UI prompt after 2+ consecutive failures
+ // First failure might be due to timing/focus, second failure indicates real restriction
+ if (this.failedAttempts >= 2) {
+ this.clearPending = true;
+ this.notifyStatusChange('manual_clear_required');
+ } else {
+ // First failure - just set pending, will retry on focus
+ this.notifyStatusChange('pending');
+ }
+ } else {
+ console.warn(`[Clipboard] ❌ ERROR - Failed to clear clipboard from: ${source}`, error);
}
- console.warn(`[Clipboard] ❌ ERROR - Failed to clear clipboard from: ${source}`, error);
+ return false;
});
},
// Check and clear if needed (called on focus events)
checkAndClear: function(source) {
if (this.clearByTime && Date.now() >= this.clearByTime) {
- // Reset pending state when we're actively trying to clear
- this.clearPending = false;
- this.notifyStatusChange('active');
- // Small delay to ensure browser is ready after focus
+ // Small delay to ensure browser is ready after focus, then attempt clear
+ // Don't reset pending state here - let attemptClipboardClear handle it based on success/failure
setTimeout(() => {
this.attemptClipboardClear(source);
}, 100);