From da97410f48a1e94d7e1fe019c69a7c847fe67ddf Mon Sep 17 00:00:00 2001
From: chunhualin1 <chunhualin1@lenovo.com>
Date: 星期三, 12 八月 2026 17:42:02 +0800
Subject: [PATCH] 修复LLM工具无法点击的问题
---
src/Moli.Desktop.Tests/Runtime/DesktopRuntimeCoordinatorTests.cs | 87 +++++++++++++++++++++++++++++++++++++++++--
1 files changed, 83 insertions(+), 4 deletions(-)
diff --git a/src/Moli.Desktop.Tests/Runtime/DesktopRuntimeCoordinatorTests.cs b/src/Moli.Desktop.Tests/Runtime/DesktopRuntimeCoordinatorTests.cs
index 60e959c..00e8102 100644
--- a/src/Moli.Desktop.Tests/Runtime/DesktopRuntimeCoordinatorTests.cs
+++ b/src/Moli.Desktop.Tests/Runtime/DesktopRuntimeCoordinatorTests.cs
@@ -1,9 +1,11 @@
+using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging.Abstractions;
using Moli.Desktop.Configuration;
using Moli.Desktop.Diagnostics;
using Moli.Desktop.Host;
using Moli.Desktop.Interop;
using Moli.Desktop.Layout;
+using Moli.Desktop.Llm;
using Moli.Desktop.Plugins;
using Moli.Desktop.Runtime;
using Moli.Desktop.Tests.Interop;
@@ -76,7 +78,26 @@
Assert.False(result.Succeeded);
Assert.Equal("WidgetLayoutLocked", result.ErrorCode);
- Assert.Null(fixture.Surface.LastAppliedLayout);
+ Assert.Equal(2, fixture.Surface.AppliedLayoutCount);
+ Assert.True(fixture.Surface.LastAppliedLayout?.IsLocked);
+ Assert.Equal(new RectD(100, 100, 320, 160), fixture.Surface.LastAppliedLayout?.Bounds);
+ }
+
+ [Fact]
+ public async Task StartAsync_RestoresRuntimeFlagsBeforeCreatingWidgetSurfaces()
+ {
+ var fixture = await RuntimeFixture.CreateAsync(new RuntimeSettings
+ {
+ EditMode = true,
+ SafeInputMode = true
+ });
+
+ var result = await fixture.Runtime.StartAsync();
+
+ Assert.True(result.Succeeded);
+ Assert.True(fixture.Surface.EditModeEnabled);
+ Assert.True(fixture.Surface.SafeInputModeEnabled);
+ Assert.Equal(1, fixture.Surface.AppliedLayoutCount);
}
private sealed class RuntimeFixture
@@ -101,7 +122,7 @@
public FakeRuntimeSurfaceController Surface { get; }
public WidgetInstanceId WidgetId { get; }
- public static async Task<RuntimeFixture> CreateAsync()
+ public static async Task<RuntimeFixture> CreateAsync(RuntimeSettings? runtimeSettings = null)
{
var root = Path.Combine(Path.GetTempPath(), "Moli.Desktop.Tests", Guid.NewGuid().ToString("N"));
var paths = new DesktopPaths(Path.Combine(root, "app"), Path.Combine(root, "local"));
@@ -114,6 +135,14 @@
var widgetId = new WidgetInstanceId("widget-01");
await CreatePluginAsync(paths);
+ if (runtimeSettings is not null)
+ {
+ await configuration.SaveAppSettingsAsync(new AppSettingsDocument
+ {
+ Runtime = runtimeSettings
+ });
+ }
+
await configuration.SaveLayoutAsync(new LayoutDocument
{
Monitors =
@@ -142,7 +171,9 @@
new FakeWin32InteropService(),
diagnostics,
events,
- surface);
+ surface,
+ new DisplayChangeMonitor(),
+ new FakeLlmGateway());
return new RuntimeFixture(runtime, configuration, events, surface, widgetId);
}
@@ -182,7 +213,9 @@
private sealed class FakeRuntimeSurfaceController : IRuntimeSurfaceController
{
public bool EditModeEnabled { get; private set; }
+ public bool SafeInputModeEnabled { get; private set; }
public WidgetLayout? LastAppliedLayout { get; private set; }
+ public int AppliedLayoutCount { get; private set; }
public Task ApplyEditModeAsync(bool enabled, CancellationToken cancellationToken = default)
{
@@ -190,11 +223,16 @@
return Task.CompletedTask;
}
- public Task ApplySafeInputModeAsync(bool enabled, CancellationToken cancellationToken = default) => Task.CompletedTask;
+ public Task ApplySafeInputModeAsync(bool enabled, CancellationToken cancellationToken = default)
+ {
+ SafeInputModeEnabled = enabled;
+ return Task.CompletedTask;
+ }
public Task ApplyWidgetLayoutAsync(WidgetLayout layout, CancellationToken cancellationToken = default)
{
LastAppliedLayout = layout;
+ AppliedLayoutCount++;
return Task.CompletedTask;
}
@@ -203,5 +241,46 @@
public Task DisableWallpaperAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
public Task ShutdownAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
+
+ public Task SyncAllLayoutsAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
+
+ public Task SyncWallpaperMonitorsAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
+
+ public Task ReattachDesktopLayersAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
+ }
+
+ private sealed class FakeLlmGateway : ILlmGatewayService
+ {
+ public Task<IReadOnlyList<LlmModelSummary>> GetModelsAsync(CancellationToken cancellationToken = default)
+ => Task.FromResult<IReadOnlyList<LlmModelSummary>>([]);
+
+ public Task<IReadOnlyList<LlmModelSummary>> GetModelsAsync(LlmPluginRuntimeConfig runtimeConfig, CancellationToken cancellationToken = default)
+ => Task.FromResult<IReadOnlyList<LlmModelSummary>>([]);
+
+ public Task<IReadOnlyList<AiChatProjectSummary>> GetProjectsAsync(LlmPluginRuntimeConfig runtimeConfig, CancellationToken cancellationToken = default)
+ => Task.FromResult<IReadOnlyList<AiChatProjectSummary>>([]);
+
+ public Task<AiChatMemoryCapabilities> GetMemoryCapabilitiesAsync(LlmPluginRuntimeConfig runtimeConfig, CancellationToken cancellationToken = default)
+ => Task.FromResult(new AiChatMemoryCapabilities());
+
+ public Task<AiChatJsonResult> GetMemoriesAsync(LlmPluginRuntimeConfig runtimeConfig, AiChatGetMemoriesRequest request, CancellationToken cancellationToken = default)
+ => Task.FromResult(new AiChatJsonResult());
+
+ public Task<AiChatJsonResult> CreateMemoryAsync(LlmPluginRuntimeConfig runtimeConfig, AiChatCreateMemoryRequest request, CancellationToken cancellationToken = default)
+ => Task.FromResult(new AiChatJsonResult());
+
+ public Task DeleteMemoryAsync(LlmPluginRuntimeConfig runtimeConfig, string memoryId, CancellationToken cancellationToken = default) => Task.CompletedTask;
+
+ public Task<AiChatJsonResult> RecallMemoriesAsync(LlmPluginRuntimeConfig runtimeConfig, AiChatRecallMemoriesRequest request, CancellationToken cancellationToken = default)
+ => Task.FromResult(new AiChatJsonResult());
+
+ public async IAsyncEnumerable<LlmStreamEvent> StreamChatAsync(LlmChatRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default)
+ {
+ yield break;
+ }
+
+ public Task CancelAsync(string requestId, CancellationToken cancellationToken = default) => Task.CompletedTask;
+
+ public Task CancelPluginRequestsAsync(string pluginId, CancellationToken cancellationToken = default) => Task.CompletedTask;
}
}
--
Gitblit v1.9.1