基于WebView2实现的Win11桌面框架,利用插件自定义
Moli
2026-07-29 cf40cded1708bb303be4a404b7aceddd196e1d46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Moli.Desktop.Audio;
using Moli.Desktop.Configuration;
using Moli.Desktop.Diagnostics;
using Moli.Desktop.Interop;
using Moli.Desktop.Layout;
using Moli.Desktop.Api;
using Moli.Desktop.Llm;
using Moli.Desktop.Management;
using Moli.Desktop.Plugins;
using Moli.Desktop.Runtime;
using Moli.Desktop.Tray;
using Moli.Desktop.WebView;
using Moli.Desktop.Windows;
 
namespace Moli.Desktop.Host;
 
/// <summary>Builds the application host and shared services.</summary>
public static class DesktopHostBuilder
{
    public static IHostBuilder Create(string[] args)
    {
        return Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
            .ConfigureLogging(logging =>
            {
                var paths = new DesktopPaths();
                logging.ClearProviders();
                logging.AddDebug();
                logging.AddProvider(new DailyFileLoggerProvider(paths.LogDirectory));
            })
            .ConfigureServices(services =>
            {
                services.AddSingleton<DesktopPaths>();
                services.AddSingleton<IDiagnosticsService, DiagnosticsService>();
                services.AddSingleton<IDefaultContentInstaller, DefaultContentInstaller>();
                services.AddSingleton<IRuntimeEventBus, RuntimeEventBus>();
                services.AddHostedService<WasapiLoopbackAudioSpectrumService>();
                services.AddSingleton<IRuntimeSurfaceController, RuntimeSurfaceController>();
                services.AddSingleton<IDesktopRuntime, DesktopRuntimeCoordinator>();
                services.AddSingleton<IConfigurationService, JsonConfigurationService>();
                services.AddSingleton<ILlmModelRegistry, LlmModelRegistry>();
                services.AddSingleton<ICredentialStore, EnvironmentCredentialStore>();
                services.AddHttpClient<OpenAICompatibleAdapter>();
                services.AddHttpClient<AiChatClient>();
                services.AddSingleton<IAiChatClient>(sp => sp.GetRequiredService<AiChatClient>());
                services.AddSingleton<ILlmProviderAdapter>(sp => sp.GetRequiredService<OpenAICompatibleAdapter>());
                services.AddSingleton<ILlmProviderAdapterFactory, LlmProviderAdapterFactory>();
                services.AddSingleton<ILlmGatewayService, LlmGatewayService>();
                services.AddSingleton<IPluginManifestValidator, PluginManifestValidator>();
                services.AddSingleton<PluginStateMachine>();
                services.AddSingleton<IPluginManager, PluginManager>();
                services.AddSingleton<ILayoutManager, LayoutManager>();
                services.AddSingleton<IDesktopLayerStrategy, WorkerWDesktopLayerStrategy>();
                services.AddSingleton<IDesktopLayerStrategy, BottomDesktopLayerStrategy>();
                services.AddSingleton<IWin32InteropService, Win32InteropService>();
                services.AddSingleton<PluginBridgeDispatcher>();
                services.AddSingleton<IWebViewHostFactory, WebViewHostFactory>();
                services.AddSingleton<LocalApiService>();
                services.AddSingleton<ILocalApiStatus>(sp => sp.GetRequiredService<LocalApiService>());
                services.AddHostedService(sp => sp.GetRequiredService<LocalApiService>());
                services.AddSingleton<IStartupService, RegistryStartupService>();
                services.AddSingleton<ITrayShell, TrayShell>();
                services.AddTransient<ManagementWindow>();
            });
    }
}