Skip to content

Commit 164b07c

Browse files
Improved Pandoc installation checking (#571)
1 parent 473bfd0 commit 164b07c

File tree

8 files changed

+93
-7
lines changed

8 files changed

+93
-7
lines changed

app/MindWork AI Studio/Assistants/I18N/allTexts.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,12 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::PROFILESELECTION::T918741365"] = "You can
16661666
-- Provider
16671667
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::PROVIDERSELECTION::T900237532"] = "Provider"
16681668

1669+
-- Pandoc Installation
1670+
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T185447014"] = "Pandoc Installation"
1671+
1672+
-- Pandoc may be required for importing files.
1673+
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T2596465560"] = "Pandoc may be required for importing files."
1674+
16691675
-- Images are not supported yet
16701676
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T298062956"] = "Images are not supported yet"
16711677

@@ -5368,6 +5374,12 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOC::T567205144"] = "It seems that Pandoc i
53685374
-- The latest Pandoc version was not found, installing version {0} instead.
53695375
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOC::T726914939"] = "The latest Pandoc version was not found, installing version {0} instead."
53705376

5377+
-- Pandoc is required for Microsoft Word export.
5378+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOCEXPORT::T1473115556"] = "Pandoc is required for Microsoft Word export."
5379+
5380+
-- Pandoc Installation
5381+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOCEXPORT::T185447014"] = "Pandoc Installation"
5382+
53715383
-- Error during Microsoft Word export
53725384
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOCEXPORT::T3290596792"] = "Error during Microsoft Word export"
53735385

app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private async Task RemoveBlock()
138138

139139
private async Task ExportToWord()
140140
{
141-
await PandocExport.ToMicrosoftWord(this.RustService, T("Export Chat to Microsoft Word"), this.Content);
141+
await PandocExport.ToMicrosoftWord(this.RustService, this.DialogService, T("Export Chat to Microsoft Word"), this.Content);
142142
}
143143

144144
private async Task RegenerateBlock()

app/MindWork AI Studio/Components/ReadFileContent.razor.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
using AIStudio.Dialogs;
12
using AIStudio.Tools.Rust;
23
using AIStudio.Tools.Services;
34

45
using Microsoft.AspNetCore.Components;
56

7+
using DialogOptions = AIStudio.Dialogs.DialogOptions;
8+
69
namespace AIStudio.Components;
710

811
public partial class ReadFileContent : MSGComponentBase
@@ -16,6 +19,12 @@ public partial class ReadFileContent : MSGComponentBase
1619
[Inject]
1720
private RustService RustService { get; init; } = null!;
1821

22+
[Inject]
23+
private IDialogService DialogService { get; init; } = null!;
24+
25+
[Inject]
26+
private ILogger<ReadFileContent> Logger { get; init; } = null!;
27+
1928
private async Task SelectFile()
2029
{
2130
var selectedFile = await this.RustService.SelectFile(T("Select file to read its content"));
@@ -38,6 +47,26 @@ private async Task SelectFile()
3847
return;
3948
}
4049

50+
// Ensure that Pandoc is installed and ready:
51+
var pandocState = await Pandoc.CheckAvailabilityAsync(this.RustService, showSuccessMessage: false);
52+
if (!pandocState.IsAvailable)
53+
{
54+
var dialogParameters = new DialogParameters<PandocDialog>
55+
{
56+
{ x => x.ShowInitialResultInSnackbar, false },
57+
};
58+
59+
var dialogReference = await this.DialogService.ShowAsync<PandocDialog>(T("Pandoc Installation"), dialogParameters, DialogOptions.FULLSCREEN);
60+
await dialogReference.Result;
61+
62+
pandocState = await Pandoc.CheckAvailabilityAsync(this.RustService, showSuccessMessage: true);
63+
if (!pandocState.IsAvailable)
64+
{
65+
this.Logger.LogError("Pandoc is not available after installation attempt.");
66+
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.Cancel, T("Pandoc may be required for importing files.")));
67+
}
68+
}
69+
4170
var fileContent = await this.RustService.ReadArbitraryFileData(selectedFile.SelectedFilePath, int.MaxValue);
4271
await this.FileContentChanged.InvokeAsync(fileContent);
4372
}

app/MindWork AI Studio/Plugins/languages/de-de-43065dbc-78d0-45b7-92be-f14c2926e2dc/plugin.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,12 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::PROFILESELECTION::T918741365"] = "Hier k
16681668
-- Provider
16691669
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::PROVIDERSELECTION::T900237532"] = "Anbieter"
16701670

1671+
-- Pandoc Installation
1672+
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T185447014"] = "Pandoc-Installation"
1673+
1674+
-- Pandoc may be required for importing files.
1675+
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T2596465560"] = "Pandoc wird möglicherweise zum Importieren von Dateien benötigt."
1676+
16711677
-- Images are not supported yet
16721678
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T298062956"] = "Bilder werden derzeit nicht unterstützt"
16731679

@@ -5370,6 +5376,12 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOC::T567205144"] = "Es scheint, dass Pando
53705376
-- The latest Pandoc version was not found, installing version {0} instead.
53715377
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOC::T726914939"] = "Die neueste Pandoc-Version wurde nicht gefunden, stattdessen wird Version {0} installiert."
53725378

5379+
-- Pandoc is required for Microsoft Word export.
5380+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOCEXPORT::T1473115556"] = "Pandoc wird für den Export nach Microsoft Word benötigt."
5381+
5382+
-- Pandoc Installation
5383+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOCEXPORT::T185447014"] = "Pandoc-Installation"
5384+
53735385
-- Error during Microsoft Word export
53745386
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOCEXPORT::T3290596792"] = "Fehler beim Exportieren nach Microsoft Word"
53755387

app/MindWork AI Studio/Plugins/languages/en-us-97dfb1ba-50c4-4440-8dfa-6575daf543c8/plugin.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,12 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::PROFILESELECTION::T918741365"] = "You can
16681668
-- Provider
16691669
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::PROVIDERSELECTION::T900237532"] = "Provider"
16701670

1671+
-- Pandoc Installation
1672+
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T185447014"] = "Pandoc Installation"
1673+
1674+
-- Pandoc may be required for importing files.
1675+
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T2596465560"] = "Pandoc may be required for importing files."
1676+
16711677
-- Images are not supported yet
16721678
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T298062956"] = "Images are not supported yet"
16731679

@@ -5370,6 +5376,12 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOC::T567205144"] = "It seems that Pandoc i
53705376
-- The latest Pandoc version was not found, installing version {0} instead.
53715377
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOC::T726914939"] = "The latest Pandoc version was not found, installing version {0} instead."
53725378

5379+
-- Pandoc is required for Microsoft Word export.
5380+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOCEXPORT::T1473115556"] = "Pandoc is required for Microsoft Word export."
5381+
5382+
-- Pandoc Installation
5383+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOCEXPORT::T185447014"] = "Pandoc Installation"
5384+
53735385
-- Error during Microsoft Word export
53745386
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PANDOCEXPORT::T3290596792"] = "Error during Microsoft Word export"
53755387

app/MindWork AI Studio/Tools/Pandoc.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public static partial class Pandoc
3737
/// </summary>
3838
/// <param name="rustService">Global rust service to access file system and data dir.</param>
3939
/// <param name="showMessages">Controls if snackbars are shown to the user.</param>
40+
/// <param name="showSuccessMessage">Controls if a success snackbar is shown to the user.</param>
4041
/// <returns>True, if pandoc is available and the minimum required version is met, else false.</returns>
41-
public static async Task<PandocInstallation> CheckAvailabilityAsync(RustService rustService, bool showMessages = true)
42+
public static async Task<PandocInstallation> CheckAvailabilityAsync(RustService rustService, bool showMessages = true, bool showSuccessMessage = true)
4243
{
4344
try
4445
{
@@ -80,7 +81,7 @@ public static async Task<PandocInstallation> CheckAvailabilityAsync(RustService
8081

8182
if (installedVersion >= MINIMUM_REQUIRED_VERSION)
8283
{
83-
if (showMessages)
84+
if (showMessages && showSuccessMessage)
8485
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle, string.Format(TB("Pandoc v{0} is installed."), installedVersionString)));
8586

8687
LOG.LogInformation("Pandoc v{0} is installed and matches the required version (v{1})", installedVersionString, MINIMUM_REQUIRED_VERSION.ToString());

app/MindWork AI Studio/Tools/PandocExport.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using System.Diagnostics;
22
using AIStudio.Chat;
3+
using AIStudio.Dialogs;
34
using AIStudio.Tools.PluginSystem;
45
using AIStudio.Tools.Services;
56

7+
using DialogOptions = AIStudio.Dialogs.DialogOptions;
8+
69
namespace AIStudio.Tools;
710

811
public static class PandocExport
@@ -11,7 +14,7 @@ public static class PandocExport
1114

1215
private static string TB(string fallbackEn) => I18N.I.T(fallbackEn, typeof(PandocExport).Namespace, nameof(PandocExport));
1316

14-
public static async Task<bool> ToMicrosoftWord(RustService rustService, string dialogTitle, IContent markdownContent)
17+
public static async Task<bool> ToMicrosoftWord(RustService rustService, IDialogService dialogService, string dialogTitle, IContent markdownContent)
1518
{
1619
var response = await rustService.SaveFile(dialogTitle, new("Microsoft Word", ["docx"]));
1720
if (response.UserCancelled)
@@ -40,9 +43,25 @@ public static async Task<bool> ToMicrosoftWord(RustService rustService, string d
4043
await File.WriteAllTextAsync(tempMarkdownFilePath, markdownText);
4144

4245
// Ensure that Pandoc is installed and ready:
43-
var pandocState = await Pandoc.CheckAvailabilityAsync(rustService);
46+
var pandocState = await Pandoc.CheckAvailabilityAsync(rustService, showSuccessMessage: false);
4447
if (!pandocState.IsAvailable)
45-
return false;
48+
{
49+
var dialogParameters = new DialogParameters<PandocDialog>
50+
{
51+
{ x => x.ShowInitialResultInSnackbar, false },
52+
};
53+
54+
var dialogReference = await dialogService.ShowAsync<PandocDialog>(TB("Pandoc Installation"), dialogParameters, DialogOptions.FULLSCREEN);
55+
await dialogReference.Result;
56+
57+
pandocState = await Pandoc.CheckAvailabilityAsync(rustService, showSuccessMessage: true);
58+
if (!pandocState.IsAvailable)
59+
{
60+
LOGGER.LogError("Pandoc is not available after installation attempt.");
61+
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.Cancel, TB("Pandoc is required for Microsoft Word export.")));
62+
return false;
63+
}
64+
}
4665

4766
// Call Pandoc to create the Word file:
4867
var pandoc = await PandocProcessBuilder

app/MindWork AI Studio/wwwroot/changelog/v0.9.53.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
- Added the ability to use documents as input for profile fields.
55
- Added the ability to distribute profiles via configuration plugins in enterprise environments. Thanks, Paul (`PaulKoudelka`), for your first contribution.
66
- Added the ability to preset an app-wide default profile using a configuration plugin in enterprise environments.
7-
- Improved profiles by removing their input limits.
7+
- Improved profiles by removing their input limits.
8+
- Improved the file reading component to correctly verify the Pandoc installation and open the installation dialog when needed.

0 commit comments

Comments
 (0)