mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-18 05:58:00 +00:00
Added settings manager to handle configuration
This commit is contained in:
3 files changed
+36
-4
No files matched your search
@@ -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
|
#region Overrides of ComponentBase
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
|
var dataDir = await this.JsRuntime.InvokeAsync<string>("window.__TAURI__.path.appLocalDataDir");
|
||||||
|
var configDir = await this.JsRuntime.InvokeAsync<string>("window.__TAURI__.path.appConfigDir");
|
||||||
|
SettingsManager.ConfigDirectory = configDir;
|
||||||
|
SettingsManager.DataDirectory = dataDir;
|
||||||
|
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ using MudBlazor;
|
|||||||
using MudBlazor.Services;
|
using MudBlazor.Services;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Services.AddMudServices();
|
||||||
|
builder.Services.AddMudMarkdownServices();
|
||||||
|
builder.Services.AddSingleton<SettingsManager>();
|
||||||
builder.Services.AddRazorComponents()
|
builder.Services.AddRazorComponents()
|
||||||
.AddInteractiveServerComponents()
|
.AddInteractiveServerComponents()
|
||||||
.AddHubOptions(x =>
|
.AddHubOptions(x =>
|
||||||
@@ -15,8 +18,6 @@ builder.WebHost.UseKestrel();
|
|||||||
builder.WebHost.UseWebRoot("wwwroot");
|
builder.WebHost.UseWebRoot("wwwroot");
|
||||||
builder.WebHost.UseStaticWebAssets();
|
builder.WebHost.UseStaticWebAssets();
|
||||||
builder.WebHost.UseUrls("http://localhost:5000");
|
builder.WebHost.UseUrls("http://localhost:5000");
|
||||||
builder.Services.AddMudServices();
|
|
||||||
builder.Services.AddMudMarkdownServices();
|
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|||||||
@@ -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<string> GetAPIKey(IJSRuntime jsRuntime) => await jsRuntime.InvokeAsync<string>("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));
|
||||||
|
}
|
||||||
Reference in new issue
Block a user