mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-20 22:52:56 +00:00
Finished dialog; installation and availability check logic
This commit is contained in:
parent
012b28da27
commit
81b276be69
@ -7,14 +7,14 @@
|
||||
{
|
||||
<div class="mb-4">
|
||||
<MudText Class="mb-2">
|
||||
AI Studio relies on the third-party app <strong>Pandoc</strong> to process and retrieve data from
|
||||
local
|
||||
AI Studio relies on the <strong>free and open-sourced</strong> third-party app <strong>Pandoc</strong> to process and retrieve data from local
|
||||
Office files (ex. <strong>Word</strong>) and later other text formats like LaTeX.
|
||||
</MudText>
|
||||
<MudText>
|
||||
Unfortunately Pandocs GPL license is not compatible with AI Studios licences.
|
||||
Therefore you have to accept Pandocs GPL license before we can download and install Pandoc
|
||||
automatically for you (recommended).
|
||||
Unfortunately Pandoc's GPL license is not compatible with AI Studios licences, nonetheless software under GPL is generally free to use and
|
||||
free of charge as well.
|
||||
Therefore you have to accept Pandoc's GPL license before we can download and install Pandoc for free
|
||||
automatically for you <strong>(recommended)</strong>.
|
||||
However you can download it yourself manually with the instructions below.
|
||||
</MudText>
|
||||
<MudExpansionPanels>
|
||||
@ -27,7 +27,7 @@
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(this.licenseText))
|
||||
{
|
||||
<div>@this.licenseText</div>
|
||||
<MudJustifiedText>@this.licenseText</MudJustifiedText>
|
||||
}
|
||||
</MudExpansionPanel>
|
||||
</MudExpansionPanels>
|
||||
@ -38,10 +38,10 @@
|
||||
Pandoc is distributed under the
|
||||
<MudLink Typo="Typo.caption" Href="https://github.com/jgm/pandoc/blob/main/COPYRIGHT" Target="_blank">GNU General Public License v2 (GPL)</MudLink>.
|
||||
By clicking "Accept GPL and Install", you agree to the terms of the GPL license <br/> and Pandoc
|
||||
will be installed automatically for you.<br/>
|
||||
will be installed automatically for you. Software under GPL is <strong>free of charge</strong> and free to use.<br/>
|
||||
</MudText>
|
||||
<MudButton OnClick="InstallPandocAsync" Color="Color.Primary" Class="mt-4" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.InstallDesktop">
|
||||
Accept GPL and Install
|
||||
Accept GPL and install for free
|
||||
</MudButton>
|
||||
</ExpansionPanel>
|
||||
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.Build" HeaderText="Manual installation">
|
||||
@ -51,7 +51,7 @@
|
||||
<MudExpansionPanels Outlined="false" Elevation="0">
|
||||
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.AppRegistration" HeaderText="Download with installer" IsExpanded="true">
|
||||
<MudList T="string">
|
||||
<MudListItem T="string" Class="mb-4">
|
||||
<MudListItem T="string" Class="mb-2">
|
||||
Accept the terms of the GPL license and download the latest installer with the download button below.
|
||||
Eventually you need to allow the download of the installer in the download window.
|
||||
<CodeTabs>
|
||||
@ -66,7 +66,7 @@
|
||||
</MudList>
|
||||
<MudText Class="mb-3" Typo="Typo.caption">
|
||||
Pandoc is distributed under the <MudLink Typo="Typo.caption" Href="https://github.com/jgm/pandoc/blob/main/COPYRIGHT" Target="_blank">GNU General Public License v2 (GPL)</MudLink>.
|
||||
By clicking "Accept GPL and download installer", you agree to the terms of the GPL license.<br/>
|
||||
By clicking "Accept GPL and download installer", you agree to the terms of the GPL license. Software under GPL is <strong>free of charge</strong> and free to use.<br/>
|
||||
</MudText>
|
||||
<MudButton OnClick="@this.GetInstaller" Color="Color.Secondary" Class="mt-4" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.Downloading">
|
||||
Accept GPL and download installer
|
||||
@ -74,10 +74,10 @@
|
||||
</ExpansionPanel>
|
||||
<ExpansionPanel HeaderIcon="@Icons.Material.Outlined.Archive" HeaderText="Download with archive">
|
||||
<MudList T="string">
|
||||
<MudListItem T="string" Class="mb-4">
|
||||
<MudListItem T="string" Class="mb-2">
|
||||
Accept the terms of the GPL license and download the latest archive with the download button below.
|
||||
</MudListItem>
|
||||
<MudListItem T="string" Class="mb-4">
|
||||
<MudListItem T="string" Class="mb-2">
|
||||
Extract the archive to a folder of your choice.
|
||||
<CodeTabs>
|
||||
<CodeBlock Title="Windows">C:\Users\%USERNAME%\pandoc</CodeBlock>
|
||||
@ -85,7 +85,7 @@
|
||||
<CodeBlock Title="Linux">/usr/local/bin/pandoc</CodeBlock>
|
||||
</CodeTabs>
|
||||
</MudListItem>
|
||||
<MudListItem T="string" Class="mb-4">
|
||||
<MudListItem T="string" Class="mb-2">
|
||||
Open the folder and copy the full path to the <CodeBlock IsInline="@true">pandoc.exe</CodeBlock> file into your
|
||||
clipboard.
|
||||
<CodeTabs>
|
||||
@ -107,7 +107,7 @@
|
||||
</MudList>
|
||||
<MudText Class="mb-3" Typo="Typo.caption">
|
||||
Pandoc is distributed under the <MudLink Typo="Typo.caption" Href="https://github.com/jgm/pandoc/blob/main/COPYRIGHT" Target="_blank">GNU General Public License v2 (GPL)</MudLink>.
|
||||
By clicking "Accept GPL and archive", you agree to the terms of the GPL license.<br/>
|
||||
By clicking "Accept GPL and archive", you agree to the terms of the GPL license. Software under GPL is <strong>free of charge</strong> and free to use.<br/>
|
||||
</MudText>
|
||||
<MudButton OnClick="@this.GetArchive" Color="Color.Secondary" Class="mt-4" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.Downloading">
|
||||
Accept GPL and download archive
|
||||
@ -117,7 +117,7 @@
|
||||
</ExpansionPanel>
|
||||
</MudExpansionPanels>
|
||||
<div class="mt-2">
|
||||
<MudButton Variant="Variant.Text" Color="Color.Default">Reject GPL licence</MudButton>
|
||||
<MudButton OnClick="@this.RejectLicense" Variant="Variant.Text" Color="Color.Default">Reject GPL licence</MudButton>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
@ -151,7 +151,4 @@
|
||||
</MudItem>
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<!-- Hier können Sie bei Bedarf Aktionen hinzufügen -->
|
||||
</DialogActions>
|
||||
</MudDialog>
|
@ -14,6 +14,9 @@ public partial class PandocDialog : ComponentBase
|
||||
[Inject]
|
||||
protected IJSRuntime JsRuntime { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private IDialogService DialogService { get; init; } = null!;
|
||||
|
||||
[CascadingParameter]
|
||||
private IMudDialogInstance MudDialog { get; set; } = null!;
|
||||
|
||||
@ -42,12 +45,17 @@ public partial class PandocDialog : ComponentBase
|
||||
|
||||
private async Task CheckPandocAvailabilityAsync()
|
||||
{
|
||||
this.isPandocAvailable = await Pandoc.CheckAvailabilityAsync(false);
|
||||
this.isPandocAvailable = await Pandoc.CheckAvailabilityAsync(this.RustService);
|
||||
this.showSkeleton = false;
|
||||
await this.InvokeAsync(this.StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task InstallPandocAsync() => await Pandoc.InstallAsync(this.RustService);
|
||||
private async Task InstallPandocAsync()
|
||||
{
|
||||
await Pandoc.InstallAsync(this.RustService);
|
||||
this.MudDialog.Close(DialogResult.Ok(true));
|
||||
await this.DialogService.ShowAsync<PandocDialog>("pandoc dialog");
|
||||
}
|
||||
|
||||
private void ProceedToInstallation() => this.showInstallPage = true;
|
||||
|
||||
@ -56,7 +64,6 @@ public partial class PandocDialog : ComponentBase
|
||||
var uri = await Pandoc.GenerateInstallerUriAsync();
|
||||
var filename = this.FilenameFromUri(uri);
|
||||
await this.JsRuntime.InvokeVoidAsync("triggerDownload", uri, filename);
|
||||
|
||||
}
|
||||
|
||||
private async Task GetArchive()
|
||||
@ -66,15 +73,33 @@ public partial class PandocDialog : ComponentBase
|
||||
await this.JsRuntime.InvokeVoidAsync("triggerDownload", uri, filename);
|
||||
}
|
||||
|
||||
private async Task RejectLicense()
|
||||
{
|
||||
var message = "Pandoc is open-source and free of charge, but if you reject Pandoc's license, it can not be installed and some of AIStudios data retrieval features will be disabled (e.g. using Office files like Word)." +
|
||||
"This decision can be revoked at any time. Are you sure you want to reject the license?";
|
||||
|
||||
var dialogParameters = new DialogParameters
|
||||
{
|
||||
{ "Message", message },
|
||||
};
|
||||
|
||||
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Reject Pandoc's licence", dialogParameters, DialogOptions.FULLSCREEN);
|
||||
var dialogResult = await dialogReference.Result;
|
||||
if (dialogResult is null || dialogResult.Canceled)
|
||||
dialogReference.Close();
|
||||
else
|
||||
this.Cancel();
|
||||
}
|
||||
|
||||
private string FilenameFromUri(string uri)
|
||||
{
|
||||
var index = uri.LastIndexOf('/');
|
||||
return uri[(index + 1)..];
|
||||
}
|
||||
|
||||
private async Task OnExpandedChanged(bool newVal)
|
||||
private async Task OnExpandedChanged(bool isExpanded)
|
||||
{
|
||||
if (newVal)
|
||||
if (isExpanded)
|
||||
{
|
||||
this.isLoading = true;
|
||||
try
|
||||
|
@ -20,8 +20,27 @@ public static partial class Pandoc
|
||||
/// Checks if pandoc is available on the system and can be started as a process
|
||||
/// </summary>
|
||||
/// <returns>True, if pandoc is available and the minimum required version is met, else False.</returns>
|
||||
public static async Task<bool> CheckAvailabilityAsync(bool showMessages = true)
|
||||
public static async Task<bool> CheckAvailabilityAsync(RustService rustService, bool showMessages = true)
|
||||
{
|
||||
var installDir = await GetPandocDataFolder(rustService);
|
||||
var subdirectories = Directory.GetDirectories(installDir);
|
||||
|
||||
if (subdirectories.Length > 1)
|
||||
{
|
||||
await InstallAsync(rustService);
|
||||
return true;
|
||||
}
|
||||
|
||||
var hasPandoc = false;
|
||||
foreach (var subdirectory in subdirectories)
|
||||
{
|
||||
if (subdirectory.Contains("pandoc"))
|
||||
hasPandoc = true;
|
||||
}
|
||||
|
||||
if (hasPandoc)
|
||||
return true;
|
||||
|
||||
try
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
@ -88,9 +107,8 @@ public static partial class Pandoc
|
||||
|
||||
public static async Task InstallAsync(RustService rustService)
|
||||
{
|
||||
var dataDir = await rustService.GetDataDirectory();
|
||||
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Help, $"{dataDir}"));
|
||||
var installDir = Path.Join(dataDir, "pandoc");
|
||||
var installDir = await GetPandocDataFolder(rustService);
|
||||
ClearFolder(installDir);
|
||||
|
||||
try
|
||||
{
|
||||
@ -127,24 +145,8 @@ public static partial class Pandoc
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var currentPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine);
|
||||
var pandocDir = Path.Join(currentPath, "pandoc-3.6.4");
|
||||
if (currentPath != null && !currentPath.Contains(pandocDir))
|
||||
{
|
||||
Environment.SetEnvironmentVariable(
|
||||
"PATH",
|
||||
$"{currentPath};{pandocDir}",
|
||||
EnvironmentVariableTarget.Machine);
|
||||
Console.WriteLine("Pandoc-Verzeichnis zum PATH hinzugefügt.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Pandoc-Verzeichnis ist bereits im PATH.");
|
||||
}
|
||||
|
||||
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle,
|
||||
$"Pandoc {MINIMUM_REQUIRED_VERSION.ToString()} was installed successfully."));
|
||||
$"Pandoc {await FetchLatestVersionAsync()} was installed successfully."));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -152,9 +154,21 @@ public static partial class Pandoc
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task ExtractZipAsync(string zipPath, string targetDir)
|
||||
private static void ClearFolder(string path)
|
||||
{
|
||||
if (!Directory.Exists(path)) return;
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var dir in Directory.GetDirectories(path))
|
||||
{
|
||||
Directory.Delete(dir, true);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.LogError(ex, "Error clearing pandoc folder.");
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<string> FetchLatestVersionAsync() {
|
||||
@ -222,6 +236,8 @@ public static partial class Pandoc
|
||||
/// </summary>
|
||||
private static string GetPandocExecutableName() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "pandoc.exe" : "pandoc";
|
||||
|
||||
private static async Task<string> GetPandocDataFolder(RustService rustService) => Path.Join(await rustService.GetDataDirectory(), "pandoc");
|
||||
|
||||
[GeneratedRegex(@"pandoc(?:\.exe)?\s*([0-9]+\.[0-9]+)")]
|
||||
private static partial Regex PandocRegex();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user