2026-04-16 01:59:21 +08:00
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
|
using Avalonia.Markup.Xaml;
|
2026-04-16 19:28:58 +08:00
|
|
|
|
using Avalonia.Threading;
|
2026-04-16 14:17:46 +08:00
|
|
|
|
using LanMountainDesktop.Launcher.Services;
|
2026-04-16 01:59:21 +08:00
|
|
|
|
|
|
|
|
|
|
namespace LanMountainDesktop.Launcher.Views;
|
|
|
|
|
|
|
2026-04-16 19:28:58 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 启动画面窗口 - 简洁设计
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class SplashWindow : Window, ISplashStageReporter
|
2026-04-16 01:59:21 +08:00
|
|
|
|
{
|
|
|
|
|
|
public SplashWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
AvaloniaXamlLoader.Load(this);
|
|
|
|
|
|
}
|
2026-04-16 14:17:46 +08:00
|
|
|
|
|
2026-04-16 19:28:58 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新进度和状态
|
|
|
|
|
|
/// </summary>
|
2026-04-16 14:17:46 +08:00
|
|
|
|
public void Report(string stage, string message)
|
|
|
|
|
|
{
|
2026-04-16 19:28:58 +08:00
|
|
|
|
Dispatcher.UIThread.Post(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var statusText = this.GetControl<TextBlock>("StatusText");
|
|
|
|
|
|
var progressIndicator = this.GetControl<ProgressBar>("ProgressIndicator");
|
2026-04-16 14:17:46 +08:00
|
|
|
|
|
2026-04-16 19:28:58 +08:00
|
|
|
|
// 更新状态文本
|
|
|
|
|
|
statusText.Text = message;
|
2026-04-16 14:17:46 +08:00
|
|
|
|
|
2026-04-16 19:28:58 +08:00
|
|
|
|
// 根据阶段更新进度
|
|
|
|
|
|
var progress = ResolveProgress(stage);
|
|
|
|
|
|
if (progress > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
progressIndicator.IsIndeterminate = false;
|
|
|
|
|
|
progressIndicator.Value = progress;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
progressIndicator.IsIndeterminate = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-04-16 14:17:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-16 19:28:58 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新进度(0-100)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void UpdateProgress(int percent, string? message = null)
|
2026-04-16 14:17:46 +08:00
|
|
|
|
{
|
2026-04-16 19:28:58 +08:00
|
|
|
|
Dispatcher.UIThread.Post(() =>
|
2026-04-16 14:17:46 +08:00
|
|
|
|
{
|
2026-04-16 19:28:58 +08:00
|
|
|
|
var statusText = this.GetControl<TextBlock>("StatusText");
|
|
|
|
|
|
var progressIndicator = this.GetControl<ProgressBar>("ProgressIndicator");
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(message))
|
2026-04-16 14:17:46 +08:00
|
|
|
|
{
|
2026-04-16 19:28:58 +08:00
|
|
|
|
statusText.Text = message;
|
2026-04-16 14:17:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-16 19:28:58 +08:00
|
|
|
|
progressIndicator.IsIndeterminate = false;
|
|
|
|
|
|
progressIndicator.Value = Math.Clamp(percent, 0, 100);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新状态文本
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void UpdateStatus(string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
Dispatcher.UIThread.Post(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var statusText = this.GetControl<TextBlock>("StatusText");
|
|
|
|
|
|
statusText.Text = message;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据阶段名称解析进度值
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static int ResolveProgress(string stage)
|
|
|
|
|
|
{
|
|
|
|
|
|
return stage.ToLowerInvariant() switch
|
|
|
|
|
|
{
|
|
|
|
|
|
"initializing" => 10,
|
|
|
|
|
|
"update" => 30,
|
|
|
|
|
|
"plugins" => 50,
|
|
|
|
|
|
"launch" => 70,
|
|
|
|
|
|
"ready" => 100,
|
|
|
|
|
|
_ => 0
|
|
|
|
|
|
};
|
2026-04-16 14:17:46 +08:00
|
|
|
|
}
|
2026-04-16 01:59:21 +08:00
|
|
|
|
}
|