mirror of
				https://github.com/MindWorkAI/AI-Studio.git
				synced 2025-10-31 20:20:20 +00:00 
			
		
		
		
	Added settings manager to handle configuration
This commit is contained in:
		
							parent
							
								
									b02b39c023
								
							
						
					
					
						commit
						583f530d28
					
				| @ -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<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(); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -4,6 +4,9 @@ using MudBlazor; | ||||
| using MudBlazor.Services; | ||||
| 
 | ||||
| var builder = WebApplication.CreateBuilder(args); | ||||
| builder.Services.AddMudServices(); | ||||
| builder.Services.AddMudMarkdownServices(); | ||||
| builder.Services.AddSingleton<SettingsManager>(); | ||||
| 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(); | ||||
|  | ||||
							
								
								
									
										20
									
								
								app/MindWork AI Studio/SettingsManager.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								app/MindWork AI Studio/SettingsManager.cs
									
									
									
									
									
										Normal file
									
								
							| @ -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)); | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user