From 6c6da368dd5ed52b9ba487423cc58a60b920d5b4 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 29 May 2019 09:36:57 -0400 Subject: [PATCH] options page --- src/App/Pages/Settings/OptionsPage.xaml | 34 +++++++++++- src/App/Pages/Settings/OptionsPage.xaml.cs | 3 +- .../Pages/Settings/OptionsPageViewModel.cs | 52 ++++++++++++++++++- 3 files changed, 86 insertions(+), 3 deletions(-) diff --git a/src/App/Pages/Settings/OptionsPage.xaml b/src/App/Pages/Settings/OptionsPage.xaml index 7858de044..f1e5a7874 100644 --- a/src/App/Pages/Settings/OptionsPage.xaml +++ b/src/App/Pages/Settings/OptionsPage.xaml @@ -7,10 +7,42 @@ xmlns:u="clr-namespace:Bit.App.Utilities" x:DataType="pages:OptionsPageViewModel" Title="{Binding PageTitle}"> + - + + + + + + + + + + diff --git a/src/App/Pages/Settings/OptionsPage.xaml.cs b/src/App/Pages/Settings/OptionsPage.xaml.cs index 1ac7f67dd..56f1a8b8c 100644 --- a/src/App/Pages/Settings/OptionsPage.xaml.cs +++ b/src/App/Pages/Settings/OptionsPage.xaml.cs @@ -13,9 +13,10 @@ namespace Bit.App.Pages _vm.Page = this; } - protected override void OnAppearing() + protected async override void OnAppearing() { base.OnAppearing(); + await _vm.InitAsync(); } } } diff --git a/src/App/Pages/Settings/OptionsPageViewModel.cs b/src/App/Pages/Settings/OptionsPageViewModel.cs index 9ff0a8f01..d9eafc654 100644 --- a/src/App/Pages/Settings/OptionsPageViewModel.cs +++ b/src/App/Pages/Settings/OptionsPageViewModel.cs @@ -1,7 +1,7 @@ using Bit.App.Abstractions; using Bit.App.Resources; +using Bit.Core; using Bit.Core.Abstractions; -using Bit.Core.Exceptions; using Bit.Core.Utilities; using System.Threading.Tasks; @@ -11,13 +11,63 @@ namespace Bit.App.Pages { private readonly IDeviceActionService _deviceActionService; private readonly IPlatformUtilsService _platformUtilsService; + private readonly IStorageService _storageService; + private readonly ITotpService _totpService; + private readonly IStateService _stateService; + + private bool _disableFavicon; + private bool _disableAutoTotpCopy; public OptionsPageViewModel() { _deviceActionService = ServiceContainer.Resolve("deviceActionService"); _platformUtilsService = ServiceContainer.Resolve("platformUtilsService"); + _storageService = ServiceContainer.Resolve("storageService"); + _totpService = ServiceContainer.Resolve("totpService"); + _stateService = ServiceContainer.Resolve("stateService"); PageTitle = AppResources.Options; } + + public bool DisableFavicon + { + get => _disableFavicon; + set + { + if(SetProperty(ref _disableFavicon, value)) + { + var task = UpdateDisableFaviconAsync(); + } + } + } + + public bool DisableAutoTotpCopy + { + get => _disableAutoTotpCopy; + set + { + if(SetProperty(ref _disableAutoTotpCopy, value)) + { + var task = UpdateAutoTotpCopyAsync(); + } + } + } + + public async Task InitAsync() + { + DisableAutoTotpCopy = !(await _totpService.IsAutoCopyEnabledAsync()); + DisableFavicon = await _storageService.GetAsync(Constants.DisableFaviconKey); + } + + private async Task UpdateAutoTotpCopyAsync() + { + await _storageService.SaveAsync(Constants.DisableAutoTotpCopyKey, DisableAutoTotpCopy); + } + + private async Task UpdateDisableFaviconAsync() + { + await _storageService.SaveAsync(Constants.DisableFaviconKey, DisableFavicon); + await _stateService.SaveAsync(Constants.DisableFaviconKey, DisableFavicon); + } } }