mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
* fix.hy3试图修复中 * Resolve dev paths and fix splash UI thread Compute a solutionRoot and expand development search paths (LanMountainDesktop and dev-test) in DeploymentLocator, add logging when scanning/finding hosts, and return distinct full paths. Ensure backward-compatible path checks. Fix cross-thread UI calls: invoke splashWindow.DismissAsync on the UI thread in LauncherFlowCoordinator, and make SplashWindow.DismissAsync ensure it runs on the UI thread before closing (simplified Close call). These changes improve development host discovery and prevent UI-thread access issues during shutdown. * Add configurable data location (portable/system) Introduce support for choosing and resolving the application's data root (system user dir vs. portable app folder). Adds DataLocationConfig model, DataLocationResolver (load/save/resolve/migrate), a UI prompt (DataLocationPromptWindow) and an OOBE step (DataLocationOobeStep) to let users pick and optionally migrate existing data. Wire the chosen data root into the launcher flow and host launch plan (forwarded via --data-root and LMD_DATA_ROOT), and add AppDataPathProvider to let runtime services read the effective data root (initialized in Program.Main). Update various services (logging, settings, DB, plugin/market, startup registry, etc.) to use the new provider/resolver and register the config type in the JSON context. This enables portable installs, safe migration, and runtime overrides via CLI or environment variable. * Add dev/debug startup flow and launch profiles Handle design-time initialization and add a developer debug startup path: App now skips normal startup when in design mode and shows a DevDebugWindow when running in debug (unless a preview or apply-update command). CommandContext.IsDebugMode is extended to include DOTNET_ENVIRONMENT=Development via a new IsDevelopmentEnvironment helper. Program.Main and BuildAvaloniaApp are made public to aid tooling. Added multiple launchSettings profiles for debug and preview commands that set DOTNET_ENVIRONMENT=Development to simplify IDE debugging and UI previewing. * Simplify splash to fade; add themed about banners Simplify splash startup visuals by removing the multi-mode/slide behavior and always using a fade animation. Update App to create SplashWindow without a StartupVisualMode parameter and remove related fields, layout configuration, slide animation, and easing helpers from SplashWindow. Clean up unused using. Replace the single about_banner asset with theme-aware variants (about_banner_dark.png and about_banner_light.png), delete the old about_banner.png, and update AboutSettingsPage to use a DynamicResource ImageBrush (AboutBannerBrush) that selects the appropriate banner per theme. * Use AppJsonContext for startup state serialization Switch serialization to the source-generated System.Text.Json context: add JsonSerializable(typeof(StartupAttemptRecord)) to AppJsonContext and replace the previous JsonSerializerOptions-based Serialize/Deserialize calls with AppJsonContext.Default.StartupAttemptRecord. Also remove the now-unused SerializerOptions field. Additionally, update .gitignore to exclude /test-aot-publish. * Add OOBE redesign, theme & data location support Introduce a redesigned OOBE flow and data-location/theme support across the launcher. Adds a new ThemeService for applying light/dark and accent colors; integrates FluentIcons.Avalonia package for icons. Overhauls OobeWindow (UX animations, typing effect, multi-step theme and data-location pages, Monet options, and final welcome step) and its code-behind to handle step navigation, accent selection, and data-location resolution. Adds DataLocation UI and handlers (DataLocationPromptWindow changes, DataLocation resolver usage) and wires a DevDebug UI for toggling/opening the data-location page. UpdateEngineService now resolves the launcher root via DataLocationResolver. Misc: update various view models, localization entries and remove TrimmerRoots.xml. * Refactor data location paths and add background service Refactor DataLocationResolver to centralize data path resolution (ResolveLauncherDataPath, ResolveDesktopDataPath, ResolveConfigPath, ResolveLauncherLogsPath, ResolveLauncherStatePath) and replace usages of the previous ".launcher" layout with a "Launcher" folder. Update API: LoadConfig/SaveConfig reorganized and ApplyLocationChoice now accepts an optional custom path and migration flag; migration logic updated accordingly. Update dependent services and views (Logger, DeploymentLocator, UpdateEngineService, OobeStateService, StartupAttemptRegistry, LauncherDebugSettingsStore, OobeWindow) to use the new resolver APIs and paths. Add LauncherBackgroundService to load/validate/cache a custom splash background image and wire it into SplashWindow (AXAML/Axaml.cs) with UI placeholders and overlay. Misc: minor cleanup of Oobe/Splash XAML and related code adjustments and logging improvements.
175 lines
5.5 KiB
C#
175 lines
5.5 KiB
C#
using Avalonia.Media.Imaging;
|
|
|
|
namespace LanMountainDesktop.Launcher.Services;
|
|
|
|
/// <summary>
|
|
/// 启动器背景图片服务
|
|
/// </summary>
|
|
internal static class LauncherBackgroundService
|
|
{
|
|
private const string PictureFileName = "Launcher Picture";
|
|
private const long MaxFileSize = 10 * 1024 * 1024; // 10MB
|
|
private const double WindowAspectRatio = 7.0 / 5.0; // 700:500
|
|
private const double AspectRatioTolerance = 0.15; // 15% 误差
|
|
|
|
private static Bitmap? _cachedBitmap;
|
|
private static string? _cachedPath;
|
|
|
|
/// <summary>
|
|
/// 背景图片信息
|
|
/// </summary>
|
|
public record BackgroundImageInfo
|
|
{
|
|
public required bool Exists { get; init; }
|
|
public required bool IsValid { get; init; }
|
|
public string? FilePath { get; init; }
|
|
public Bitmap? Bitmap { get; init; }
|
|
public int Width { get; init; }
|
|
public int Height { get; init; }
|
|
public double AspectRatio { get; init; }
|
|
public string? ErrorMessage { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载背景图片
|
|
/// </summary>
|
|
public static BackgroundImageInfo LoadBackgroundImage()
|
|
{
|
|
try
|
|
{
|
|
var resolver = new DataLocationResolver(AppContext.BaseDirectory);
|
|
var launcherPath = resolver.ResolveLauncherDataPath();
|
|
|
|
// 查找图片文件
|
|
var imagePath = FindImageFile(launcherPath);
|
|
if (imagePath == null)
|
|
{
|
|
return new BackgroundImageInfo
|
|
{
|
|
Exists = false,
|
|
IsValid = false,
|
|
ErrorMessage = "未找到背景图片文件"
|
|
};
|
|
}
|
|
|
|
// 检查文件大小
|
|
var fileInfo = new FileInfo(imagePath);
|
|
if (fileInfo.Length > MaxFileSize)
|
|
{
|
|
return new BackgroundImageInfo
|
|
{
|
|
Exists = true,
|
|
IsValid = false,
|
|
FilePath = imagePath,
|
|
ErrorMessage = $"图片文件过大 ({fileInfo.Length / 1024 / 1024}MB > 10MB)"
|
|
};
|
|
}
|
|
|
|
// 使用缓存
|
|
if (_cachedBitmap != null && _cachedPath == imagePath)
|
|
{
|
|
return new BackgroundImageInfo
|
|
{
|
|
Exists = true,
|
|
IsValid = true,
|
|
FilePath = imagePath,
|
|
Bitmap = _cachedBitmap,
|
|
Width = _cachedBitmap.PixelSize.Width,
|
|
Height = _cachedBitmap.PixelSize.Height,
|
|
AspectRatio = (double)_cachedBitmap.PixelSize.Width / _cachedBitmap.PixelSize.Height
|
|
};
|
|
}
|
|
|
|
// 加载图片
|
|
var bitmap = new Bitmap(imagePath);
|
|
var width = bitmap.PixelSize.Width;
|
|
var height = bitmap.PixelSize.Height;
|
|
var aspectRatio = (double)width / height;
|
|
|
|
// 校验比例
|
|
var ratioDiff = Math.Abs(aspectRatio - WindowAspectRatio) / WindowAspectRatio;
|
|
if (ratioDiff > AspectRatioTolerance)
|
|
{
|
|
bitmap.Dispose();
|
|
return new BackgroundImageInfo
|
|
{
|
|
Exists = true,
|
|
IsValid = false,
|
|
FilePath = imagePath,
|
|
Width = width,
|
|
Height = height,
|
|
AspectRatio = aspectRatio,
|
|
ErrorMessage = $"图片比例不符合要求 ({aspectRatio:F2},需要接近 {WindowAspectRatio:F2})"
|
|
};
|
|
}
|
|
|
|
// 缓存图片
|
|
_cachedBitmap = bitmap;
|
|
_cachedPath = imagePath;
|
|
|
|
Logger.Info($"[LauncherBackground] 背景图片加载成功: {imagePath} ({width}x{height}, 比例: {aspectRatio:F2})");
|
|
|
|
return new BackgroundImageInfo
|
|
{
|
|
Exists = true,
|
|
IsValid = true,
|
|
FilePath = imagePath,
|
|
Bitmap = bitmap,
|
|
Width = width,
|
|
Height = height,
|
|
AspectRatio = aspectRatio
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Warn($"[LauncherBackground] 加载背景图片失败: {ex.Message}");
|
|
return new BackgroundImageInfo
|
|
{
|
|
Exists = false,
|
|
IsValid = false,
|
|
ErrorMessage = $"加载失败: {ex.Message}"
|
|
};
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查找图片文件
|
|
/// </summary>
|
|
private static string? FindImageFile(string directory)
|
|
{
|
|
var extensions = new[] { ".png", ".jpg", ".jpeg", ".bmp", ".gif", ".webp" };
|
|
|
|
foreach (var ext in extensions)
|
|
{
|
|
var path = Path.Combine(directory, PictureFileName + ext);
|
|
if (File.Exists(path))
|
|
{
|
|
return path;
|
|
}
|
|
}
|
|
|
|
// 也尝试不带扩展名的匹配(如果文件本身就有扩展名)
|
|
var files = Directory.GetFiles(directory, PictureFileName + ".*");
|
|
foreach (var file in files)
|
|
{
|
|
var ext = Path.GetExtension(file).ToLowerInvariant();
|
|
if (extensions.Contains(ext))
|
|
{
|
|
return file;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清除缓存
|
|
/// </summary>
|
|
public static void ClearCache()
|
|
{
|
|
_cachedBitmap?.Dispose();
|
|
_cachedBitmap = null;
|
|
_cachedPath = null;
|
|
}
|
|
}
|