protected async override void OnAppearing() { base.OnAppearing(); _broadcasterService.Subscribe(_pageName, async(message) => { if (message.Command == "syncCompleted") { await Task.Delay(500); Device.BeginInvokeOnMainThread(() => { var task = _vm.LoadAsync(); }); } }); await LoadOnAppearedAsync(_mainLayout, false, async() => { if (!_syncService.SyncInProgress) { await _vm.LoadAsync(); } else { await Task.Delay(5000); if (!_vm.Loaded) { await _vm.LoadAsync(); } } }, _mainContent); // Push registration var lastPushRegistration = await _storageService.GetAsync <DateTime?>(Constants.PushLastRegistrationDateKey); lastPushRegistration = lastPushRegistration.GetValueOrDefault(DateTime.MinValue); if (Device.RuntimePlatform == Device.iOS) { var pushPromptShow = await _storageService.GetAsync <bool?>(Constants.PushInitialPromptShownKey); if (!pushPromptShow.GetValueOrDefault(false)) { await _storageService.SaveAsync(Constants.PushInitialPromptShownKey, true); await DisplayAlert(AppResources.EnableAutomaticSyncing, AppResources.PushNotificationAlert, AppResources.OkGotIt); } if (!pushPromptShow.GetValueOrDefault(false) || DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1)) { await _pushNotificationService.RegisterAsync(); } } else if (Device.RuntimePlatform == Device.Android && DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1)) { await _pushNotificationService.RegisterAsync(); } }
protected async override void OnAppearing() { base.OnAppearing(); if (_syncService.SyncInProgress) { IsBusy = true; } _broadcasterService.Subscribe(_pageName, async(message) => { 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(); } }); } }); var migratedFromV1 = await _storageService.GetAsync <bool?>(Constants.MigratedFromV1); await LoadOnAppearedAsync(_mainLayout, false, async() => { if (!_syncService.SyncInProgress) { try { await _vm.LoadAsync(); } catch (Exception e) when(e.Message.Contains("No key.")) { await Task.Delay(5000); await _vm.LoadAsync(); } } else { await Task.Delay(5000); if (!_vm.Loaded) { await _vm.LoadAsync(); } } // Forced sync if for some reason we have no data after a v1 migration if (_vm.MainPage && !_syncService.SyncInProgress && migratedFromV1.GetValueOrDefault() && !_vm.HasCiphers && Xamarin.Essentials.Connectivity.NetworkAccess != Xamarin.Essentials.NetworkAccess.None) { var triedV1ReSync = await _storageService.GetAsync <bool?>(Constants.TriedV1Resync); if (!triedV1ReSync.GetValueOrDefault()) { await _storageService.SaveAsync(Constants.TriedV1Resync, true); await _syncService.FullSyncAsync(true); } } }, _mainContent); if (!_vm.MainPage) { return; } // Push registration var lastPushRegistration = await _storageService.GetAsync <DateTime?>(Constants.PushLastRegistrationDateKey); lastPushRegistration = lastPushRegistration.GetValueOrDefault(DateTime.MinValue); if (Device.RuntimePlatform == Device.iOS) { var pushPromptShow = await _storageService.GetAsync <bool?>(Constants.PushInitialPromptShownKey); if (!pushPromptShow.GetValueOrDefault(false)) { await _storageService.SaveAsync(Constants.PushInitialPromptShownKey, true); await DisplayAlert(AppResources.EnableAutomaticSyncing, AppResources.PushNotificationAlert, AppResources.OkGotIt); } if (!pushPromptShow.GetValueOrDefault(false) || DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1)) { await _pushNotificationService.RegisterAsync(); } } else if (Device.RuntimePlatform == Device.Android) { if (DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1)) { await _pushNotificationService.RegisterAsync(); } if (!_deviceActionService.AutofillAccessibilityServiceRunning() && !_deviceActionService.AutofillServiceEnabled()) { if (migratedFromV1.GetValueOrDefault()) { var migratedFromV1AutofillPromptShown = await _storageService.GetAsync <bool?>( Constants.MigratedFromV1AutofillPromptShown); if (!migratedFromV1AutofillPromptShown.GetValueOrDefault()) { await DisplayAlert(AppResources.Autofill, AppResources.AutofillServiceNotEnabled, AppResources.Ok); } } } await _storageService.SaveAsync(Constants.MigratedFromV1AutofillPromptShown, true); } }
protected async override void OnAppearing() { base.OnAppearing(); if (_syncService.SyncInProgress) { IsBusy = true; } _accountAvatar?.OnAppearing(); if (_vm.MainPage) { _vm.AvatarImageSource = await GetAvatarImageSourceAsync(); } _broadcasterService.Subscribe(_pageName, 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() => { if (!_syncService.SyncInProgress || (await _cipherService.GetAllAsync()).Any()) { try { await _vm.LoadAsync(); } catch (Exception e) when(e.Message.Contains("No key.")) { await Task.Delay(1000); await _vm.LoadAsync(); } } else { await Task.Delay(5000); if (!_vm.Loaded) { await _vm.LoadAsync(); } } await ShowPreviousPageAsync(); AdjustToolbar(); }, _mainContent); if (!_vm.MainPage) { return; } // Push registration var lastPushRegistration = await _stateService.GetPushLastRegistrationDateAsync(); lastPushRegistration = lastPushRegistration.GetValueOrDefault(DateTime.MinValue); if (Device.RuntimePlatform == Device.iOS) { var pushPromptShow = await _stateService.GetPushInitialPromptShownAsync(); if (!pushPromptShow.GetValueOrDefault(false)) { await _stateService.SetPushInitialPromptShownAsync(true); await DisplayAlert(AppResources.EnableAutomaticSyncing, AppResources.PushNotificationAlert, AppResources.OkGotIt); } if (!pushPromptShow.GetValueOrDefault(false) || DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1)) { await _pushNotificationService.RegisterAsync(); } } else if (Device.RuntimePlatform == Device.Android) { if (DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1)) { await _pushNotificationService.RegisterAsync(); } } }