bitwarden-mobile/src/App/Pages/Accounts/EnvironmentPageViewModel.cs

62 lines
2.1 KiB
C#
Raw Normal View History

2022-04-26 17:21:17 +02:00
using System;
using System.Threading.Tasks;
using Bit.App.Resources;
2019-05-02 18:20:56 +02:00
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
2019-05-31 18:13:14 +02:00
using Xamarin.Forms;
2019-05-02 18:20:56 +02:00
namespace Bit.App.Pages
{
public class EnvironmentPageViewModel : BaseViewModel
{
private readonly IEnvironmentService _environmentService;
public EnvironmentPageViewModel()
{
_environmentService = ServiceContainer.Resolve<IEnvironmentService>("environmentService");
PageTitle = AppResources.Settings;
BaseUrl = _environmentService.BaseUrl;
WebVaultUrl = _environmentService.WebVaultUrl;
ApiUrl = _environmentService.ApiUrl;
IdentityUrl = _environmentService.IdentityUrl;
IconsUrl = _environmentService.IconsUrl;
NotificationsUrls = _environmentService.NotificationsUrl;
2019-05-31 18:13:14 +02:00
SubmitCommand = new Command(async () => await SubmitAsync());
2019-05-02 18:20:56 +02:00
}
2019-05-31 18:13:14 +02:00
public Command SubmitCommand { get; }
2019-05-02 18:20:56 +02:00
public string BaseUrl { get; set; }
public string ApiUrl { get; set; }
public string IdentityUrl { get; set; }
public string WebVaultUrl { get; set; }
public string IconsUrl { get; set; }
public string NotificationsUrls { get; set; }
public Action SubmitSuccessAction { get; set; }
public Action CloseAction { get; set; }
2019-05-02 18:20:56 +02:00
public async Task SubmitAsync()
{
var resUrls = await _environmentService.SetUrlsAsync(new Core.Models.Data.EnvironmentUrlData
{
Base = BaseUrl,
Api = ApiUrl,
Identity = IdentityUrl,
WebVault = WebVaultUrl,
Icons = IconsUrl,
Notifications = NotificationsUrls
});
// re-set urls since service can change them, ex: prefixing https://
BaseUrl = resUrls.Base;
WebVaultUrl = resUrls.WebVault;
ApiUrl = resUrls.Api;
IdentityUrl = resUrls.Identity;
IconsUrl = resUrls.Icons;
NotificationsUrls = resUrls.Notifications;
SubmitSuccessAction?.Invoke();
2019-05-02 18:20:56 +02:00
}
}
}