Existing ASP.NET API with vanilla JS SPA, WindowWatcher, Chrome extension, and MCP server. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
1011 B
C#
33 lines
1011 B
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using WindowWatcher;
|
|
|
|
var hostCts = new CancellationTokenSource();
|
|
|
|
var builder = Host.CreateApplicationBuilder(args);
|
|
|
|
builder.Services.Configure<WindowWatcherOptions>(
|
|
builder.Configuration.GetSection(WindowWatcherOptions.SectionName));
|
|
|
|
builder.Services.AddHttpClient("TaskTrackerApi", (sp, client) =>
|
|
{
|
|
var config = sp.GetRequiredService<Microsoft.Extensions.Options.IOptions<WindowWatcherOptions>>().Value;
|
|
client.BaseAddress = new Uri(config.ApiBaseUrl);
|
|
});
|
|
|
|
builder.Services.AddHostedService<Worker>();
|
|
|
|
var host = builder.Build();
|
|
|
|
// Run the host in a background thread
|
|
var hostTask = Task.Run(() => host.RunAsync(hostCts.Token));
|
|
|
|
// Run WinForms tray icon on the main thread
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
Application.Run(new TrayApplicationContext(hostCts));
|
|
|
|
// Wait for host to finish
|
|
await hostTask;
|