protected async override void OnAppearing() { if (_requireAuth && !_authService.IsAuthenticated) { Device.BeginInvokeOnMainThread( () => Application.Current.MainPage = new ExtendedNavigationPage(new HomePage())); } if (_syncIndicator) { MessagingCenter.Subscribe <Application, bool>(Application.Current, "SyncCompleted", (sender, success) => Device.BeginInvokeOnMainThread(() => IsBusy = _syncService.SyncInProgress)); MessagingCenter.Subscribe <ISyncService>(Application.Current, "SyncStarted", (sender) => Device.BeginInvokeOnMainThread(() => IsBusy = _syncService.SyncInProgress)); } if (_syncIndicator) { IsBusy = _syncService.SyncInProgress; } _googleAnalyticsService.TrackPage(GetType().Name); await _lockService.CheckLockAsync(false, true); base.OnAppearing(); }
public App( AppOptions options, IAuthService authService, IConnectivity connectivity, IDatabaseService databaseService, ISyncService syncService, ISettings settings, ILockService lockService, ILocalizeService localizeService, IAppInfoService appInfoService, IAppSettingsService appSettingsService, IDeviceActionService deviceActionService) { _options = options ?? new AppOptions(); _authService = authService; _databaseService = databaseService; _connectivity = connectivity; _syncService = syncService; _settings = settings; _lockService = lockService; _localizeService = localizeService; _appInfoService = appInfoService; _appSettingsService = appSettingsService; _deviceActionService = deviceActionService; SetCulture(); SetStyles(); if (authService.IsAuthenticated) { if (_options.FromAutofillFramework && _options.SaveType.HasValue) { MainPage = new ExtendedNavigationPage(new VaultAddCipherPage(_options)); } else if (_options.Uri != null) { MainPage = new ExtendedNavigationPage(new VaultAutofillListCiphersPage(_options)); } else { MainPage = new MainPage(); } } else { MainPage = new ExtendedNavigationPage(new HomePage()); } if (Device.RuntimePlatform == Device.iOS) { MessagingCenter.Subscribe <Application, bool>(Current, "Resumed", async(sender, args) => { Device.BeginInvokeOnMainThread(async() => await _lockService.CheckLockAsync(args)); await Task.Run(() => FullSyncAsync()).ConfigureAwait(false); }); } }
protected async override void OnStart() { // Handle when your app starts await _lockService.CheckLockAsync(false); if (string.IsNullOrWhiteSpace(_options.Uri)) { var updated = Helpers.PerformUpdateTasks(_settings, _appInfoService, _databaseService, _syncService); if (!updated) { await Task.Run(() => FullSyncAsync()).ConfigureAwait(false); } } if ((DateTime.UtcNow - _appSettingsService.LastCacheClear).TotalDays >= 1) { await Task.Run(() => _deviceActionService.ClearCache()).ConfigureAwait(false); } Debug.WriteLine("OnStart"); }
private void LockTimer(int lockOptionMinutes) { if (_lockBackgroundTaskId > 0) { UIApplication.SharedApplication.EndBackgroundTask(_lockBackgroundTaskId); _lockBackgroundTaskId = 0; } _lockBackgroundTaskId = UIApplication.SharedApplication.BeginBackgroundTask(() => { UIApplication.SharedApplication.EndBackgroundTask(_lockBackgroundTaskId); _lockBackgroundTaskId = 0; }); var lockOptionMs = lockOptionMinutes * 60000; _lockTimer?.Invalidate(); _lockTimer?.Dispose(); _lockTimer = null; var lockMsSpan = TimeSpan.FromMilliseconds(lockOptionMs + 10); Device.BeginInvokeOnMainThread(() => { _lockTimer = NSTimer.CreateScheduledTimer(lockMsSpan, timer => { Device.BeginInvokeOnMainThread(() => { _lockService.CheckLockAsync(); _lockTimer?.Invalidate(); _lockTimer?.Dispose(); _lockTimer = null; if (_lockBackgroundTaskId > 0) { UIApplication.SharedApplication.EndBackgroundTask(_lockBackgroundTaskId); _lockBackgroundTaskId = 0; } }); }); }); }