mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-11-23 10:50:21 +00:00
Added handling for missing Pandoc installation
This commit is contained in:
parent
3e646edfeb
commit
11ca24e48e
@ -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()
|
||||||
|
|||||||
@ -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)
|
||||||
|
{
|
||||||
|
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;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Call Pandoc to create the Word file:
|
// Call Pandoc to create the Word file:
|
||||||
var pandoc = await PandocProcessBuilder
|
var pandoc = await PandocProcessBuilder
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user