2022-04-26 18:21:17 +03:00
|
|
|
|
using System;
|
2022-10-31 18:57:09 +03:00
|
|
|
|
using System.Linq;
|
2022-04-26 18:21:17 +03:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Bit.App.Abstractions;
|
2019-05-17 19:03:35 +03:00
|
|
|
|
using Bit.App.Models;
|
2019-04-10 06:24:03 +03:00
|
|
|
|
using Bit.App.Pages;
|
2019-04-11 22:33:10 +03:00
|
|
|
|
using Bit.App.Resources;
|
|
|
|
|
using Bit.App.Services;
|
2019-03-30 04:23:34 +03:00
|
|
|
|
using Bit.App.Utilities;
|
2022-06-08 20:24:01 +03:00
|
|
|
|
using Bit.App.Utilities.AccountManagement;
|
2022-09-26 20:27:57 +03:00
|
|
|
|
using Bit.Core;
|
2019-04-11 22:33:10 +03:00
|
|
|
|
using Bit.Core.Abstractions;
|
2022-04-26 18:21:17 +03:00
|
|
|
|
using Bit.Core.Enums;
|
2022-02-23 20:40:17 +03:00
|
|
|
|
using Bit.Core.Models.Data;
|
2022-10-18 19:21:45 +03:00
|
|
|
|
using Bit.Core.Models.Response;
|
2022-07-06 00:14:10 +03:00
|
|
|
|
using Bit.Core.Services;
|
2019-04-11 22:33:10 +03:00
|
|
|
|
using Bit.Core.Utilities;
|
2019-03-28 03:12:44 +03:00
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using Xamarin.Forms.Xaml;
|
|
|
|
|
|
|
|
|
|
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
|
|
|
|
|
namespace Bit.App
|
|
|
|
|
{
|
2022-06-08 20:24:01 +03:00
|
|
|
|
public partial class App : Application, IAccountsManagerHost
|
2019-03-28 03:12:44 +03:00
|
|
|
|
{
|
2019-04-18 20:15:46 +03:00
|
|
|
|
private readonly IBroadcasterService _broadcasterService;
|
|
|
|
|
private readonly IMessagingService _messagingService;
|
2019-05-15 22:47:50 +03:00
|
|
|
|
private readonly IStateService _stateService;
|
2020-05-29 19:26:36 +03:00
|
|
|
|
private readonly IVaultTimeoutService _vaultTimeoutService;
|
2019-05-16 00:37:59 +03:00
|
|
|
|
private readonly ISyncService _syncService;
|
|
|
|
|
private readonly IAuthService _authService;
|
2019-05-17 19:03:35 +03:00
|
|
|
|
private readonly IDeviceActionService _deviceActionService;
|
2022-10-12 00:19:32 +03:00
|
|
|
|
private readonly IFileService _fileService;
|
2022-06-08 20:24:01 +03:00
|
|
|
|
private readonly IAccountsManager _accountsManager;
|
2022-09-26 20:27:57 +03:00
|
|
|
|
private readonly IPushNotificationService _pushNotificationService;
|
2020-03-06 00:18:04 +03:00
|
|
|
|
private static bool _isResumed;
|
2022-10-31 18:57:09 +03:00
|
|
|
|
// these variables are static because the app is launching new activities on notification click, creating new instances of App.
|
2022-09-26 20:27:57 +03:00
|
|
|
|
private static bool _pendingCheckPasswordlessLoginRequests;
|
2022-10-31 18:57:09 +03:00
|
|
|
|
private static object _processingLoginRequestLock = new object();
|
2020-03-06 00:18:04 +03:00
|
|
|
|
|
2019-05-17 19:03:35 +03:00
|
|
|
|
public App(AppOptions appOptions)
|
2019-03-28 03:12:44 +03:00
|
|
|
|
{
|
2020-05-29 19:26:36 +03:00
|
|
|
|
Options = appOptions ?? new AppOptions();
|
2020-05-29 22:25:06 +03:00
|
|
|
|
if (Options.IosExtension)
|
2020-05-29 19:26:36 +03:00
|
|
|
|
{
|
|
|
|
|
Current = this;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-18 20:15:46 +03:00
|
|
|
|
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
|
|
|
|
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
2019-05-15 22:47:50 +03:00
|
|
|
|
_stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
2020-05-29 19:26:36 +03:00
|
|
|
|
_vaultTimeoutService = ServiceContainer.Resolve<IVaultTimeoutService>("vaultTimeoutService");
|
2019-05-16 00:37:59 +03:00
|
|
|
|
_syncService = ServiceContainer.Resolve<ISyncService>("syncService");
|
|
|
|
|
_authService = ServiceContainer.Resolve<IAuthService>("authService");
|
2019-05-17 19:03:35 +03:00
|
|
|
|
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
2022-10-12 00:19:32 +03:00
|
|
|
|
_fileService = ServiceContainer.Resolve<IFileService>();
|
2022-06-08 20:24:01 +03:00
|
|
|
|
_accountsManager = ServiceContainer.Resolve<IAccountsManager>("accountsManager");
|
2022-09-26 20:27:57 +03:00
|
|
|
|
_pushNotificationService = ServiceContainer.Resolve<IPushNotificationService>();
|
2022-06-08 20:24:01 +03:00
|
|
|
|
|
|
|
|
|
_accountsManager.Init(() => Options, this);
|
2019-03-30 00:54:03 +03:00
|
|
|
|
|
2019-05-29 22:50:20 +03:00
|
|
|
|
Bootstrap();
|
2019-04-19 19:29:37 +03:00
|
|
|
|
_broadcasterService.Subscribe(nameof(App), async (message) =>
|
2019-04-10 06:24:03 +03:00
|
|
|
|
{
|
2022-07-06 00:14:10 +03:00
|
|
|
|
try
|
2019-04-10 06:24:03 +03:00
|
|
|
|
{
|
2022-07-06 00:14:10 +03:00
|
|
|
|
if (message.Command == "showDialog")
|
2019-04-19 19:29:37 +03:00
|
|
|
|
{
|
2022-07-06 00:14:10 +03:00
|
|
|
|
var details = message.Data as DialogDetails;
|
|
|
|
|
var confirmed = true;
|
|
|
|
|
var confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ?
|
|
|
|
|
AppResources.Ok : details.ConfirmText;
|
|
|
|
|
Device.BeginInvokeOnMainThread(async () =>
|
2019-05-30 18:40:33 +03:00
|
|
|
|
{
|
2022-07-06 00:14:10 +03:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(details.CancelText))
|
|
|
|
|
{
|
|
|
|
|
confirmed = await Current.MainPage.DisplayAlert(details.Title, details.Text, confirmText,
|
|
|
|
|
details.CancelText);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await Current.MainPage.DisplayAlert(details.Title, details.Text, confirmText);
|
|
|
|
|
}
|
|
|
|
|
_messagingService.Send("showDialogResolve", new Tuple<int, bool>(details.DialogId, confirmed));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (message.Command == "resumed")
|
|
|
|
|
{
|
|
|
|
|
if (Device.RuntimePlatform == Device.iOS)
|
2019-05-30 18:40:33 +03:00
|
|
|
|
{
|
2022-07-06 00:14:10 +03:00
|
|
|
|
ResumedAsync().FireAndForget();
|
2019-05-30 18:40:33 +03:00
|
|
|
|
}
|
2022-07-06 00:14:10 +03:00
|
|
|
|
}
|
|
|
|
|
else if (message.Command == "slept")
|
2019-05-30 21:13:02 +03:00
|
|
|
|
{
|
2022-07-06 00:14:10 +03:00
|
|
|
|
if (Device.RuntimePlatform == Device.iOS)
|
|
|
|
|
{
|
|
|
|
|
await SleptAsync();
|
|
|
|
|
}
|
2019-05-30 21:13:02 +03:00
|
|
|
|
}
|
2022-07-06 00:14:10 +03:00
|
|
|
|
else if (message.Command == "migrated")
|
2019-07-14 03:25:31 +03:00
|
|
|
|
{
|
2022-07-06 00:14:10 +03:00
|
|
|
|
await Task.Delay(1000);
|
|
|
|
|
await _accountsManager.NavigateOnAccountChangeAsync();
|
2019-07-14 03:25:31 +03:00
|
|
|
|
}
|
2022-07-06 00:14:10 +03:00
|
|
|
|
else if (message.Command == "popAllAndGoToTabGenerator" ||
|
|
|
|
|
message.Command == "popAllAndGoToTabMyVault" ||
|
|
|
|
|
message.Command == "popAllAndGoToTabSend" ||
|
|
|
|
|
message.Command == "popAllAndGoToAutofillCiphers")
|
2019-06-05 23:37:54 +03:00
|
|
|
|
{
|
2022-07-06 00:14:10 +03:00
|
|
|
|
Device.BeginInvokeOnMainThread(async () =>
|
2019-06-05 23:37:54 +03:00
|
|
|
|
{
|
2022-07-06 00:14:10 +03:00
|
|
|
|
if (Current.MainPage is TabsPage tabsPage)
|
2019-06-05 23:37:54 +03:00
|
|
|
|
{
|
2022-07-06 00:14:10 +03:00
|
|
|
|
while (tabsPage.Navigation.ModalStack.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
await tabsPage.Navigation.PopModalAsync(false);
|
|
|
|
|
}
|
|
|
|
|
if (message.Command == "popAllAndGoToAutofillCiphers")
|
|
|
|
|
{
|
|
|
|
|
Current.MainPage = new NavigationPage(new AutofillCiphersPage(Options));
|
|
|
|
|
}
|
|
|
|
|
else if (message.Command == "popAllAndGoToTabMyVault")
|
|
|
|
|
{
|
|
|
|
|
Options.MyVaultTile = false;
|
|
|
|
|
tabsPage.ResetToVaultPage();
|
|
|
|
|
}
|
|
|
|
|
else if (message.Command == "popAllAndGoToTabGenerator")
|
|
|
|
|
{
|
|
|
|
|
Options.GeneratorTile = false;
|
|
|
|
|
tabsPage.ResetToGeneratorPage();
|
|
|
|
|
}
|
|
|
|
|
else if (message.Command == "popAllAndGoToTabSend")
|
|
|
|
|
{
|
|
|
|
|
tabsPage.ResetToSendPage();
|
|
|
|
|
}
|
2019-06-05 23:37:54 +03:00
|
|
|
|
}
|
2022-07-06 00:14:10 +03:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (message.Command == "convertAccountToKeyConnector")
|
|
|
|
|
{
|
|
|
|
|
Device.BeginInvokeOnMainThread(async () =>
|
|
|
|
|
{
|
|
|
|
|
await Application.Current.MainPage.Navigation.PushModalAsync(
|
|
|
|
|
new NavigationPage(new RemoveMasterPasswordPage()));
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-10-31 18:57:09 +03:00
|
|
|
|
else if (message.Command == Constants.PasswordlessLoginRequestKey || message.Command == "unlocked" || message.Command == AccountsManagerMessageCommands.ACCOUNT_SWITCH_COMPLETED)
|
2022-09-26 20:27:57 +03:00
|
|
|
|
{
|
2022-10-31 18:57:09 +03:00
|
|
|
|
lock (_processingLoginRequestLock)
|
|
|
|
|
{
|
|
|
|
|
// lock doesn't allow for async execution
|
|
|
|
|
CheckPasswordlessLoginRequestsAsync().Wait();
|
|
|
|
|
}
|
2022-09-26 20:27:57 +03:00
|
|
|
|
}
|
2019-06-05 23:37:54 +03:00
|
|
|
|
}
|
2022-07-06 00:14:10 +03:00
|
|
|
|
catch (Exception ex)
|
2021-11-11 04:46:48 +03:00
|
|
|
|
{
|
2022-07-06 00:14:10 +03:00
|
|
|
|
LoggerHelper.LogEvenIfCantBeResolved(ex);
|
2021-11-11 04:46:48 +03:00
|
|
|
|
}
|
2019-04-10 06:24:03 +03:00
|
|
|
|
});
|
2019-03-28 03:12:44 +03:00
|
|
|
|
}
|
2020-05-29 19:26:36 +03:00
|
|
|
|
|
2022-09-26 20:27:57 +03:00
|
|
|
|
private async Task CheckPasswordlessLoginRequestsAsync()
|
|
|
|
|
{
|
|
|
|
|
if (!_isResumed)
|
|
|
|
|
{
|
|
|
|
|
_pendingCheckPasswordlessLoginRequests = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_pendingCheckPasswordlessLoginRequests = false;
|
|
|
|
|
if (await _vaultTimeoutService.IsLockedAsync())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var notification = await _stateService.GetPasswordlessLoginNotificationAsync();
|
|
|
|
|
if (notification == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:21:45 +03:00
|
|
|
|
if (await CheckShouldSwitchActiveUserAsync(notification))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-26 20:27:57 +03:00
|
|
|
|
// Delay to wait for the vault page to appear
|
|
|
|
|
await Task.Delay(2000);
|
2022-10-31 18:57:09 +03:00
|
|
|
|
// if there is a request modal opened ignore all incoming requests
|
|
|
|
|
if (App.Current.MainPage.Navigation.ModalStack.Any(p => p is NavigationPage navPage && navPage.CurrentPage is LoginPasswordlessPage))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-09-26 20:27:57 +03:00
|
|
|
|
var loginRequestData = await _authService.GetPasswordlessLoginRequestByIdAsync(notification.Id);
|
|
|
|
|
var page = new LoginPasswordlessPage(new LoginPasswordlessDetails()
|
|
|
|
|
{
|
|
|
|
|
PubKey = loginRequestData.PublicKey,
|
|
|
|
|
Id = loginRequestData.Id,
|
|
|
|
|
IpAddress = loginRequestData.RequestIpAddress,
|
|
|
|
|
Email = await _stateService.GetEmailAsync(),
|
|
|
|
|
FingerprintPhrase = loginRequestData.RequestFingerprint,
|
|
|
|
|
RequestDate = loginRequestData.CreationDate,
|
|
|
|
|
DeviceType = loginRequestData.RequestDeviceType,
|
|
|
|
|
Origin = loginRequestData.Origin,
|
|
|
|
|
});
|
|
|
|
|
await _stateService.SetPasswordlessLoginNotificationAsync(null);
|
|
|
|
|
_pushNotificationService.DismissLocalNotification(Constants.PasswordlessNotificationId);
|
2022-10-12 17:55:38 +03:00
|
|
|
|
if (loginRequestData.CreationDate.ToUniversalTime().AddMinutes(Constants.PasswordlessNotificationTimeoutInMinutes) > DateTime.UtcNow)
|
2022-09-30 22:44:56 +03:00
|
|
|
|
{
|
|
|
|
|
await Device.InvokeOnMainThreadAsync(() => Application.Current.MainPage.Navigation.PushModalAsync(new NavigationPage(page)));
|
|
|
|
|
}
|
2022-09-26 20:27:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:21:45 +03:00
|
|
|
|
private async Task<bool> CheckShouldSwitchActiveUserAsync(PasswordlessRequestNotification notification)
|
|
|
|
|
{
|
|
|
|
|
var activeUserId = await _stateService.GetActiveUserIdAsync();
|
|
|
|
|
if (notification.UserId == activeUserId)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var notificationUserEmail = await _stateService.GetEmailAsync(notification.UserId);
|
2022-11-04 19:54:16 +03:00
|
|
|
|
Device.BeginInvokeOnMainThread(async () =>
|
2022-10-18 19:21:45 +03:00
|
|
|
|
{
|
2022-11-04 19:54:16 +03:00
|
|
|
|
try
|
2022-10-18 19:21:45 +03:00
|
|
|
|
{
|
2022-11-04 19:54:16 +03:00
|
|
|
|
var result = await _deviceActionService.DisplayAlertAsync(AppResources.LogInRequested, string.Format(AppResources.LoginAttemptFromXDoYouWantToSwitchToThisAccount, notificationUserEmail), AppResources.Cancel, AppResources.Ok);
|
|
|
|
|
if (result == AppResources.Ok)
|
|
|
|
|
{
|
|
|
|
|
await _stateService.SetActiveUserAsync(notification.UserId);
|
|
|
|
|
_messagingService.Send(AccountsManagerMessageCommands.SWITCHED_ACCOUNT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LoggerHelper.LogEvenIfCantBeResolved(ex);
|
2022-10-18 19:21:45 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 19:26:36 +03:00
|
|
|
|
public AppOptions Options { get; private set; }
|
|
|
|
|
|
2019-05-17 19:03:35 +03:00
|
|
|
|
protected async override void OnStart()
|
2019-03-28 03:12:44 +03:00
|
|
|
|
{
|
2019-05-16 19:30:20 +03:00
|
|
|
|
System.Diagnostics.Debug.WriteLine("XF App: OnStart");
|
2022-09-26 20:27:57 +03:00
|
|
|
|
_isResumed = true;
|
2019-05-17 19:03:35 +03:00
|
|
|
|
await ClearCacheIfNeededAsync();
|
2019-05-29 00:18:27 +03:00
|
|
|
|
Prime();
|
2020-05-29 19:26:36 +03:00
|
|
|
|
if (string.IsNullOrWhiteSpace(Options.Uri))
|
2019-05-30 21:13:02 +03:00
|
|
|
|
{
|
|
|
|
|
var updated = await AppHelpers.PerformUpdateTasksAsync(_syncService, _deviceActionService,
|
2022-02-23 20:40:17 +03:00
|
|
|
|
_stateService);
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (!updated)
|
2019-05-30 21:13:02 +03:00
|
|
|
|
{
|
|
|
|
|
SyncIfNeeded();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-26 20:27:57 +03:00
|
|
|
|
if (_pendingCheckPasswordlessLoginRequests)
|
|
|
|
|
{
|
2022-10-31 18:57:09 +03:00
|
|
|
|
_messagingService.Send(Constants.PasswordlessLoginRequestKey);
|
2022-09-26 20:27:57 +03:00
|
|
|
|
}
|
2021-06-29 17:23:20 +03:00
|
|
|
|
if (Device.RuntimePlatform == Device.Android)
|
|
|
|
|
{
|
|
|
|
|
await _vaultTimeoutService.CheckVaultTimeoutAsync();
|
2022-01-19 17:09:30 +03:00
|
|
|
|
// Reset delay on every start
|
|
|
|
|
_vaultTimeoutService.DelayLockAndLogoutMs = null;
|
2021-06-29 17:23:20 +03:00
|
|
|
|
}
|
2019-07-13 00:29:40 +03:00
|
|
|
|
_messagingService.Send("startEventTimer");
|
2019-03-28 03:12:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-16 19:30:20 +03:00
|
|
|
|
protected async override void OnSleep()
|
2019-03-28 03:12:44 +03:00
|
|
|
|
{
|
2019-05-16 19:30:20 +03:00
|
|
|
|
System.Diagnostics.Debug.WriteLine("XF App: OnSleep");
|
2020-03-06 00:18:04 +03:00
|
|
|
|
_isResumed = false;
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (Device.RuntimePlatform == Device.Android)
|
2019-05-31 03:24:30 +03:00
|
|
|
|
{
|
2020-05-29 19:26:36 +03:00
|
|
|
|
var isLocked = await _vaultTimeoutService.IsLockedAsync();
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (!isLocked)
|
2019-07-22 15:37:06 +03:00
|
|
|
|
{
|
2022-02-23 20:40:17 +03:00
|
|
|
|
await _stateService.SetLastActiveTimeAsync(_deviceActionService.GetActiveTime());
|
2019-07-22 15:37:06 +03:00
|
|
|
|
}
|
2022-04-20 03:38:17 +03:00
|
|
|
|
if (!SetTabsPageFromAutofill(isLocked))
|
|
|
|
|
{
|
|
|
|
|
ClearAutofillUri();
|
|
|
|
|
}
|
2019-07-14 03:25:31 +03:00
|
|
|
|
await SleptAsync();
|
2019-05-31 03:24:30 +03:00
|
|
|
|
}
|
2019-03-28 03:12:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-07 05:49:17 +03:00
|
|
|
|
protected override void OnResume()
|
2019-03-28 03:12:44 +03:00
|
|
|
|
{
|
2019-05-16 19:30:20 +03:00
|
|
|
|
System.Diagnostics.Debug.WriteLine("XF App: OnResume");
|
2020-03-06 00:18:04 +03:00
|
|
|
|
_isResumed = true;
|
2022-09-26 20:27:57 +03:00
|
|
|
|
if (_pendingCheckPasswordlessLoginRequests)
|
|
|
|
|
{
|
2022-10-31 18:57:09 +03:00
|
|
|
|
_messagingService.Send(Constants.PasswordlessLoginRequestKey);
|
2022-09-26 20:27:57 +03:00
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (Device.RuntimePlatform == Device.Android)
|
2019-05-30 21:13:02 +03:00
|
|
|
|
{
|
2022-02-14 19:29:04 +03:00
|
|
|
|
ResumedAsync().FireAndForget();
|
2019-05-30 21:13:02 +03:00
|
|
|
|
}
|
2019-06-25 00:02:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 03:25:31 +03:00
|
|
|
|
private async Task SleptAsync()
|
|
|
|
|
{
|
2022-01-19 17:09:30 +03:00
|
|
|
|
await _vaultTimeoutService.CheckVaultTimeoutAsync();
|
2019-07-14 03:25:31 +03:00
|
|
|
|
_messagingService.Send("stopEventTimer");
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-14 19:29:04 +03:00
|
|
|
|
private async Task ResumedAsync()
|
2019-06-25 00:02:05 +03:00
|
|
|
|
{
|
2022-06-15 19:44:25 +03:00
|
|
|
|
await _stateService.CheckExtensionActiveUserAndSwitchIfNeededAsync();
|
2020-12-14 23:29:30 +03:00
|
|
|
|
await _vaultTimeoutService.CheckVaultTimeoutAsync();
|
2019-07-13 00:29:40 +03:00
|
|
|
|
_messagingService.Send("startEventTimer");
|
2022-02-14 19:29:04 +03:00
|
|
|
|
await UpdateThemeAsync();
|
2019-06-25 00:02:05 +03:00
|
|
|
|
await ClearCacheIfNeededAsync();
|
|
|
|
|
Prime();
|
|
|
|
|
SyncIfNeeded();
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (Current.MainPage is NavigationPage navPage && navPage.CurrentPage is LockPage lockPage)
|
2019-06-06 15:04:54 +03:00
|
|
|
|
{
|
2020-06-08 15:25:13 +03:00
|
|
|
|
await lockPage.PromptBiometricAfterResumeAsync();
|
2019-06-06 15:04:54 +03:00
|
|
|
|
}
|
2019-03-28 03:12:44 +03:00
|
|
|
|
}
|
2019-04-11 22:33:10 +03:00
|
|
|
|
|
2022-01-24 23:20:48 +03:00
|
|
|
|
public async Task UpdateThemeAsync()
|
|
|
|
|
{
|
|
|
|
|
await Device.InvokeOnMainThreadAsync(() =>
|
|
|
|
|
{
|
2022-02-23 20:40:17 +03:00
|
|
|
|
ThemeManager.SetTheme(Current.Resources);
|
2022-01-24 23:20:48 +03:00
|
|
|
|
_messagingService.Send("updatedTheme");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 22:33:10 +03:00
|
|
|
|
private void SetCulture()
|
|
|
|
|
{
|
|
|
|
|
// Calendars are removed by linker. ref https://bugzilla.xamarin.com/show_bug.cgi?id=59077
|
|
|
|
|
new System.Globalization.ThaiBuddhistCalendar();
|
|
|
|
|
new System.Globalization.HijriCalendar();
|
|
|
|
|
new System.Globalization.UmAlQuraCalendar();
|
|
|
|
|
}
|
2019-04-19 23:40:20 +03:00
|
|
|
|
|
2019-05-17 19:03:35 +03:00
|
|
|
|
private async Task ClearCacheIfNeededAsync()
|
|
|
|
|
{
|
2022-02-23 20:40:17 +03:00
|
|
|
|
var lastClear = await _stateService.GetLastFileCacheClearAsync();
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if ((DateTime.UtcNow - lastClear.GetValueOrDefault(DateTime.MinValue)).TotalDays >= 1)
|
2019-05-17 19:03:35 +03:00
|
|
|
|
{
|
2022-10-12 00:19:32 +03:00
|
|
|
|
var task = Task.Run(() => _fileService.ClearCacheAsync());
|
2019-05-17 19:03:35 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-20 03:38:17 +03:00
|
|
|
|
private void ClearAutofillUri()
|
|
|
|
|
{
|
|
|
|
|
if (Device.RuntimePlatform == Device.Android && !string.IsNullOrWhiteSpace(Options.Uri))
|
|
|
|
|
{
|
|
|
|
|
Options.Uri = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SetTabsPageFromAutofill(bool isLocked)
|
2019-05-17 19:03:35 +03:00
|
|
|
|
{
|
2020-05-29 19:26:36 +03:00
|
|
|
|
if (Device.RuntimePlatform == Device.Android && !string.IsNullOrWhiteSpace(Options.Uri) &&
|
|
|
|
|
!Options.FromAutofillFramework)
|
2019-05-17 19:03:35 +03:00
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
|
|
|
{
|
2020-05-29 19:26:36 +03:00
|
|
|
|
Options.Uri = null;
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (isLocked)
|
2019-07-22 15:37:06 +03:00
|
|
|
|
{
|
|
|
|
|
Current.MainPage = new NavigationPage(new LockPage());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Current.MainPage = new TabsPage();
|
|
|
|
|
}
|
2019-05-17 19:03:35 +03:00
|
|
|
|
});
|
|
|
|
|
});
|
2022-04-20 03:38:17 +03:00
|
|
|
|
return true;
|
2019-05-17 19:03:35 +03:00
|
|
|
|
}
|
2022-04-20 03:38:17 +03:00
|
|
|
|
return false;
|
2019-05-17 19:03:35 +03:00
|
|
|
|
}
|
2019-05-29 00:18:27 +03:00
|
|
|
|
|
|
|
|
|
private void Prime()
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
var word = EEFLongWordList.Instance.List[1];
|
|
|
|
|
var parsedDomain = DomainName.TryParse("https://bitwarden.com", out var domainName);
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-05-29 22:50:20 +03:00
|
|
|
|
|
|
|
|
|
private void Bootstrap()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
SetCulture();
|
2022-02-23 20:40:17 +03:00
|
|
|
|
ThemeManager.SetTheme(Current.Resources);
|
2021-10-08 15:47:40 +03:00
|
|
|
|
Current.RequestedThemeChanged += (s, a) =>
|
|
|
|
|
{
|
2022-01-24 23:20:48 +03:00
|
|
|
|
UpdateThemeAsync();
|
2021-10-08 15:47:40 +03:00
|
|
|
|
};
|
2022-02-23 20:40:17 +03:00
|
|
|
|
Current.MainPage = new NavigationPage(new HomePage(Options));
|
2022-07-15 01:17:04 +03:00
|
|
|
|
_accountsManager.NavigateOnAccountChangeAsync().FireAndForget();
|
2019-05-29 22:50:20 +03:00
|
|
|
|
ServiceContainer.Resolve<MobilePlatformUtilsService>("platformUtilsService").Init();
|
|
|
|
|
}
|
2019-05-30 21:13:02 +03:00
|
|
|
|
|
|
|
|
|
private void SyncIfNeeded()
|
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
|
2019-06-04 06:12:54 +03:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-05-30 21:13:02 +03:00
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
var lastSync = await _syncService.GetLastSyncAsync();
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (lastSync == null || ((DateTime.UtcNow - lastSync) > TimeSpan.FromMinutes(30)))
|
2019-05-30 21:13:02 +03:00
|
|
|
|
{
|
2019-08-12 16:35:18 +03:00
|
|
|
|
await Task.Delay(1000);
|
2019-05-30 21:13:02 +03:00
|
|
|
|
await _syncService.FullSyncAsync(false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-07-07 05:49:17 +03:00
|
|
|
|
|
2022-06-08 20:24:01 +03:00
|
|
|
|
public async Task SetPreviousPageInfoAsync()
|
2019-07-31 23:50:16 +03:00
|
|
|
|
{
|
|
|
|
|
PreviousPageInfo lastPageBeforeLock = null;
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (Current.MainPage is TabbedPage tabbedPage && tabbedPage.Navigation.ModalStack.Count > 0)
|
2019-07-31 23:50:16 +03:00
|
|
|
|
{
|
|
|
|
|
var topPage = tabbedPage.Navigation.ModalStack[tabbedPage.Navigation.ModalStack.Count - 1];
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (topPage is NavigationPage navPage)
|
2019-07-31 23:50:16 +03:00
|
|
|
|
{
|
2022-07-27 19:46:56 +03:00
|
|
|
|
if (navPage.CurrentPage is CipherDetailsPage cipherDetailsPage)
|
2019-07-31 23:50:16 +03:00
|
|
|
|
{
|
|
|
|
|
lastPageBeforeLock = new PreviousPageInfo
|
|
|
|
|
{
|
|
|
|
|
Page = "view",
|
2022-07-27 19:46:56 +03:00
|
|
|
|
CipherId = cipherDetailsPage.ViewModel.CipherId
|
2019-07-31 23:50:16 +03:00
|
|
|
|
};
|
|
|
|
|
}
|
2022-07-27 19:46:56 +03:00
|
|
|
|
else if (navPage.CurrentPage is CipherAddEditPage cipherAddEditPage && cipherAddEditPage.ViewModel.EditMode)
|
2019-07-31 23:50:16 +03:00
|
|
|
|
{
|
|
|
|
|
lastPageBeforeLock = new PreviousPageInfo
|
|
|
|
|
{
|
|
|
|
|
Page = "edit",
|
2022-07-27 19:46:56 +03:00
|
|
|
|
CipherId = cipherAddEditPage.ViewModel.CipherId
|
2019-07-31 23:50:16 +03:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-23 20:40:17 +03:00
|
|
|
|
await _stateService.SetPreviousPageInfoAsync(lastPageBeforeLock);
|
2022-06-08 20:24:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Navigate(NavigationTarget navTarget, INavigationParams navParams)
|
|
|
|
|
{
|
|
|
|
|
switch (navTarget)
|
|
|
|
|
{
|
|
|
|
|
case NavigationTarget.HomeLogin:
|
|
|
|
|
Current.MainPage = new NavigationPage(new HomePage(Options));
|
|
|
|
|
break;
|
|
|
|
|
case NavigationTarget.Login:
|
|
|
|
|
if (navParams is LoginNavigationParams loginParams)
|
|
|
|
|
{
|
|
|
|
|
Current.MainPage = new NavigationPage(new LoginPage(loginParams.Email, Options));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NavigationTarget.Lock:
|
|
|
|
|
if (navParams is LockNavigationParams lockParams)
|
|
|
|
|
{
|
|
|
|
|
Current.MainPage = new NavigationPage(new LockPage(Options, lockParams.AutoPromptBiometric));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Current.MainPage = new NavigationPage(new LockPage(Options));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NavigationTarget.Home:
|
|
|
|
|
Current.MainPage = new TabsPage(Options);
|
|
|
|
|
break;
|
|
|
|
|
case NavigationTarget.AddEditCipher:
|
2022-07-27 19:46:56 +03:00
|
|
|
|
Current.MainPage = new NavigationPage(new CipherAddEditPage(appOptions: Options));
|
2022-06-08 20:24:01 +03:00
|
|
|
|
break;
|
|
|
|
|
case NavigationTarget.AutofillCiphers:
|
|
|
|
|
Current.MainPage = new NavigationPage(new AutofillCiphersPage(Options));
|
|
|
|
|
break;
|
|
|
|
|
case NavigationTarget.SendAddEdit:
|
|
|
|
|
Current.MainPage = new NavigationPage(new SendAddEditPage(Options));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-07-31 23:50:16 +03:00
|
|
|
|
}
|
2019-03-28 03:12:44 +03:00
|
|
|
|
}
|
|
|
|
|
}
|