コード例 #1
0
ファイル: AddEditPage.xaml.cs プロジェクト: xq2/mobile
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            if (!await AppHelpers.IsVaultTimeoutImmediateAsync())
            {
                await _vaultTimeoutService.CheckVaultTimeoutAsync();
            }
            if (await _vaultTimeoutService.IsLockedAsync())
            {
                return;
            }
            await LoadOnAppearedAsync(_scrollView, true, async() =>
            {
                var success = await _vm.LoadAsync(_appOptions);
                if (!success)
                {
                    await Navigation.PopModalAsync();
                    return;
                }
                AdjustToolbar();
                await ShowAlertsAsync();
                if (!_vm.EditMode && string.IsNullOrWhiteSpace(_vm.Cipher?.Name))
                {
                    RequestFocus(_nameEntry);
                }
                _scrollView.Scrolled += (sender, args) => _vm.HandleScroll();
            });

            // Hide password reprompt option if using key connector
            _passwordPrompt.IsVisible = !await _keyConnectorService.GetUsesKeyConnector();
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: tank0226/bitwarden-mobile
        protected async override void OnSleep()
        {
            System.Diagnostics.Debug.WriteLine("XF App: OnSleep");
            _isResumed = false;
            if (Device.RuntimePlatform == Device.Android)
            {
                var isLocked = await _vaultTimeoutService.IsLockedAsync();

                if (!isLocked)
                {
                    await _storageService.SaveAsync(Constants.LastActiveTimeKey, _deviceActionService.GetActiveTime());
                }
                SetTabsPageFromAutofill(isLocked);
                await SleptAsync();
            }
        }
コード例 #3
0
        protected async override void OnAppearing()
        {
            base.OnAppearing();
            if (_syncService.SyncInProgress)
            {
                IsBusy = true;
            }
            if (!await AppHelpers.IsVaultTimeoutImmediateAsync())
            {
                await _vaultTimeoutService.CheckVaultTimeoutAsync();
            }
            if (await _vaultTimeoutService.IsLockedAsync())
            {
                return;
            }

            _accountAvatar?.OnAppearing();
            _vm.AvatarImageSource = await GetAvatarImageSourceAsync();

            _broadcasterService.Subscribe(nameof(AutofillCiphersPage), async(message) =>
            {
                try
                {
                    if (message.Command == "syncStarted")
                    {
                        Device.BeginInvokeOnMainThread(() => IsBusy = true);
                    }
                    else if (message.Command == "syncCompleted")
                    {
                        await Task.Delay(500);
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            IsBusy = false;
                            if (_vm.LoadedOnce)
                            {
                                var task = _vm.LoadAsync();
                            }
                        });
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.LogEvenIfCantBeResolved(ex);
                }
            });

            await LoadOnAppearedAsync(_mainLayout, false, async() =>
            {
                try
                {
                    await _vm.LoadAsync();
                }
                catch (Exception e) when(e.Message.Contains("No key."))
                {
                    await Task.Delay(1000);
                    await _vm.LoadAsync();
                }
            }, _mainContent);
        }
コード例 #4
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            try
            {
                if (!await AppHelpers.IsVaultTimeoutImmediateAsync())
                {
                    await _vaultTimeoutService.CheckVaultTimeoutAsync();
                }
                if (await _vaultTimeoutService.IsLockedAsync())
                {
                    return;
                }
                await _vm.InitAsync();

                _broadcasterService.Subscribe(nameof(SendAddEditPage), message =>
                {
                    if (message.Command == "selectFileResult")
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            var data     = message.Data as Tuple <byte[], string>;
                            _vm.FileData = data.Item1;
                            _vm.FileName = data.Item2;
                        });
                    }
                });

                await LoadOnAppearedAsync(_scrollView, true, async() =>
                {
                    var success = await _vm.LoadAsync();
                    if (!success)
                    {
                        await CloseAsync();
                        return;
                    }
                    await HandleCreateRequest();
                    if (!_vm.EditMode && string.IsNullOrWhiteSpace(_vm.Send?.Name))
                    {
                        RequestFocus(_nameEntry);
                    }
                    AdjustToolbar();
                });
            }
            catch (Exception ex)
            {
#if !FDROID
                Crashes.TrackError(ex);
#endif
                await CloseAsync();
            }
        }
コード例 #5
0
        public async override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal,
                                                 FillCallback callback)
        {
            var structure = request.FillContexts?.LastOrDefault()?.Structure;

            if (structure == null)
            {
                return;
            }

            var parser = new Parser(structure, ApplicationContext);

            parser.Parse();

            if (_storageService == null)
            {
                _storageService = ServiceContainer.Resolve <IStorageService>("storageService");
            }

            var shouldAutofill = await parser.ShouldAutofillAsync(_storageService);

            if (!shouldAutofill)
            {
                return;
            }

            var inlineAutofillEnabled = await _storageService.GetAsync <bool?>(Constants.InlineAutofillEnabledKey) ?? true;

            if (_vaultTimeoutService == null)
            {
                _vaultTimeoutService = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService");
            }

            List <FilledItem> items = null;
            await _vaultTimeoutService.CheckVaultTimeoutAsync();

            var locked = await _vaultTimeoutService.IsLockedAsync();

            if (!locked)
            {
                if (_cipherService == null)
                {
                    _cipherService = ServiceContainer.Resolve <ICipherService>("cipherService");
                }
                items = await AutofillHelpers.GetFillItemsAsync(parser, _cipherService);
            }

            // build response
            var response = AutofillHelpers.BuildFillResponse(parser, items, locked, inlineAutofillEnabled, request);

            callback.OnSuccess(response);
        }
コード例 #6
0
        private async Task SsoAuthSuccessAsync()
        {
            RestoreAppOptionsFromCopy();
            await AppHelpers.ClearPreviousPage();

            if (await _vaultTimeoutService.IsLockedAsync())
            {
                Application.Current.MainPage = new NavigationPage(new LockPage(_appOptions));
            }
            else
            {
                Application.Current.MainPage = new TabsPage(_appOptions, null);
            }
        }
コード例 #7
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            try
            {
                if (!await AppHelpers.IsVaultTimeoutImmediateAsync())
                {
                    await _vaultTimeoutService.CheckVaultTimeoutAsync();
                }
                if (await _vaultTimeoutService.IsLockedAsync())
                {
                    return;
                }
                await _vm.InitAsync();

                if (!await _vm.LoadAsync())
                {
                    await CloseAsync();

                    return;
                }

                _accountAvatar?.OnAppearing();
                await Device.InvokeOnMainThreadAsync(async() => _vm.AvatarImageSource = await GetAvatarImageSourceAsync());

                await HandleCreateRequest();

                if (string.IsNullOrWhiteSpace(_vm.Send?.Name))
                {
                    RequestFocus(_nameEntry);
                }
                AdjustToolbar();
            }
            catch (Exception ex)
            {
                _logger.Value.Exception(ex);
                await CloseAsync();
            }
        }
コード例 #8
0
 protected async override void OnAppearing()
 {
     base.OnAppearing();
     if (!await AppHelpers.IsVaultTimeoutImmediateAsync())
     {
         await _vaultTimeoutService.CheckVaultTimeoutAsync();
     }
     if (await _vaultTimeoutService.IsLockedAsync())
     {
         return;
     }
     await LoadOnAppearedAsync(_mainLayout, false, async() =>
     {
         try
         {
             await _vm.LoadAsync();
         }
         catch (Exception e) when(e.Message.Contains("No key."))
         {
             await Task.Delay(1000);
             await _vm.LoadAsync();
         }
     }, _mainContent);
 }
コード例 #9
0
ファイル: AccountsManager.cs プロジェクト: turlodales/mobile
        public async Task NavigateOnAccountChangeAsync(bool?isAuthed = null)
        {
            // TODO: this could be improved by doing chain of responsability pattern
            // but for now it may be an overkill, if logic gets more complex consider refactoring it

            var authed = isAuthed ?? await _stateService.IsAuthenticatedAsync();

            if (authed)
            {
                if (await _vaultTimeoutService.IsLoggedOutByTimeoutAsync() ||
                    await _vaultTimeoutService.ShouldLogOutByTimeoutAsync())
                {
                    // TODO implement orgIdentifier flow to SSO Login page, same as email flow below
                    // var orgIdentifier = await _stateService.GetOrgIdentifierAsync();

                    var email = await _stateService.GetEmailAsync();

                    Options.HideAccountSwitcher = await _stateService.GetActiveUserIdAsync() == null;

                    _accountsManagerHost.Navigate(NavigationTarget.Login, new LoginNavigationParams(email));
                }
                else if (await _vaultTimeoutService.IsLockedAsync() ||
                         await _vaultTimeoutService.ShouldLockAsync())
                {
                    _accountsManagerHost.Navigate(NavigationTarget.Lock);
                }
                else if (Options.FromAutofillFramework && Options.SaveType.HasValue)
                {
                    _accountsManagerHost.Navigate(NavigationTarget.AddEditCipher);
                }
                else if (Options.Uri != null)
                {
                    _accountsManagerHost.Navigate(NavigationTarget.AutofillCiphers);
                }
                else if (Options.CreateSend != null)
                {
                    _accountsManagerHost.Navigate(NavigationTarget.SendAddEdit);
                }
                else
                {
                    _accountsManagerHost.Navigate(NavigationTarget.Home);
                }
            }
            else
            {
                Options.HideAccountSwitcher = await _stateService.GetActiveUserIdAsync() == null;

                if (await _vaultTimeoutService.IsLoggedOutByTimeoutAsync() ||
                    await _vaultTimeoutService.ShouldLogOutByTimeoutAsync())
                {
                    // TODO implement orgIdentifier flow to SSO Login page, same as email flow below
                    // var orgIdentifier = await _stateService.GetOrgIdentifierAsync();

                    var email = await _stateService.GetEmailAsync();

                    _accountsManagerHost.Navigate(NavigationTarget.Login, new LoginNavigationParams(email));
                }
                else
                {
                    _accountsManagerHost.Navigate(NavigationTarget.HomeLogin);
                }
            }
        }
コード例 #10
0
        public async override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal,
                                                 FillCallback callback)
        {
            try
            {
                var structure = request.FillContexts?.LastOrDefault()?.Structure;
                if (structure == null)
                {
                    return;
                }

                var parser = new Parser(structure, ApplicationContext);
                parser.Parse();

                if (_storageService == null)
                {
                    _storageService = ServiceContainer.Resolve <IStorageService>("storageService");
                }

                var shouldAutofill = await parser.ShouldAutofillAsync(_storageService);

                if (!shouldAutofill)
                {
                    return;
                }

                var inlineAutofillEnabled = await _storageService.GetAsync <bool?>(Constants.InlineAutofillEnabledKey) ?? true;

                if (_vaultTimeoutService == null)
                {
                    _vaultTimeoutService = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService");
                }

                List <FilledItem> items = null;
                await _vaultTimeoutService.CheckVaultTimeoutAsync();

                var locked = await _vaultTimeoutService.IsLockedAsync();

                if (!locked)
                {
                    if (_cipherService == null)
                    {
                        _cipherService = ServiceContainer.Resolve <ICipherService>("cipherService");
                    }
                    items = await AutofillHelpers.GetFillItemsAsync(parser, _cipherService);
                }

                // build response
                var response          = AutofillHelpers.CreateFillResponse(parser, items, locked, inlineAutofillEnabled, request);
                var disableSavePrompt = await _storageService.GetAsync <bool?>(Constants.AutofillDisableSavePromptKey);

                if (!disableSavePrompt.GetValueOrDefault())
                {
                    AutofillHelpers.AddSaveInfo(parser, request, response, parser.FieldCollection);
                }
                callback.OnSuccess(response.Build());
            }
            catch (Exception e)
            {
#if !FDROID
                Crashes.TrackError(e);
#endif
            }
        }