diff --git a/app/MindWork AI Studio/Components/Layout/MainLayout.razor.cs b/app/MindWork AI Studio/Components/Layout/MainLayout.razor.cs index 8754c8d..e79913f 100644 --- a/app/MindWork AI Studio/Components/Layout/MainLayout.razor.cs +++ b/app/MindWork AI Studio/Components/Layout/MainLayout.razor.cs @@ -1,11 +1,22 @@ -namespace MindWork_AI_Studio.Components.Layout; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; -public partial class MainLayout +namespace AIStudio.Components.Layout; + +public partial class MainLayout : LayoutComponentBase { + [Inject] + private IJSRuntime JsRuntime { get; set; } = null!; + #region Overrides of ComponentBase protected override async Task OnInitializedAsync() { + var dataDir = await this.JsRuntime.InvokeAsync("window.__TAURI__.path.appLocalDataDir"); + var configDir = await this.JsRuntime.InvokeAsync("window.__TAURI__.path.appConfigDir"); + SettingsManager.ConfigDirectory = configDir; + SettingsManager.DataDirectory = dataDir; + await base.OnInitializedAsync(); } diff --git a/app/MindWork AI Studio/Program.cs b/app/MindWork AI Studio/Program.cs index 967abbe..8953701 100644 --- a/app/MindWork AI Studio/Program.cs +++ b/app/MindWork AI Studio/Program.cs @@ -4,6 +4,9 @@ using MudBlazor; using MudBlazor.Services; var builder = WebApplication.CreateBuilder(args); +builder.Services.AddMudServices(); +builder.Services.AddMudMarkdownServices(); +builder.Services.AddSingleton(); builder.Services.AddRazorComponents() .AddInteractiveServerComponents() .AddHubOptions(x => @@ -15,8 +18,6 @@ builder.WebHost.UseKestrel(); builder.WebHost.UseWebRoot("wwwroot"); builder.WebHost.UseStaticWebAssets(); builder.WebHost.UseUrls("http://localhost:5000"); -builder.Services.AddMudServices(); -builder.Services.AddMudMarkdownServices(); var app = builder.Build(); app.UseStaticFiles(); diff --git a/app/MindWork AI Studio/SettingsManager.cs b/app/MindWork AI Studio/SettingsManager.cs new file mode 100644 index 0000000..aeddaba --- /dev/null +++ b/app/MindWork AI Studio/SettingsManager.cs @@ -0,0 +1,20 @@ +using Microsoft.JSInterop; + +namespace AIStudio; + +public sealed class SettingsManager +{ + public static string? ConfigDirectory { get; set; } + + public static string? DataDirectory { get; set; } + + public bool IsSetUp => !string.IsNullOrWhiteSpace(ConfigDirectory) && !string.IsNullOrWhiteSpace(DataDirectory); + + private readonly record struct GetSecretRequest(string Destination, string UserName); + + public async Task GetAPIKey(IJSRuntime jsRuntime) => await jsRuntime.InvokeAsync("window.__TAURI__.invoke", "get_secret", new GetSecretRequest("api_key", Environment.UserName)); + + private readonly record struct StoreSecretRequest(string Destination, string UserName, string Secret); + + public async Task SetAPIKey(IJSRuntime jsRuntime, string key) => await jsRuntime.InvokeVoidAsync("window.__TAURI__.invoke", "store_secret", new StoreSecretRequest("api_key", Environment.UserName, key)); +} \ No newline at end of file