Add ManagePandocDependency component

This commit is contained in:
Thorsten Sommer 2025-05-30 18:32:18 +02:00
parent f16594f7eb
commit ebc8c2b12a
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,10 @@
@inherits MSGComponentBase
<MudStack Row="false" Class="mb-3 pa-3 border-dashed border rounded-lg">
<MudJustifiedText Typo="Typo.body1">
@this.DetermineIntroText()
</MudJustifiedText>
<MudButton Color="Color.Default" Variant="Variant.Filled" OnClick="() => this.ShowPandocDialogAsync()">
@this.DetermineButtonText()
</MudButton>
</MudStack>

View File

@ -0,0 +1,79 @@
using AIStudio.Dialogs;
using AIStudio.Tools.Services;
using Microsoft.AspNetCore.Components;
using DialogOptions = AIStudio.Dialogs.DialogOptions;
namespace AIStudio.Components;
public partial class ManagePandocDependency : MSGComponentBase
{
[Parameter]
public string IntroText { get; set; } = string.Empty;
[Inject]
private IDialogService DialogService { get; init; } = null!;
[Inject]
private RustService RustService { get; init; } = null!;
private PandocInstallation pandocInstallation;
#region Overrides of MSGComponentBase
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
this.pandocInstallation = await Pandoc.CheckAvailabilityAsync(this.RustService, false);
}
#endregion
private string DetermineButtonText()
{
if(this.pandocInstallation == default)
return T("Please wait while we check the availability of Pandoc.");
switch (this.pandocInstallation)
{
case { CheckWasSuccessful: true, IsAvailable: true }:
return T("Check your Pandoc installation");
case { CheckWasSuccessful: true, IsAvailable: false }:
return T("Update Pandoc");
case { CheckWasSuccessful: false }:
return T("Install Pandoc");
}
}
private string DetermineIntroText()
{
if (this.pandocInstallation == default)
return $"{this.IntroText} {T("Please wait while we check the availability of Pandoc.")}";
switch (this.pandocInstallation)
{
case { CheckWasSuccessful: true, IsAvailable: true }:
return $"{this.IntroText} {T("Your Pandoc installation meets the requirements.")}";
case { CheckWasSuccessful: true, IsAvailable: false }:
return $"{this.IntroText} {T("Your Pandoc installation is outdated. Please update it to the latest version to ensure compatibility with all features.")}";
case { CheckWasSuccessful: false }:
return $"{this.IntroText} {T("Pandoc is not installed or not available. Please install it to use the features that require Pandoc.")}";
}
}
private async Task ShowPandocDialogAsync()
{
var dialogReference = await this.DialogService.ShowAsync<PandocDialog>(T("Pandoc Installation"), DialogOptions.FULLSCREEN);
await dialogReference.Result;
// Refresh the availability of Pandoc after the dialog is closed:
this.pandocInstallation = await Pandoc.CheckAvailabilityAsync(this.RustService, false);
await this.InvokeAsync(this.StateHasChanged);
}
}