diff --git a/TemplateApp/Controls/AccountControl.xaml b/TemplateApp/Controls/AccountControl.xaml index ad1f804..7b53c63 100644 --- a/TemplateApp/Controls/AccountControl.xaml +++ b/TemplateApp/Controls/AccountControl.xaml @@ -17,7 +17,7 @@ xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors" xmlns:ui="using:Microsoft.Toolkit.Uwp.UI" mc:Ignorable="d"> - + diff --git a/TemplateApp/Controls/AccountControl.xaml.cs b/TemplateApp/Controls/AccountControl.xaml.cs index cca45c4..fb81717 100644 --- a/TemplateApp/Controls/AccountControl.xaml.cs +++ b/TemplateApp/Controls/AccountControl.xaml.cs @@ -1,4 +1,5 @@ -using Protecc.Classes; +using Microsoft.Toolkit.Uwp.UI.Controls; +using Protecc.Classes; using Protecc.Helpers; using Protecc.Services; using System; @@ -36,7 +37,8 @@ public sealed partial class AccountControl : UserControl public VaultItem AccountVaultItem { get { return (VaultItem)GetValue(AccountVaultItemProperty); } - set { + set + { SetValue(AccountVaultItemProperty, value); TOTP = new TOTPHelper(AccountVaultItem); } @@ -44,6 +46,17 @@ public VaultItem AccountVaultItem public static readonly DependencyProperty AccountVaultItemProperty = DependencyProperty.Register("AccountVaultItem", typeof(VaultItem), typeof(AccountControl), null); + public InAppNotification InAppNotificationComponent + { + get { return (InAppNotification)GetValue(InAppNotificationComponentProperty); } + set + { + SetValue(InAppNotificationComponentProperty, value); + } + } + public static readonly DependencyProperty InAppNotificationComponentProperty = + DependencyProperty.Register("InAppNotificationComponent", typeof(InAppNotification), typeof(AccountControl), null); + public AccountControl() { this.InitializeComponent(); @@ -90,10 +103,15 @@ private async void Copy_Click(object sender, RoutedEventArgs e) dataPackage.SetText(TOTP.Code.Replace(" ", "")); Clipboard.SetContent(dataPackage); CopyIcon.Symbol = Fluent.Icons.FluentSymbol.Checkmark20; + // Show notification + InAppNotificationComponent.Show("Code copied to clipboard!", 3000); } catch { CopyIcon.Symbol = Fluent.Icons.FluentSymbol.ErrorCircle20; + // Inform user about error + InAppNotificationComponent.Show("An error occurred while copying to clipboard.", 3000); + } await Task.Delay(2000); CopyIcon.Symbol = Fluent.Icons.FluentSymbol.Copy20; @@ -110,5 +128,28 @@ private void CodeBlock_Loaded(object sender, RoutedEventArgs e) } //private void Content_Loaded(object sender, RoutedEventArgs e) => TOTP = new TOTPHelper(CodeBlock, Progress, AccountVaultItem); + + /// + /// Copies displayed code to clipboard and displays Windows notification. + /// + private void Content_DoubleTapped(object sender, RoutedEventArgs e) + { + try + { + // Remove spaces and copy to clipboard + var content = new DataPackage(); + content.RequestedOperation = DataPackageOperation.Copy; + content.SetText(TOTP.Code.Replace(" ", "")); + Clipboard.SetContent(content); + + // Show notification + InAppNotificationComponent.Show("Code copied to clipboard!", 3000); + } + catch + { + // Inform user about error + InAppNotificationComponent.Show("An error occurred while copying to clipboard.", 3000); + } + } } } diff --git a/TemplateApp/MainPage.xaml b/TemplateApp/MainPage.xaml index 94c6648..458b39b 100644 --- a/TemplateApp/MainPage.xaml +++ b/TemplateApp/MainPage.xaml @@ -83,7 +83,7 @@ - + @@ -103,5 +103,6 @@ +