LANCommander/LANCommander.Server/UI/Pages/Settings/Integrations/Steam.razor

114 lines
3.6 KiB
Text

@page "/Settings/Integrations/Steam"
@using LANCommander.Server.Services.Enums
@using LANCommander.Server.UI.Pages.Settings.Components
@inject SteamCMDService SteamCmdService
@inject IMessageService MessageService
@inject ILogger<Beacon> Logger
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
<PageHeader Title="Steam">
<PageHeaderExtra>
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
</PageHeaderExtra>
</PageHeader>
<PageContent>
<Form Model="_settings" Layout="@FormLayout.Vertical">
<FormItem Label="SteamCMD Path">
<FilePicker @bind-Value="_settings.SteamCMD.Path" Title="Choose SteamCMD Executable Path" Root="@_rootPath" />
</FormItem>
</Form>
<h2>Profiles</h2>
<Flex Direction="FlexDirection.Vertical" Gap="FlexGap.Large">
<Collapse>
@foreach (var profile in _settings.SteamCMD.Profiles)
{
<Panel Header="@(String.IsNullOrWhiteSpace(profile.Username) ? "New Profile" : profile.Username)">
<ExtraTemplate>
<Flex Gap="FlexGap.Small">
<Button Type="ButtonType.Text" Icon="@IconType.Outline.Close" Size="ButtonSize.Small" Danger OnClick="() => RemoveProfile(profile)"/>
</Flex>
</ExtraTemplate>
<ChildContent>
<SteamProfileEditor
@bind-Username="profile.Username"
@bind-InstallDirectory="profile.InstallDirectory"
OnAuthenticated="Save"/>
</ChildContent>
</Panel>
}
</Collapse>
<Flex Justify="FlexJustify.End">
<Button OnClick="AddProfile">Add Profile</Button>
</Flex>
</Flex>
</PageContent>
@code {
Settings _settings = SettingService.GetSettings();
string _rootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
SteamCmdConnectionStatus _connectionStatus;
string _username;
string _password;
bool _processingLogin;
protected override async Task OnInitializedAsync()
{
if (!_settings.SteamCMD.Profiles.Any())
AddProfile();
}
void AddProfile()
{
_settings.SteamCMD.Profiles.Add(new SteamCmdProfile());
}
async Task RemoveProfile(SteamCmdProfile profile)
{
_settings.SteamCMD.Profiles.Remove(profile);
if (!String.IsNullOrWhiteSpace(profile.Username))
{
var logoutMessage = new MessageConfig
{
Content = "Logging out of Steam...",
Duration = 0,
Key = Guid.NewGuid().ToString()
};
MessageService.Loading(logoutMessage);
await SteamCmdService.LogoutAsync(profile.Username);
logoutMessage.Content = "Successfully logged out from Steam!";
logoutMessage.Duration = 3;
MessageService.Success(logoutMessage);
}
if (!_settings.SteamCMD.Profiles.Any())
AddProfile();
}
async Task Save()
{
try
{
_settings.SteamCMD.Profiles = _settings.SteamCMD.Profiles.Where(p => !String.IsNullOrWhiteSpace(p.Username)).ToList();
SettingService.SaveSettings(_settings);
MessageService.Success("Settings saved!");
}
catch (Exception ex)
{
MessageService.Error("An unknown error occurred.");
Logger.LogError(ex, "An unknown error occurred.");
}
}
}