From 3ecee4a821b8abb95d19d7f7ea6867db132f0632 Mon Sep 17 00:00:00 2001 From: Geoffroy BONNEVILLE Date: Tue, 26 May 2020 12:30:52 +0200 Subject: [PATCH] Fix ClipboardAction so that it only clears Clipboard when Window is active --- .../en-us/baselisting/releaseNotes.txt | 3 ++- .../fr-fr/baselisting/releaseNotes.txt | 3 ++- WinAppCommon/Actions/ClipboardAction.cs | 18 ++++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ModernKeePass/appMetadata/en-us/baselisting/releaseNotes.txt b/ModernKeePass/appMetadata/en-us/baselisting/releaseNotes.txt index 31f167c..714e4dd 100644 --- a/ModernKeePass/appMetadata/en-us/baselisting/releaseNotes.txt +++ b/ModernKeePass/appMetadata/en-us/baselisting/releaseNotes.txt @@ -1 +1,2 @@ -Data is now protected in memory as well as at rest \ No newline at end of file +Data is now protected in memory as well as at rest +Fix clipboard copy expiration issue \ No newline at end of file diff --git a/ModernKeePass/appMetadata/fr-fr/baselisting/releaseNotes.txt b/ModernKeePass/appMetadata/fr-fr/baselisting/releaseNotes.txt index d8254c6..2bc3280 100644 --- a/ModernKeePass/appMetadata/fr-fr/baselisting/releaseNotes.txt +++ b/ModernKeePass/appMetadata/fr-fr/baselisting/releaseNotes.txt @@ -1 +1,2 @@ -Protection des donnees en memoire en plus du chiffrement de la base de donnees \ No newline at end of file +Protection des donnees en memoire en plus du chiffrement de la base de donnees +Correction d'un bug dans l'expiration des donnees copiees \ No newline at end of file diff --git a/WinAppCommon/Actions/ClipboardAction.cs b/WinAppCommon/Actions/ClipboardAction.cs index ffec1db..b1e4509 100644 --- a/WinAppCommon/Actions/ClipboardAction.cs +++ b/WinAppCommon/Actions/ClipboardAction.cs @@ -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(); var cryptography = App.Services.GetRequiredService(); + 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); } } }