mirror of
https://github.com/bitwarden/mobile
synced 2026-01-04 17:43:17 +00:00
update tasks and sync on app start
This commit is contained in:
@@ -28,5 +28,8 @@ namespace Bit.App.Abstractions
|
||||
void Autofill(CipherView cipher);
|
||||
void CloseAutofill();
|
||||
void Background();
|
||||
bool AutofillAccessibilityServiceRunning();
|
||||
bool AutofillServiceEnabled();
|
||||
string GetBuildNumber();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,13 @@ namespace Bit.App
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
else if(message.Command == "resumed")
|
||||
{
|
||||
if(Device.RuntimePlatform == Device.iOS)
|
||||
{
|
||||
SyncIfNeeded();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -114,6 +121,15 @@ namespace Bit.App
|
||||
System.Diagnostics.Debug.WriteLine("XF App: OnStart");
|
||||
await ClearCacheIfNeededAsync();
|
||||
Prime();
|
||||
if(string.IsNullOrWhiteSpace(_appOptions.Uri))
|
||||
{
|
||||
var updated = await AppHelpers.PerformUpdateTasksAsync(_syncService, _deviceActionService,
|
||||
_storageService);
|
||||
if(!updated)
|
||||
{
|
||||
SyncIfNeeded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected async override void OnSleep()
|
||||
@@ -129,6 +145,10 @@ namespace Bit.App
|
||||
_messagingService.Send("cancelLockTimer");
|
||||
await ClearCacheIfNeededAsync();
|
||||
Prime();
|
||||
if(Device.RuntimePlatform == Device.Android)
|
||||
{
|
||||
SyncIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCulture()
|
||||
@@ -264,5 +284,17 @@ namespace Bit.App
|
||||
var mainPageTask = SetMainPageAsync();
|
||||
ServiceContainer.Resolve<MobilePlatformUtilsService>("platformUtilsService").Init();
|
||||
}
|
||||
|
||||
private void SyncIfNeeded()
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var lastSync = await _syncService.GetLastSyncAsync();
|
||||
if(DateTime.UtcNow - lastSync > TimeSpan.FromMinutes(30))
|
||||
{
|
||||
await _syncService.FullSyncAsync(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@ namespace Bit.App.Services
|
||||
Constants.AccessibilityAutofillPersistNotificationKey,
|
||||
Constants.LastActiveKey,
|
||||
Constants.PushInitialPromptShownKey,
|
||||
Constants.LastFileCacheClearKey
|
||||
Constants.LastFileCacheClearKey,
|
||||
Constants.LastBuildKey
|
||||
};
|
||||
|
||||
public MobileStorageService(
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Bit.App.Pages;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Pages;
|
||||
using Bit.App.Resources;
|
||||
using Bit.Core;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Models.View;
|
||||
using Bit.Core.Utilities;
|
||||
@@ -108,5 +110,28 @@ namespace Bit.App.Utilities
|
||||
}
|
||||
return selection;
|
||||
}
|
||||
|
||||
public static async Task<bool> PerformUpdateTasksAsync(ISyncService syncService,
|
||||
IDeviceActionService deviceActionService, IStorageService storageService)
|
||||
{
|
||||
var lastSync = await syncService.GetLastSyncAsync();
|
||||
var currentBuild = deviceActionService.GetBuildNumber();
|
||||
var lastBuild = await storageService.GetAsync<string>(Constants.LastBuildKey);
|
||||
if(lastBuild == null)
|
||||
{
|
||||
// Installed
|
||||
}
|
||||
else if(lastBuild != currentBuild)
|
||||
{
|
||||
// Updated
|
||||
var tasks = Task.Run(() => syncService.FullSyncAsync(true));
|
||||
}
|
||||
if(lastBuild != currentBuild)
|
||||
{
|
||||
await storageService.SaveAsync(Constants.LastBuildKey, currentBuild);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user