mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 23:25:45 +03:00
Workaround for older bug in Xamarin.Forms by waiting for app to resume before attempting to set Application.Current.MainPage (#757)
This commit is contained in:
parent
b65b01fe3d
commit
6ffb3136d4
2 changed files with 26 additions and 0 deletions
|
@ -39,6 +39,8 @@ namespace Bit.App
|
|||
private readonly IDeviceActionService _deviceActionService;
|
||||
private readonly AppOptions _appOptions;
|
||||
|
||||
private static bool _isResumed;
|
||||
|
||||
public App(AppOptions appOptions)
|
||||
{
|
||||
_appOptions = appOptions ?? new AppOptions();
|
||||
|
@ -150,6 +152,27 @@ namespace Bit.App
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Workaround for https://github.com/xamarin/Xamarin.Forms/issues/7478
|
||||
// Fixed in last Xamarin.Forms 4.4.0.x - remove this hack after updating
|
||||
public static void WaitForResume()
|
||||
{
|
||||
var checkFrequencyInMillis = 100;
|
||||
var maxTimeInMillis = 5000;
|
||||
|
||||
var count = 0;
|
||||
while(!_isResumed)
|
||||
{
|
||||
Task.Delay(checkFrequencyInMillis).Wait();
|
||||
count += checkFrequencyInMillis;
|
||||
|
||||
// don't let this run forever
|
||||
if(count >= maxTimeInMillis)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected async override void OnStart()
|
||||
{
|
||||
|
@ -172,6 +195,7 @@ namespace Bit.App
|
|||
protected async override void OnSleep()
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("XF App: OnSleep");
|
||||
_isResumed = false;
|
||||
if(Device.RuntimePlatform == Device.Android)
|
||||
{
|
||||
var isLocked = await _lockService.IsLockedAsync();
|
||||
|
@ -187,6 +211,7 @@ namespace Bit.App
|
|||
protected override void OnResume()
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("XF App: OnResume");
|
||||
_isResumed = true;
|
||||
if(Device.RuntimePlatform == Device.Android)
|
||||
{
|
||||
ResumedAsync();
|
||||
|
|
|
@ -141,6 +141,7 @@ namespace Bit.App.Pages
|
|||
page.DuoWebView.RegisterAction(sig =>
|
||||
{
|
||||
Token = sig;
|
||||
App.WaitForResume();
|
||||
Device.BeginInvokeOnMainThread(async () => await SubmitAsync());
|
||||
});
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue