From 4f8dfc51c2f2f81938ecba855736efda5011cde2 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Thu, 29 May 2025 17:09:49 +0200 Subject: [PATCH] Add Pandoc version and installation support --- app/MindWork AI Studio/Pages/About.razor | 22 ++++++++++-- app/MindWork AI Studio/Pages/About.razor.cs | 40 +++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/app/MindWork AI Studio/Pages/About.razor b/app/MindWork AI Studio/Pages/About.razor index 0f5329d0..4ee3778f 100644 --- a/app/MindWork AI Studio/Pages/About.razor +++ b/app/MindWork AI Studio/Pages/About.razor @@ -19,13 +19,29 @@ + - - @T("Check for updates") - + + + @T("Check for updates") + + @if (this.pandocInstallation != default && !this.pandocInstallation.IsAvailable) + { + + @if (string.IsNullOrWhiteSpace(this.pandocInstallation.Version)) + { + @T("Install Pandoc") + } + else + { + @T("Update Pandoc") + } + + } + diff --git a/app/MindWork AI Studio/Pages/About.razor.cs b/app/MindWork AI Studio/Pages/About.razor.cs index 66657077..3b9d5727 100644 --- a/app/MindWork AI Studio/Pages/About.razor.cs +++ b/app/MindWork AI Studio/Pages/About.razor.cs @@ -1,6 +1,7 @@ using System.Reflection; using AIStudio.Components; +using AIStudio.Dialogs; using AIStudio.Tools.Metadata; using AIStudio.Tools.Rust; using AIStudio.Tools.Services; @@ -9,6 +10,8 @@ using Microsoft.AspNetCore.Components; using SharedTools; +using DialogOptions = AIStudio.Dialogs.DialogOptions; + namespace AIStudio.Pages; public partial class About : MSGComponentBase @@ -16,6 +19,9 @@ public partial class About : MSGComponentBase [Inject] private RustService RustService { get; init; } = null!; + [Inject] + private IDialogService DialogService { get; init; } = null!; + [Inject] private ISnackbar Snackbar { get; init; } = null!; @@ -23,6 +29,8 @@ public partial class About : MSGComponentBase private static readonly MetaDataAttribute META_DATA = ASSEMBLY.GetCustomAttribute()!; private static readonly MetaDataArchitectureAttribute META_DATA_ARCH = ASSEMBLY.GetCustomAttribute()!; private static readonly MetaDataLibrariesAttribute META_DATA_LIBRARIES = ASSEMBLY.GetCustomAttribute()!; + + private static string TB(string fallbackEN) => Tools.PluginSystem.I18N.I.T(fallbackEN, typeof(About).Namespace, nameof(About)); private string osLanguage = string.Empty; @@ -43,6 +51,9 @@ public partial class About : MSGComponentBase private string BuildTime => $"{T("Build time")}: {META_DATA.BuildTime}"; private string VersionPdfium => $"{T("Used PDFium version")}: v{META_DATA_LIBRARIES.PdfiumVersion}"; + + private string versionPandoc = TB("Determine Pandoc version, please wait..."); + private PandocInstallation pandocInstallation; private GetLogPathsResponse logPaths; @@ -52,11 +63,40 @@ public partial class About : MSGComponentBase { this.osLanguage = await this.RustService.ReadUserLanguage(); this.logPaths = await this.RustService.GetLogPaths(); + await base.OnInitializedAsync(); + await this.DeterminePandocVersion(); } #endregion + private async Task DeterminePandocVersion() + { + this.pandocInstallation = await Pandoc.CheckAvailabilityAsync(this.RustService, false); + var pandocInstallationType = this.pandocInstallation.IsLocalInstallation + ? T("installed by AI Studio") + : T("installation provided by the system"); + + switch (this.pandocInstallation) + { + case { CheckWasSuccessful: true, IsAvailable: true }: + this.versionPandoc = $"{this.T("Installed Pandoc version")}: v{this.pandocInstallation.Version} ({pandocInstallationType}) - OK"; + break; + + case { CheckWasSuccessful: true, IsAvailable: false }: + this.versionPandoc = $"{this.T("Installed Pandoc version")}: v{this.pandocInstallation.Version} ({pandocInstallationType}) - {T("this version does not met the requirements")}"; + break; + + default: + this.versionPandoc = TB("Installed Pandoc version: Pandoc is not installed or not available."); + break; + } + + this.StateHasChanged(); + } + + private async Task ShowPandocDialog() => await this.DialogService.ShowAsync(T("Pandoc Installation"), DialogOptions.FULLSCREEN); + private async Task CopyStartupLogPath() { await this.RustService.CopyText2Clipboard(this.Snackbar, this.logPaths.LogStartupPath);