feat.动画优化与更新界面

This commit is contained in:
lincube
2026-05-17 19:36:07 +08:00
parent a5abda62dc
commit 9404a0b347
29 changed files with 1607 additions and 71 deletions

View File

@@ -0,0 +1,38 @@
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using LanMountainDesktop.DesktopEditing;
using Xunit;
namespace LanMountainDesktop.Tests;
public sealed class DesktopEditOverlayPresenterTests
{
[Fact]
public void CompositionOffsetHelperFallsBackWhenVisualIsUnavailable()
{
var service = new CompositionVisualAnimationService(_ => null);
var target = new Border();
var result = service.TrySetOffset(target, new Point(12, 34));
Assert.False(result);
Assert.False(service.TrySetOpacity(target, 0.5));
Assert.False(service.TrySetUniformScale(target, 1.05));
}
[Fact]
public void PreviewRectUsesCanvasPlacementWhenCompositionIsUnavailable()
{
var presenter = new DesktopEditOverlayPresenter(new CompositionVisualAnimationService(_ => null));
var root = Assert.IsType<Canvas>(presenter.Root);
presenter.SetPreviewRect(new Rect(12, 34, 180, 120));
var ghost = root.Children.OfType<DesktopEditGhostView>().Single();
Assert.Equal(12, Canvas.GetLeft(ghost));
Assert.Equal(34, Canvas.GetTop(ghost));
Assert.Equal(180, ghost.Width);
Assert.Equal(120, ghost.Height);
}
}

View File

@@ -64,6 +64,63 @@ public sealed class WindowLayerIsolationTests
Assert.Contains("window.RefreshDesktopLayer()", source);
}
[Fact]
public void MainWindowDesktopLayerService_DoesNotUseFusedDesktopPassthroughBoundary()
{
var source = ReadRepositoryFile("LanMountainDesktop", "Services", "MainWindowDesktopLayerService.cs");
Assert.Contains("IMainWindowDesktopLayerService", source);
Assert.Contains("SetParent", source);
Assert.Contains("HWND_BOTTOM", source);
Assert.DoesNotContain("WindowBottomMostServiceFactory", source);
Assert.DoesNotContain("IRegionPassthroughService", source);
Assert.DoesNotContain("SetInteractiveRegions", source);
Assert.DoesNotContain("HTTRANSPARENT", source);
Assert.DoesNotContain("WS_EX_NOACTIVATE", source);
}
[Fact]
public void MainWindowRestorePaths_UseDesktopLayerAwareActivation()
{
var source = ReadRepositoryFile("LanMountainDesktop", "App.axaml.cs");
var restoreSource = ExtractMethodSource(source, "RestoreOrCreateMainWindowCore");
var trayFallbackSource = ExtractMethodSource(source, "RecoverFromTrayUnavailable");
var applyLayerSource = ExtractMethodSource(source, "ApplyMainWindowDesktopLayerRuntimeState");
Assert.Contains("ActivateOrRefreshMainWindowLayer(mainWindow", restoreSource);
Assert.DoesNotContain("Topmost = true", restoreSource);
Assert.Contains("ActivateOrRefreshMainWindowLayer(mainWindow", trayFallbackSource);
Assert.DoesNotContain("Topmost = true", trayFallbackSource);
Assert.Contains("FusedDesktopManagerServiceFactory.GetOrCreate().Shutdown()", applyLayerSource);
}
[Fact]
public void AppSettingsSnapshot_MainWindowDesktopLayerDefaultsToDisabled()
{
Assert.False(new LanMountainDesktop.Models.AppSettingsSnapshot().EnableMainWindowDesktopLayer);
}
[Fact]
public void DeveloperSettings_DefinesMutuallyExclusiveDesktopLayerToggles()
{
var viewModelSource = ReadRepositoryFile("LanMountainDesktop", "ViewModels", "SettingsViewModels.cs");
var pageSource = ReadRepositoryFile("LanMountainDesktop", "Views", "SettingsPages", "DevSettingsPage.axaml.cs");
var xamlSource = ReadRepositoryFile("LanMountainDesktop", "Views", "SettingsPages", "DevSettingsPage.axaml");
Assert.Contains("EnableMainWindowDesktopLayer", viewModelSource);
Assert.Contains("ApplyFusedDesktopPreference", viewModelSource);
Assert.Contains("ApplyMainWindowDesktopLayerPreference", viewModelSource);
Assert.Contains("nameof(AppSettingsSnapshot.EnableFusedDesktop)", viewModelSource);
Assert.Contains("nameof(AppSettingsSnapshot.EnableMainWindowDesktopLayer)", viewModelSource);
Assert.Contains("ConfirmDesktopLayerSwitchAsync", pageSource);
Assert.Contains("OnFusedDesktopToggleChanged", xamlSource);
Assert.Contains("OnMainWindowDesktopLayerToggleChanged", xamlSource);
Assert.Contains("Mode=OneWay", xamlSource);
}
private static string ReadRepositoryFile(params string[] segments)
{
var directory = new DirectoryInfo(AppContext.BaseDirectory);
@@ -85,4 +142,37 @@ public sealed class WindowLayerIsolationTests
throw new FileNotFoundException($"Could not locate repository file '{Path.Combine(segments)}'.");
}
private static string ExtractMethodSource(string source, string methodName)
{
var methodIndex = source.IndexOf($"private bool {methodName}(", StringComparison.Ordinal);
if (methodIndex < 0)
{
methodIndex = source.IndexOf($"private void {methodName}(", StringComparison.Ordinal);
}
Assert.True(methodIndex >= 0, $"Could not locate method '{methodName}'.");
var braceIndex = source.IndexOf('{', methodIndex);
Assert.True(braceIndex >= 0, $"Could not locate method body for '{methodName}'.");
var depth = 0;
for (var i = braceIndex; i < source.Length; i++)
{
if (source[i] == '{')
{
depth++;
}
else if (source[i] == '}')
{
depth--;
if (depth == 0)
{
return source.Substring(methodIndex, i - methodIndex + 1);
}
}
}
throw new InvalidOperationException($"Could not extract method '{methodName}'.");
}
}