Added handling for missing Pandoc installation

This commit is contained in:
Thorsten Sommer 2025-11-14 13:11:10 +01:00
parent 3e646edfeb
commit 11ca24e48e
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 23 additions and 4 deletions

View File

@ -138,7 +138,7 @@ public partial class ContentBlockComponent : MSGComponentBase
private async Task ExportToWord() private async Task ExportToWord()
{ {
await PandocExport.ToMicrosoftWord(this.RustService, T("Export Chat to Microsoft Word"), this.Content); await PandocExport.ToMicrosoftWord(this.RustService, this.DialogService, T("Export Chat to Microsoft Word"), this.Content);
} }
private async Task RegenerateBlock() private async Task RegenerateBlock()

View File

@ -1,8 +1,11 @@
using System.Diagnostics; using System.Diagnostics;
using AIStudio.Chat; using AIStudio.Chat;
using AIStudio.Dialogs;
using AIStudio.Tools.PluginSystem; using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.Services; using AIStudio.Tools.Services;
using DialogOptions = AIStudio.Dialogs.DialogOptions;
namespace AIStudio.Tools; namespace AIStudio.Tools;
public static class PandocExport public static class PandocExport
@ -11,7 +14,7 @@ public static class PandocExport
private static string TB(string fallbackEn) => I18N.I.T(fallbackEn, typeof(PandocExport).Namespace, nameof(PandocExport)); private static string TB(string fallbackEn) => I18N.I.T(fallbackEn, typeof(PandocExport).Namespace, nameof(PandocExport));
public static async Task<bool> ToMicrosoftWord(RustService rustService, string dialogTitle, IContent markdownContent) public static async Task<bool> ToMicrosoftWord(RustService rustService, IDialogService dialogService, string dialogTitle, IContent markdownContent)
{ {
var response = await rustService.SaveFile(dialogTitle, new("Microsoft Word", ["docx"])); var response = await rustService.SaveFile(dialogTitle, new("Microsoft Word", ["docx"]));
if (response.UserCancelled) if (response.UserCancelled)
@ -40,9 +43,25 @@ public static class PandocExport
await File.WriteAllTextAsync(tempMarkdownFilePath, markdownText); await File.WriteAllTextAsync(tempMarkdownFilePath, markdownText);
// Ensure that Pandoc is installed and ready: // Ensure that Pandoc is installed and ready:
var pandocState = await Pandoc.CheckAvailabilityAsync(rustService); var pandocState = await Pandoc.CheckAvailabilityAsync(rustService, showSuccessMessage: false);
if (!pandocState.IsAvailable) if (!pandocState.IsAvailable)
return false; {
var dialogParameters = new DialogParameters<PandocDialog>
{
{ x => x.ShowInitialResultInSnackbar, false },
};
var dialogReference = await dialogService.ShowAsync<PandocDialog>(TB("Pandoc Installation"), dialogParameters, DialogOptions.FULLSCREEN);
await dialogReference.Result;
pandocState = await Pandoc.CheckAvailabilityAsync(rustService, showSuccessMessage: true);
if (!pandocState.IsAvailable)
{
LOGGER.LogError("Pandoc is not available after installation attempt.");
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.Cancel, TB("Pandoc is required for Microsoft Word export")));
return false;
}
}
// Call Pandoc to create the Word file: // Call Pandoc to create the Word file:
var pandoc = await PandocProcessBuilder var pandoc = await PandocProcessBuilder