122 lines
No EOL
3.6 KiB
Text
122 lines
No EOL
3.6 KiB
Text
@using LANCommander.Launcher.Data.Models
|
|
@using LANCommander.Launcher.Models
|
|
@using LANCommander.Launcher.Settings
|
|
@using LANCommander.SDK.Services
|
|
@inject UserService UserService
|
|
@inject ProfileService ProfileService
|
|
@inject AuthenticationService AuthenticationService
|
|
@inject NavigationManager NavigationManager
|
|
@inject ModalService ModalService
|
|
@inject LocalizationService LocalizationService
|
|
@inject SDK.Client Client
|
|
@inject IConnectionClient ConnectionClient
|
|
@inject ILogger<ProfileButton> Logger
|
|
|
|
<Dropdown>
|
|
<Overlay>
|
|
<Menu>
|
|
<MenuItem OnClick="ChangeAlias" Disabled="@ConnectionClient.IsOfflineMode()">
|
|
@LocalizationService.GetString("ChangeName")
|
|
</MenuItem>
|
|
<MenuItem OnClick="@(() => NavigationManager.NavigateTo("/Settings"))">
|
|
@LocalizationService.GetString("Settings")
|
|
</MenuItem>
|
|
|
|
@if (!Client.Settings.CurrentValue.Authentication.OfflineModeEnabled)
|
|
{
|
|
<MenuItem OnClick="SwitchToOfflineMode">
|
|
@LocalizationService.GetString("SwitchToOfflineMode")
|
|
</MenuItem>
|
|
}
|
|
|
|
<MenuItem OnClick="Logout">
|
|
@LocalizationService.GetString("Logout")
|
|
</MenuItem>
|
|
</Menu>
|
|
</Overlay>
|
|
|
|
<ChildContent>
|
|
<Button Type="ButtonType.Primary" Class="appbar-profile-button">
|
|
@if (AvatarId != Guid.Empty)
|
|
{
|
|
<MediaImage Id="AvatarId" />
|
|
}
|
|
|
|
<span>@Alias</span>
|
|
</Button>
|
|
</ChildContent>
|
|
</Dropdown>
|
|
|
|
@code {
|
|
User User;
|
|
Guid AvatarId = Guid.Empty;
|
|
string Alias = Settings.DEFAULT_GAME_USERNAME;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Console.WriteLine(NavigationManager.Uri);
|
|
Console.WriteLine(NavigationManager.BaseUri);
|
|
|
|
ProfileService.OnProfileDownloaded += async (sender, args) =>
|
|
{
|
|
User = await UserService.GetCurrentUser();
|
|
|
|
AvatarId = User?.Avatar?.Id ?? Guid.Empty;
|
|
Alias = String.IsNullOrWhiteSpace(User?.Alias) ? User?.UserName ?? Settings.DEFAULT_GAME_USERNAME : User.Alias;
|
|
};
|
|
|
|
if (ConnectionClient.IsOfflineMode())
|
|
{
|
|
string userName = AuthenticationService.GetCurrentUserName();
|
|
Alias = string.IsNullOrEmpty(userName) ? Alias : userName;
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
await ProfileService.DownloadProfileInfoAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogError(ex, "Could not download profile info");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
async Task ChangeAlias()
|
|
{
|
|
var modalOptions = new ModalOptions()
|
|
{
|
|
Title = LocalizationService.GetString("ChangeName"),
|
|
Maximizable = false,
|
|
DefaultMaximized = false,
|
|
Closable = true,
|
|
Centered = true
|
|
};
|
|
|
|
var modalRef = ModalService.CreateModal<ChangeAliasDialog, string, string>(modalOptions, User.Alias);
|
|
|
|
modalRef.OnOk = async (newName) =>
|
|
{
|
|
await ProfileService.ChangeAlias(newName);
|
|
await ProfileService.DownloadProfileInfoAsync();
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
};
|
|
}
|
|
|
|
async Task Logout()
|
|
{
|
|
await AuthenticationService.Logout();
|
|
|
|
NavigationManager.NavigateTo("/Authenticate");
|
|
}
|
|
|
|
async Task SwitchToOfflineMode()
|
|
{
|
|
await AuthenticationService.SetOfflineModeAsync(true);
|
|
|
|
NavigationManager.NavigateTo("/", forceLoad: true);
|
|
}
|
|
} |