Fix ClipboardAction so that it only clears Clipboard when Window is active

This commit is contained in:
Geoffroy BONNEVILLE
2020-05-26 12:30:52 +02:00
parent 3d436c56fa
commit 3ecee4a821
3 changed files with 14 additions and 10 deletions

View File

@@ -1 +1,2 @@
Data is now protected in memory as well as at rest
Fix clipboard copy expiration issue

View File

@@ -1 +1,2 @@
Protection des donnees en memoire en plus du chiffrement de la base de donnees
Correction d'un bug dans l'expiration des donnees copiees

View File

@@ -1,5 +1,6 @@
using System;
using Windows.ApplicationModel.DataTransfer;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Xaml.Interactivity;
@@ -11,6 +12,7 @@ namespace ModernKeePass.Actions
public class ClipboardAction : DependencyObject, IAction
{
private DispatcherTimer _dispatcher;
private bool _isWindowActivated = true;
public string Text
{
@@ -36,6 +38,8 @@ namespace ModernKeePass.Actions
var settings = App.Services.GetRequiredService<ISettingsProxy>();
var cryptography = App.Services.GetRequiredService<ICryptographyClient>();
CoreWindow.GetForCurrentThread().Activated += ClipboardAction_Activated;
_dispatcher = new DispatcherTimer {Interval = TimeSpan.FromSeconds(settings.GetSetting(Constants.Settings.ClipboardTimeout, 10))};
_dispatcher.Tick += Dispatcher_Tick;
@@ -48,16 +52,14 @@ namespace ModernKeePass.Actions
return null;
}
private void ClipboardAction_Activated(CoreWindow sender, WindowActivatedEventArgs args)
{
_isWindowActivated = args.WindowActivationState != CoreWindowActivationState.Deactivated;
}
private void Dispatcher_Tick(object sender, object e)
{
try
{
Clipboard.SetContent(null);
}
finally
{
_dispatcher.Stop();
}
if (_isWindowActivated) Clipboard.SetContent(null);
}
}
}