| | |
| | | using Moli.Desktop.Configuration; |
| | | using Moli.Desktop.Diagnostics; |
| | | using Moli.Desktop.Host; |
| | | using Moli.Desktop.Hotkeys; |
| | | using Moli.Desktop.Interop; |
| | | using Moli.Desktop.Layout; |
| | | using Moli.Desktop.Llm; |
| | |
| | | Assert.Equal(1, fixture.Surface.AppliedLayoutCount); |
| | | } |
| | | |
| | | [Fact] |
| | | public async Task ToggleWidgetInteractableAsync_DoesNotWriteLayoutAndOverridesClickThrough() |
| | | { |
| | | var fixture = await RuntimeFixture.CreateAsync(); |
| | | await fixture.Configuration.SaveLayoutAsync(new LayoutDocument |
| | | { |
| | | Monitors = |
| | | [ |
| | | new MonitorSnapshot { Monitors = [RuntimeFixture.PrimaryMonitor()] } |
| | | ], |
| | | Instances = |
| | | [ |
| | | new WidgetLayout |
| | | { |
| | | InstanceId = fixture.WidgetId, |
| | | PluginId = new PluginId("sample.clock"), |
| | | MonitorId = new MonitorId("primary"), |
| | | Bounds = new RectD(100, 100, 320, 160), |
| | | ClickThrough = false, |
| | | IsVisible = true |
| | | } |
| | | ] |
| | | }); |
| | | await fixture.Runtime.StartAsync(); |
| | | var before = await fixture.Configuration.LoadLayoutAsync(); |
| | | |
| | | var result = await fixture.Runtime.ToggleWidgetInteractableAsync(fixture.WidgetId); |
| | | |
| | | Assert.True(result.Succeeded); |
| | | Assert.True(result.Value!.IsInteractable); |
| | | Assert.True(result.Value.HasSessionInteractable); |
| | | Assert.False(result.Value.ClickThrough); |
| | | Assert.False(result.Value.LayoutClickThrough); |
| | | Assert.Equal(1, fixture.Surface.SessionOverlayCount); |
| | | Assert.True(fixture.Surface.LastSessionOverlay?.Interactable); |
| | | |
| | | var idle = await fixture.Runtime.ToggleWidgetInteractableAsync(fixture.WidgetId); |
| | | Assert.True(idle.Succeeded); |
| | | Assert.False(idle.Value!.IsInteractable); |
| | | Assert.True(idle.Value.ClickThrough); |
| | | |
| | | var after = await fixture.Configuration.LoadLayoutAsync(); |
| | | var saved = Assert.Single(after.Instances); |
| | | Assert.Equal(before.Instances[0].ClickThrough, saved.ClickThrough); |
| | | Assert.Equal(before.Instances[0].IsVisible, saved.IsVisible); |
| | | } |
| | | |
| | | [Fact] |
| | | public async Task SetEditModeAsync_ForcesClickableOverSessionIdleOverlay() |
| | | { |
| | | var fixture = await RuntimeFixture.CreateAsync(); |
| | | await fixture.Runtime.StartAsync(); |
| | | await fixture.Runtime.SetWidgetInteractableAsync(fixture.WidgetId, false); |
| | | |
| | | var result = await fixture.Runtime.SetEditModeAsync(true); |
| | | |
| | | var widget = Assert.Single(result.Value!.Widgets); |
| | | Assert.False(widget.IsInteractable); |
| | | Assert.True(widget.HasSessionInteractable); |
| | | Assert.False(widget.ClickThrough); |
| | | Assert.True(widget.LayoutClickThrough); |
| | | } |
| | | |
| | | [Fact] |
| | | public async Task StartAsync_AppliesIdleClickThroughForEnabledToggleInteractableBinding() |
| | | { |
| | | var fixture = await CreateIdleToggleInteractableFixtureAsync(); |
| | | |
| | | var result = await fixture.Runtime.StartAsync(); |
| | | |
| | | var widget = Assert.Single(result.Value!.Widgets); |
| | | Assert.False(widget.IsInteractable); |
| | | Assert.True(widget.HasSessionInteractable); |
| | | Assert.True(widget.ClickThrough); |
| | | Assert.False(widget.LayoutClickThrough); |
| | | var saved = Assert.Single((await fixture.Configuration.LoadLayoutAsync()).Instances); |
| | | Assert.False(saved.ClickThrough); |
| | | } |
| | | |
| | | [Fact] |
| | | public async Task UpdateWidgetLayoutAsync_ClickThroughPatch_SyncsIdleOverlaySoOpenAndCloseBothTakeEffect() |
| | | { |
| | | var fixture = await CreateIdleToggleInteractableFixtureAsync(); |
| | | await fixture.Runtime.StartAsync(); |
| | | |
| | | var opened = await fixture.Runtime.UpdateWidgetLayoutAsync( |
| | | fixture.WidgetId, |
| | | new WidgetLayoutPatch { ClickThrough = true }); |
| | | |
| | | Assert.True(opened.Succeeded); |
| | | Assert.True(opened.Value!.ClickThrough); |
| | | Assert.True(opened.Value.LayoutClickThrough); |
| | | Assert.False(opened.Value.IsInteractable); |
| | | Assert.True(opened.Value.HasSessionInteractable); |
| | | Assert.False(fixture.Surface.LastSessionOverlay?.Interactable); |
| | | |
| | | var closed = await fixture.Runtime.UpdateWidgetLayoutAsync( |
| | | fixture.WidgetId, |
| | | new WidgetLayoutPatch { ClickThrough = false }); |
| | | |
| | | Assert.True(closed.Succeeded); |
| | | Assert.False(closed.Value!.ClickThrough); |
| | | Assert.False(closed.Value.LayoutClickThrough); |
| | | Assert.True(closed.Value.IsInteractable); |
| | | Assert.True(closed.Value.HasSessionInteractable); |
| | | Assert.True(fixture.Surface.LastSessionOverlay?.Interactable); |
| | | |
| | | var saved = Assert.Single((await fixture.Configuration.LoadLayoutAsync()).Instances); |
| | | Assert.False(saved.ClickThrough); |
| | | } |
| | | |
| | | [Fact] |
| | | public async Task HotkeyToggleInteractable_FlipsIdleSessionOverlay() |
| | | { |
| | | var fixture = await CreateIdleToggleInteractableFixtureAsync(); |
| | | await fixture.Runtime.StartAsync(); |
| | | Assert.True(Assert.Single((await fixture.Runtime.GetStateAsync()).Widgets).ClickThrough); |
| | | |
| | | await fixture.Hotkeys.RaiseAsync(HotkeysDocument.CreateBuiltinPaletteBinding() with |
| | | { |
| | | Target = new HotkeyTarget { PluginId = "sample.clock" } |
| | | }); |
| | | |
| | | var widget = Assert.Single((await fixture.Runtime.GetStateAsync()).Widgets); |
| | | Assert.True(widget.IsInteractable); |
| | | Assert.False(widget.ClickThrough); |
| | | } |
| | | |
| | | [Fact] |
| | | public async Task SaveHotkeysAsync_RejectsDuplicateChord() |
| | | { |
| | | var fixture = await RuntimeFixture.CreateAsync(); |
| | | await fixture.Runtime.StartAsync(); |
| | | var document = HotkeysDocument.CreateDefault(); |
| | | document.Bindings.Add(new HotkeyBinding |
| | | { |
| | | Id = "user-dup", |
| | | Keys = "Shift+Ctrl+K", |
| | | Action = HotkeyActions.RuntimeToggleEditMode, |
| | | Source = HotkeySource.User |
| | | }); |
| | | |
| | | var result = await fixture.Runtime.SaveHotkeysAsync(document); |
| | | |
| | | Assert.False(result.Succeeded); |
| | | Assert.Equal("HotkeyDuplicateChord", result.ErrorCode); |
| | | } |
| | | |
| | | private static async Task<RuntimeFixture> CreateIdleToggleInteractableFixtureAsync() |
| | | { |
| | | var fixture = await RuntimeFixture.CreateAsync(); |
| | | await fixture.Configuration.SaveLayoutAsync(new LayoutDocument |
| | | { |
| | | Monitors = [new MonitorSnapshot { Monitors = [RuntimeFixture.PrimaryMonitor()] }], |
| | | Instances = |
| | | [ |
| | | new WidgetLayout |
| | | { |
| | | InstanceId = fixture.WidgetId, |
| | | PluginId = new PluginId("sample.clock"), |
| | | MonitorId = new MonitorId("primary"), |
| | | Bounds = new RectD(100, 100, 320, 160), |
| | | ClickThrough = false |
| | | } |
| | | ] |
| | | }); |
| | | await fixture.Configuration.SaveHotkeysAsync(new HotkeysDocument |
| | | { |
| | | Bindings = |
| | | [ |
| | | HotkeysDocument.CreateBuiltinPaletteBinding() with |
| | | { |
| | | Target = new HotkeyTarget { PluginId = "sample.clock" } |
| | | } |
| | | ] |
| | | }); |
| | | return fixture; |
| | | } |
| | | |
| | | private sealed class RuntimeFixture |
| | | { |
| | | private RuntimeFixture( |
| | |
| | | JsonConfigurationService configuration, |
| | | RuntimeEventBus events, |
| | | FakeRuntimeSurfaceController surface, |
| | | FakeHotkeyService hotkeys, |
| | | WidgetInstanceId widgetId) |
| | | { |
| | | Runtime = runtime; |
| | | Configuration = configuration; |
| | | Events = events; |
| | | Surface = surface; |
| | | Hotkeys = hotkeys; |
| | | WidgetId = widgetId; |
| | | } |
| | | |
| | |
| | | public JsonConfigurationService Configuration { get; } |
| | | public RuntimeEventBus Events { get; } |
| | | public FakeRuntimeSurfaceController Surface { get; } |
| | | public FakeHotkeyService Hotkeys { get; } |
| | | public WidgetInstanceId WidgetId { get; } |
| | | |
| | | public static async Task<RuntimeFixture> CreateAsync(RuntimeSettings? runtimeSettings = null) |
| | |
| | | ] |
| | | }); |
| | | |
| | | var hotkeys = new FakeHotkeyService(); |
| | | var runtime = new DesktopRuntimeCoordinator( |
| | | configuration, |
| | | pluginManager, |
| | |
| | | events, |
| | | surface, |
| | | new DisplayChangeMonitor(), |
| | | new FakeLlmGateway()); |
| | | new FakeLlmGateway(), |
| | | hotkeys); |
| | | |
| | | return new RuntimeFixture(runtime, configuration, events, surface, widgetId); |
| | | return new RuntimeFixture(runtime, configuration, events, surface, hotkeys, widgetId); |
| | | } |
| | | |
| | | private static async Task CreatePluginAsync(DesktopPaths paths) |
| | |
| | | """); |
| | | } |
| | | |
| | | private static MonitorInfo PrimaryMonitor() => new() |
| | | public static MonitorInfo PrimaryMonitor() => new() |
| | | { |
| | | Id = new MonitorId("primary"), |
| | | Bounds = new RectD(0, 0, 1920, 1080), |
| | |
| | | public bool SafeInputModeEnabled { get; private set; } |
| | | public WidgetLayout? LastAppliedLayout { get; private set; } |
| | | public int AppliedLayoutCount { get; private set; } |
| | | public WidgetSessionOverlay? LastSessionOverlay { get; private set; } |
| | | public int SessionOverlayCount { get; private set; } |
| | | |
| | | public Task ApplyEditModeAsync(bool enabled, CancellationToken cancellationToken = default) |
| | | { |
| | |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | public Task ApplyWidgetSessionOverlayAsync(WidgetLayout layout, WidgetSessionOverlay overlay, CancellationToken cancellationToken = default) |
| | | { |
| | | LastAppliedLayout = layout; |
| | | LastSessionOverlay = overlay; |
| | | SessionOverlayCount++; |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | public Task EnableWallpaperAsync(WallpaperRuntimeState wallpaper, CancellationToken cancellationToken = default) => Task.CompletedTask; |
| | | |
| | | public Task DisableWallpaperAsync(CancellationToken cancellationToken = default) => Task.CompletedTask; |
| | |
| | | public Task ReattachDesktopLayersAsync(CancellationToken cancellationToken = default) => Task.CompletedTask; |
| | | } |
| | | |
| | | private sealed class FakeHotkeyService : IHotkeyService |
| | | { |
| | | public event Func<HotkeyBinding, Task>? HotkeyPressed; |
| | | public IReadOnlyList<HotkeyRegistration> Registrations { get; private set; } = []; |
| | | public IReadOnlyList<HotkeyBinding> Bindings { get; private set; } = []; |
| | | public bool Paused { get; private set; } |
| | | |
| | | public Task ReplaceBindingsAsync(IReadOnlyList<HotkeyBinding> bindings, CancellationToken cancellationToken = default) |
| | | { |
| | | Bindings = bindings.ToArray(); |
| | | Registrations = bindings.Select(binding => new HotkeyRegistration |
| | | { |
| | | BindingId = binding.Id, |
| | | Keys = binding.Keys, |
| | | State = !binding.Enabled || Paused ? HotkeyRegistrationState.Disabled : HotkeyRegistrationState.Registered |
| | | }).ToArray(); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | public void Pause() => Paused = true; |
| | | |
| | | public void Resume() => Paused = false; |
| | | |
| | | public void UnregisterAll() => Registrations = []; |
| | | |
| | | public Task RaiseAsync(HotkeyBinding binding) => HotkeyPressed?.Invoke(binding) ?? Task.CompletedTask; |
| | | |
| | | public void Dispose() |
| | | { |
| | | } |
| | | } |
| | | |
| | | private sealed class FakeLlmGateway : ILlmGatewayService |
| | | { |
| | | public Task<IReadOnlyList<LlmModelSummary>> GetModelsAsync(CancellationToken cancellationToken = default) |
| | |
| | | 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<AiChatProjectsResult> GetProjectsAsync(LlmPluginRuntimeConfig runtimeConfig, CancellationToken cancellationToken = default) |
| | | => Task.FromResult(new AiChatProjectsResult |
| | | { |
| | | Status = AiChatProjectStatuses.NotConfigured, |
| | | Projects = [] |
| | | }); |
| | | |
| | | public Task<AiChatMemoryCapabilities> GetMemoryCapabilitiesAsync(LlmPluginRuntimeConfig runtimeConfig, CancellationToken cancellationToken = default) |
| | | => Task.FromResult(new AiChatMemoryCapabilities()); |