LANCommander/LANCommander.Server/UI/Pages/Settings/Launcher.razor

55 lines
1.7 KiB
Text

@page "/Settings/Launcher"
@using LANCommander.Server.Models;
@using Octokit
@using Semver
@inject IMessageService MessageService
@inject ILogger<Updates> Logger
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
<PageHeader Title="Launcher" />
<div style="padding: 0 24px;">
<Form Model="Settings" Layout="@FormLayout.Vertical">
<FormItem Label="Storage Path">
<FilePicker Root="@RootPath" EntrySelectable="x => x is FileManagerDirectory" @bind-Value="@context.Launcher.StoragePath" OkText="Select Path" Title="Choose Path" OnSelected="OnPathSelected" />
</FormItem>
<FormItem Label="Host Client Updates">
<Switch @bind-Checked="context.Launcher.HostUpdates" />
</FormItem>
<FormItem>
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
</FormItem>
</Form>
</div>
@code {
Settings Settings = SettingService.GetSettings();
string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
void Save()
{
try
{
SettingService.SaveSettings(Settings);
MessageService.Success("Settings saved!");
}
catch (Exception ex)
{
MessageService.Error("An unknown error occurred.");
Logger.LogError(ex, "An unknown error occurred.");
}
}
void OnPathSelected(string path)
{
var appPath = Directory.GetCurrentDirectory();
if (path != null && path.StartsWith(appPath))
path = path.Substring(appPath.Length).TrimStart(Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar);
Settings.Launcher.StoragePath = path;
}
}