mirror of
https://github.com/bitwarden/android.git
synced 2026-07-29 01:35:15 -05:00
59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using Bit.App.Abstractions;
|
|
using Plugin.Settings.Abstractions;
|
|
using System;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Bit.App.Utilities
|
|
{
|
|
public static class Helpers
|
|
{
|
|
public static readonly DateTime Epoc = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
public static long EpocUtcNow()
|
|
{
|
|
return (long)(DateTime.UtcNow - Epoc).TotalMilliseconds;
|
|
}
|
|
|
|
public static T OnPlatform<T>(T iOS = default(T), T Android = default(T),
|
|
T WinPhone = default(T), T Windows = default(T))
|
|
{
|
|
switch(Device.RuntimePlatform)
|
|
{
|
|
case Device.iOS:
|
|
return iOS;
|
|
case Device.Android:
|
|
return Android;
|
|
case Device.WinPhone:
|
|
return WinPhone;
|
|
case Device.Windows:
|
|
return Windows;
|
|
default:
|
|
throw new Exception("Unsupported platform.");
|
|
}
|
|
}
|
|
|
|
public static bool InDebugMode()
|
|
{
|
|
#if DEBUG
|
|
return true;
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
public static bool PerformUpdateTasks(ISettings settings, IAppInfoService appInfoService,
|
|
IDatabaseService databaseService)
|
|
{
|
|
var lastBuild = settings.GetValueOrDefault(Constants.LastBuildKey, null);
|
|
if(InDebugMode() || lastBuild == null || lastBuild != appInfoService.Build)
|
|
{
|
|
settings.AddOrUpdateValue(Constants.LastBuildKey, appInfoService.Build);
|
|
databaseService.CreateTables();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|