mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
fix.修复了窗口问题,以及多次显示圆角调节选项的问题。
This commit is contained in:
@@ -65,6 +65,22 @@ public sealed class MaterialColorSettingsPageViewModelTests
|
||||
Assert.Equal(1, facade.ThemeSaveCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UserSelection_SystemMaterialModeRequestsRestart()
|
||||
{
|
||||
var facade = new FakeSettingsFacade(CreateThemeState(ThemeAppearanceValues.MaterialNone));
|
||||
var materialService = new FakeMaterialColorService(CreateSnapshot(ThemeAppearanceValues.MaterialNone));
|
||||
var viewModel = new MaterialColorSettingsPageViewModel(facade, materialService);
|
||||
string? restartReason = null;
|
||||
viewModel.RestartRequested += reason => restartReason = reason;
|
||||
|
||||
viewModel.SelectedSystemMaterialMode = viewModel.SystemMaterialModes.Single(option =>
|
||||
option.Value == ThemeAppearanceValues.MaterialMica);
|
||||
|
||||
Assert.Equal(viewModel.SystemMaterialRestartMessage, restartReason);
|
||||
Assert.False(string.IsNullOrWhiteSpace(restartReason));
|
||||
}
|
||||
|
||||
private static ThemeAppearanceSettingsState CreateThemeState(string materialMode)
|
||||
{
|
||||
return new ThemeAppearanceSettingsState(
|
||||
|
||||
103
LanMountainDesktop.Tests/SystemChromeModeTests.cs
Normal file
103
LanMountainDesktop.Tests/SystemChromeModeTests.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using Xunit;
|
||||
|
||||
namespace LanMountainDesktop.Tests;
|
||||
|
||||
public sealed class SystemChromeModeTests
|
||||
{
|
||||
[Fact]
|
||||
public void SettingsWindow_SystemChromeUsesNativeDecorations()
|
||||
{
|
||||
var source = ReadRepositoryFile("LanMountainDesktop", "Views", "SettingsWindow.axaml.cs");
|
||||
var applyChromeMode = ExtractMethodSource(source, "ApplyChromeMode");
|
||||
var onLoaded = ExtractMethodSource(source, "OnLoaded");
|
||||
|
||||
Assert.Contains("_useSystemChrome = useSystemChrome || OperatingSystem.IsMacOS();", applyChromeMode);
|
||||
Assert.Contains("WindowDecorations = WindowDecorations.Full;", applyChromeMode);
|
||||
Assert.Contains("ExtendClientAreaToDecorationsHint = !_useSystemChrome;", applyChromeMode);
|
||||
Assert.Contains("ExtendClientAreaTitleBarHeightHint = _useSystemChrome ? 0d : CustomTitleBarHeight;", applyChromeMode);
|
||||
Assert.Contains("TitleBar.ExtendsContentIntoTitleBar = !_useSystemChrome;", applyChromeMode);
|
||||
Assert.Contains("WindowTitleBarHost.IsVisible = false;", applyChromeMode);
|
||||
Assert.Contains("WindowTitleBarHost.IsVisible = true;", applyChromeMode);
|
||||
Assert.DoesNotContain("TitleBar.ExtendsContentIntoTitleBar = true;", onLoaded);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ComponentEditorWindow_SystemChromeUsesNativeDecorations()
|
||||
{
|
||||
var source = ReadRepositoryFile("LanMountainDesktop", "Views", "ComponentEditorWindow.axaml.cs");
|
||||
var applyChromeMode = ExtractMethodSource(source, "ApplyChromeMode");
|
||||
|
||||
Assert.Contains("var preferSystemChrome = useSystemChrome || OperatingSystem.IsMacOS();", applyChromeMode);
|
||||
Assert.Contains("WindowDecorations = WindowDecorations.Full;", applyChromeMode);
|
||||
Assert.Contains("ExtendClientAreaToDecorationsHint = false;", applyChromeMode);
|
||||
Assert.Contains("ExtendClientAreaTitleBarHeightHint = 0d;", applyChromeMode);
|
||||
Assert.Contains("CustomTitleBarHost.IsVisible = false;", applyChromeMode);
|
||||
Assert.Contains("WindowDecorations = WindowDecorations.BorderOnly;", applyChromeMode);
|
||||
Assert.Contains("ExtendClientAreaToDecorationsHint = true;", applyChromeMode);
|
||||
Assert.Contains("CustomTitleBarHost.IsVisible = true;", applyChromeMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SavingSystemChromeSynchronizesWindowsPatcherState()
|
||||
{
|
||||
var source = ReadRepositoryFile("LanMountainDesktop", "Services", "Settings", "SettingsDomainServices.cs");
|
||||
|
||||
Assert.Contains("if (OperatingSystem.IsWindows())", source);
|
||||
Assert.Contains("LanMountainDesktop.Platform.Windows.ChromePatchState.UseSystemChrome = state.UseSystemChrome;", source);
|
||||
}
|
||||
|
||||
private static string ReadRepositoryFile(params string[] segments)
|
||||
{
|
||||
var directory = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
while (directory is not null)
|
||||
{
|
||||
var candidate = Path.Combine(new[] { directory.FullName }.Concat(segments).ToArray());
|
||||
if (File.Exists(candidate))
|
||||
{
|
||||
return File.ReadAllText(candidate);
|
||||
}
|
||||
|
||||
if (File.Exists(Path.Combine(directory.FullName, "LanMountainDesktop.slnx")))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
directory = directory.Parent;
|
||||
}
|
||||
|
||||
throw new FileNotFoundException($"Could not locate repository file '{Path.Combine(segments)}'.");
|
||||
}
|
||||
|
||||
private static string ExtractMethodSource(string source, string methodName)
|
||||
{
|
||||
var methodIndex = source.IndexOf($"private void {methodName}(", StringComparison.Ordinal);
|
||||
if (methodIndex < 0)
|
||||
{
|
||||
methodIndex = source.IndexOf($"public 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}'.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user