diff --git a/src/Android/MainApplication.cs b/src/Android/MainApplication.cs index cfec9fc2f..a25d66a5e 100644 --- a/src/Android/MainApplication.cs +++ b/src/Android/MainApplication.cs @@ -31,7 +31,11 @@ namespace Bit.Droid { RegisterLocalServices(); ServiceContainer.Init(); - var task = App.Migration.MigrationHelpers.PerformMigrationAsync(); + if(App.Migration.MigrationHelpers.NeedsMigration()) + { + var task = App.Migration.MigrationHelpers.PerformMigrationAsync(); + Task.Delay(2000).Wait(); + } } } diff --git a/src/App/App.xaml.cs b/src/App/App.xaml.cs index 3905c3313..e6f2e0b85 100644 --- a/src/App/App.xaml.cs +++ b/src/App/App.xaml.cs @@ -99,6 +99,10 @@ namespace Bit.App } else if(message.Command == "logout") { + if(Migration.MigrationHelpers.Migrating) + { + return; + } await LogOutAsync(false); } else if(message.Command == "loggedOut") @@ -117,6 +121,11 @@ namespace Bit.App SyncIfNeeded(); } } + else if(message.Command == "migrated") + { + await Task.Delay(1000); + await SetMainPageAsync(); + } }); } @@ -295,6 +304,10 @@ namespace Bit.App private void SyncIfNeeded() { + if(Migration.MigrationHelpers.Migrating) + { + return; + } Task.Run(async () => { var lastSync = await _syncService.GetLastSyncAsync(); diff --git a/src/App/Migration/MigrationHelpers.cs b/src/App/Migration/MigrationHelpers.cs index 55ba2a48f..52e6f0737 100644 --- a/src/App/Migration/MigrationHelpers.cs +++ b/src/App/Migration/MigrationHelpers.cs @@ -5,12 +5,13 @@ using Bit.Core.Utilities; using System; using System.Text; using System.Threading.Tasks; -using Xamarin.Forms; namespace Bit.App.Migration { public static class MigrationHelpers { + public static bool Migrating = false; + public static bool NeedsMigration() { return ServiceContainer.Resolve("settingsShim") @@ -24,10 +25,12 @@ namespace Bit.App.Migration return false; } + Migrating = true; var settingsShim = ServiceContainer.Resolve("settingsShim"); var oldSecureStorageService = ServiceContainer.Resolve( "oldSecureStorageService"); + var messagingService = ServiceContainer.Resolve("messagingService"); var storageService = ServiceContainer.Resolve("storageService"); var secureStorageService = ServiceContainer.Resolve("secureStorageService"); var cryptoService = ServiceContainer.Resolve("cryptoService"); @@ -159,6 +162,8 @@ namespace Bit.App.Migration // Remove "needs migration" flag settingsShim.Remove(Constants.OldUserIdKey); + Migrating = false; + messagingService.Send("migrated"); return true; } }