mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
* ava12升级 * Enable centralized package versioning Add <Project> and <PropertyGroup> with <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> to Directory.Packages.props to enable centralized package version management across the repository. This allows package versions to be controlled from this single file instead of individual project files. * Migrate codebase to Avalonia 12 APIs Apply Avalonia 12 migration changes: replace SystemDecorations with WindowDecorations and remove ExtendClientAreaChromeHints/ExtendClientAreaTitleBarHeightHint usages; update BindingPlugins removal logic (no-op); switch clipboard usage to ClipboardExtensions.SetTextAsync; update Bitmap.CopyPixels calls to the new signature. Replace TextBox.Watermark with PlaceholderText, convert NumberBox styles to FANumberBox and adjust templates, change Checked/Unchecked handlers to IsCheckedChanged, and adapt FluentIcons usages (SymbolIconSource -> FASymbol/FAFont/FluentIcon equivalents). Fix MainWindow partial classes to inherit Window and correct missing variables/fields/usings. Add migration docs/specs/tasks under .trae and include a small TestFluentIcons project for icon testing. * Migrate to Avalonia 12 and Plugin SDK v5 Upgrade project to the Avalonia 12 baseline and Plugin SDK v5: centralize Avalonia packages, remove legacy WebView.Avalonia usage (use NativeWebView/WebView2 EnvironmentRequested), and update Fluent/Material icon/package usages. Bump multiple package/project versions to 5.0.0 and Avalonia 12.0.1, update plugin template and README/docs to SDK v5, and add PLUGIN_SDK_V5_MIGRATION.md. Also fix runtime/behavior bugs: make DataLocationResolver use a fixed bootstrap launcher data path and avoid recursive ResolveDataRoot; add legacy-state handling and extraction in OobeStateService; and update component settings tests to reflect migrated storage (DB/backup) and reset cache for test reloads. Various csproj, tests, and docs updated to reflect the migration and ensure build/test compatibility. * Update icon glyphs and symbol mappings Replace and refine icon sources across settings pages and controls: many FAFontIconSource glyphs were updated to specific Seagull Fluent Icons codepoints, some FASymbolIconSource usages were replaced with FAFontIconSource, and a number of symbol-to-Symbol enum mappings were adjusted (e.g. "Bell" -> AlertOn, "Shield" -> ShieldLock). Also clarified a comment in SettingsWindow and fixed a trailing newline in StudySettingsPage. Changes standardize icon visuals and bridge FluentIcons glyphs into FluentAvalonia icon sources. * fix.修复合并产生的问题。
309 lines
9.9 KiB
C#
309 lines
9.9 KiB
C#
using Avalonia;
|
|
using Avalonia.Animation;
|
|
using Avalonia.Animation.Easings;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Markup.Xaml;
|
|
using Avalonia.Media;
|
|
using Avalonia.Styling;
|
|
using LanMountainDesktop.Launcher.Models;
|
|
using LanMountainDesktop.Launcher.Services;
|
|
|
|
namespace LanMountainDesktop.Launcher.Views;
|
|
|
|
internal partial class DataLocationPromptWindow : Window
|
|
{
|
|
private readonly TaskCompletionSource<DataLocationPromptResult?> _completionSource = new();
|
|
private readonly DataLocationResolver _resolver;
|
|
private bool _isTransitioning;
|
|
|
|
public DataLocationPromptWindow()
|
|
{
|
|
AvaloniaXamlLoader.Load(this);
|
|
Loaded += OnWindowLoaded;
|
|
Opened += OnWindowOpened;
|
|
_resolver = new DataLocationResolver(AppContext.BaseDirectory);
|
|
}
|
|
|
|
internal DataLocationPromptWindow(DataLocationResolver resolver)
|
|
{
|
|
AvaloniaXamlLoader.Load(this);
|
|
Loaded += OnWindowLoaded;
|
|
Opened += OnWindowOpened;
|
|
_resolver = resolver;
|
|
}
|
|
|
|
private void OnWindowLoaded(object? sender, RoutedEventArgs e)
|
|
{
|
|
BindControls();
|
|
UpdateUiState();
|
|
}
|
|
|
|
private void BindControls()
|
|
{
|
|
var systemRadio = this.FindControl<RadioButton>("SystemRadio");
|
|
var portableRadio = this.FindControl<RadioButton>("PortableRadio");
|
|
var confirmButton = this.FindControl<Button>("ConfirmButton");
|
|
var cancelButton = this.FindControl<Button>("CancelButton");
|
|
|
|
if (systemRadio is not null)
|
|
{
|
|
systemRadio.IsCheckedChanged += OnSelectionChanged;
|
|
}
|
|
|
|
if (portableRadio is not null)
|
|
{
|
|
portableRadio.IsCheckedChanged += OnSelectionChanged;
|
|
}
|
|
|
|
if (confirmButton is not null)
|
|
{
|
|
confirmButton.Click += OnConfirmClick;
|
|
}
|
|
|
|
if (cancelButton is not null)
|
|
{
|
|
cancelButton.Click += OnCancelClick;
|
|
}
|
|
}
|
|
|
|
private void UpdateUiState()
|
|
{
|
|
var systemPathText = this.FindControl<TextBlock>("SystemPathText");
|
|
var portablePathText = this.FindControl<TextBlock>("PortablePathText");
|
|
var adminWarningBanner = this.FindControl<Border>("AdminWarningBanner");
|
|
var portableRadio = this.FindControl<RadioButton>("PortableRadio");
|
|
var migrationInfoBorder = this.FindControl<Border>("MigrationInfoBorder");
|
|
var migrationInfoText = this.FindControl<TextBlock>("MigrationInfoText");
|
|
|
|
if (systemPathText is not null)
|
|
{
|
|
systemPathText.Text = _resolver.DefaultSystemDataPath;
|
|
}
|
|
|
|
if (portablePathText is not null)
|
|
{
|
|
portablePathText.Text = _resolver.DefaultPortableDataPath;
|
|
}
|
|
|
|
var portableAllowed = _resolver.IsPortableModeAllowed();
|
|
|
|
if (adminWarningBanner is not null)
|
|
{
|
|
adminWarningBanner.IsVisible = !portableAllowed;
|
|
}
|
|
|
|
if (portableRadio is not null)
|
|
{
|
|
portableRadio.IsEnabled = portableAllowed;
|
|
}
|
|
|
|
var hasExistingData = _resolver.HasExistingSystemData();
|
|
if (migrationInfoBorder is not null)
|
|
{
|
|
migrationInfoBorder.IsVisible = hasExistingData;
|
|
}
|
|
|
|
if (migrationInfoText is not null && hasExistingData)
|
|
{
|
|
migrationInfoText.Text = "Existing system data was detected. Choosing portable mode will migrate the current data automatically.";
|
|
}
|
|
}
|
|
|
|
private void OnSelectionChanged(object? sender, RoutedEventArgs e)
|
|
{
|
|
var systemRadio = this.FindControl<RadioButton>("SystemRadio");
|
|
var portableRadio = this.FindControl<RadioButton>("PortableRadio");
|
|
var systemBorder = this.FindControl<Border>("SystemOptionBorder");
|
|
var portableBorder = this.FindControl<Border>("PortableOptionBorder");
|
|
|
|
var isSystem = systemRadio?.IsChecked == true;
|
|
var isPortable = portableRadio?.IsChecked == true;
|
|
|
|
if (systemBorder is not null)
|
|
{
|
|
systemBorder.BorderBrush = isSystem
|
|
? Application.Current?.FindResource("AccentFillColorDefaultBrush") as IBrush
|
|
: Application.Current?.FindResource("CardStrokeColorDefaultBrush") as IBrush;
|
|
systemBorder.BorderThickness = isSystem ? new Thickness(2) : new Thickness(1);
|
|
}
|
|
|
|
if (portableBorder is not null)
|
|
{
|
|
portableBorder.BorderBrush = isPortable
|
|
? Application.Current?.FindResource("AccentFillColorDefaultBrush") as IBrush
|
|
: Application.Current?.FindResource("CardStrokeColorDefaultBrush") as IBrush;
|
|
portableBorder.BorderThickness = isPortable ? new Thickness(2) : new Thickness(1);
|
|
}
|
|
}
|
|
|
|
private async void OnConfirmClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
if (_isTransitioning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_isTransitioning = true;
|
|
|
|
var portableRadio = this.FindControl<RadioButton>("PortableRadio");
|
|
var selectedMode = portableRadio?.IsChecked == true
|
|
? DataLocationMode.Portable
|
|
: DataLocationMode.System;
|
|
|
|
var migrateExistingData = selectedMode == DataLocationMode.Portable && _resolver.HasExistingSystemData();
|
|
|
|
try
|
|
{
|
|
await PlayExitAnimationAsync();
|
|
_completionSource.TrySetResult(new DataLocationPromptResult
|
|
{
|
|
SelectedMode = selectedMode,
|
|
MigrateExistingData = migrateExistingData
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Warn($"Error during data location prompt exit animation: {ex.Message}");
|
|
_completionSource.TrySetResult(new DataLocationPromptResult
|
|
{
|
|
SelectedMode = selectedMode,
|
|
MigrateExistingData = migrateExistingData
|
|
});
|
|
}
|
|
}
|
|
|
|
private async void OnCancelClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
if (_isTransitioning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_isTransitioning = true;
|
|
|
|
try
|
|
{
|
|
await PlayExitAnimationAsync();
|
|
_completionSource.TrySetResult(null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Warn($"Error during data location prompt cancel: {ex.Message}");
|
|
_completionSource.TrySetResult(null);
|
|
}
|
|
}
|
|
|
|
private async void OnWindowOpened(object? sender, EventArgs e)
|
|
{
|
|
await PlayEntranceAnimationAsync();
|
|
}
|
|
|
|
private async Task PlayEntranceAnimationAsync()
|
|
{
|
|
try
|
|
{
|
|
var contentGrid = this.FindControl<Grid>("ContentGrid");
|
|
if (contentGrid is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var translateTransform = contentGrid.RenderTransform as TranslateTransform ?? new TranslateTransform();
|
|
contentGrid.RenderTransform = translateTransform;
|
|
|
|
contentGrid.Opacity = 0;
|
|
translateTransform.Y = 24;
|
|
|
|
var fadeInAnimation = new Animation
|
|
{
|
|
Duration = TimeSpan.FromMilliseconds(500),
|
|
Easing = new CubicEaseOut(),
|
|
FillMode = FillMode.Forward,
|
|
Children =
|
|
{
|
|
new KeyFrame
|
|
{
|
|
Setters = { new Setter(OpacityProperty, 0.0) },
|
|
KeyTime = TimeSpan.FromMilliseconds(0)
|
|
},
|
|
new KeyFrame
|
|
{
|
|
Setters = { new Setter(OpacityProperty, 1.0) },
|
|
KeyTime = TimeSpan.FromMilliseconds(500)
|
|
}
|
|
}
|
|
};
|
|
|
|
var slideUpAnimation = new Animation
|
|
{
|
|
Duration = TimeSpan.FromMilliseconds(500),
|
|
Easing = new CubicEaseOut(),
|
|
FillMode = FillMode.Forward,
|
|
Children =
|
|
{
|
|
new KeyFrame
|
|
{
|
|
Setters = { new Setter(TranslateTransform.YProperty, 24.0) },
|
|
KeyTime = TimeSpan.FromMilliseconds(0)
|
|
},
|
|
new KeyFrame
|
|
{
|
|
Setters = { new Setter(TranslateTransform.YProperty, 0.0) },
|
|
KeyTime = TimeSpan.FromMilliseconds(500)
|
|
}
|
|
}
|
|
};
|
|
|
|
await Task.WhenAll(
|
|
fadeInAnimation.RunAsync(contentGrid),
|
|
slideUpAnimation.RunAsync(translateTransform));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Warn($"Error playing data location prompt entrance animation: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private async Task PlayExitAnimationAsync()
|
|
{
|
|
try
|
|
{
|
|
var contentGrid = this.FindControl<Grid>("ContentGrid");
|
|
if (contentGrid is null)
|
|
{
|
|
await Task.Delay(150);
|
|
return;
|
|
}
|
|
|
|
var fadeOutAnimation = new Animation
|
|
{
|
|
Duration = TimeSpan.FromMilliseconds(200),
|
|
Easing = new CubicEaseIn(),
|
|
FillMode = FillMode.Forward,
|
|
Children =
|
|
{
|
|
new KeyFrame
|
|
{
|
|
Setters = { new Setter(OpacityProperty, 1.0) },
|
|
KeyTime = TimeSpan.FromMilliseconds(0)
|
|
},
|
|
new KeyFrame
|
|
{
|
|
Setters = { new Setter(OpacityProperty, 0.0) },
|
|
KeyTime = TimeSpan.FromMilliseconds(200)
|
|
}
|
|
}
|
|
};
|
|
|
|
await fadeOutAnimation.RunAsync(contentGrid);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Warn($"Error playing data location prompt exit animation: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
internal Task<DataLocationPromptResult?> WaitForChoiceAsync() => _completionSource.Task;
|
|
}
|