mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
feat.启动器图片自定义
This commit is contained in:
@@ -3,6 +3,7 @@ using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Platform.Storage;
|
||||
using LanMountainDesktop.Launcher.Resources;
|
||||
using LanMountainDesktop.Launcher.Shell;
|
||||
|
||||
namespace LanMountainDesktop.Launcher.Views;
|
||||
|
||||
@@ -46,6 +47,7 @@ public partial class ErrorDebugWindow : Window
|
||||
}
|
||||
|
||||
UpdatePathDisplay(_selectedHostPath);
|
||||
RefreshBackgroundImageDisplay();
|
||||
}
|
||||
|
||||
private void InitializeComponents()
|
||||
@@ -63,6 +65,16 @@ public partial class ErrorDebugWindow : Window
|
||||
browseButton.Click += OnBrowseClick;
|
||||
}
|
||||
|
||||
if (this.FindControl<Button>("BrowseImageButton") is { } browseImageButton)
|
||||
{
|
||||
browseImageButton.Click += OnBrowseImageClick;
|
||||
}
|
||||
|
||||
if (this.FindControl<Button>("ClearImageButton") is { } clearImageButton)
|
||||
{
|
||||
clearImageButton.Click += OnClearImageClick;
|
||||
}
|
||||
|
||||
if (this.FindControl<Button>("OkButton") is { } okButton)
|
||||
{
|
||||
okButton.Click += (_, _) =>
|
||||
@@ -111,6 +123,56 @@ public partial class ErrorDebugWindow : Window
|
||||
UpdatePathDisplay(_selectedHostPath);
|
||||
}
|
||||
|
||||
private async void OnBrowseImageClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var storageProvider = StorageProvider;
|
||||
if (storageProvider is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var patterns = LauncherBackgroundService
|
||||
.GetSupportedExtensions()
|
||||
.Select(extension => "*" + extension)
|
||||
.ToArray();
|
||||
|
||||
var options = new FilePickerOpenOptions
|
||||
{
|
||||
Title = Strings.DebugDebug_SelectImageDialog,
|
||||
AllowMultiple = false,
|
||||
FileTypeFilter =
|
||||
[
|
||||
new FilePickerFileType(Strings.DebugDebug_ImageFiles)
|
||||
{
|
||||
Patterns = patterns
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var result = await storageProvider.OpenFilePickerAsync(options);
|
||||
if (result.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var saveResult = LauncherBackgroundService.SaveBackgroundImage(result[0].Path.LocalPath);
|
||||
var status = saveResult.IsSuccess
|
||||
? Strings.DebugDebug_BackgroundImageSaved
|
||||
: string.Format(Strings.DebugDebug_BackgroundImageSaveFailedFormat, saveResult.ErrorMessage ?? string.Empty);
|
||||
|
||||
RefreshBackgroundImageDisplay(status);
|
||||
}
|
||||
|
||||
private void OnClearImageClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var clearResult = LauncherBackgroundService.ClearBackgroundImage();
|
||||
var status = clearResult.IsSuccess
|
||||
? Strings.DebugDebug_BackgroundImageCleared
|
||||
: string.Format(Strings.DebugDebug_BackgroundImageSaveFailedFormat, clearResult.ErrorMessage ?? string.Empty);
|
||||
|
||||
RefreshBackgroundImageDisplay(status);
|
||||
}
|
||||
|
||||
private void UpdatePathDisplay(string? path)
|
||||
{
|
||||
if (this.FindControl<TextBlock>("PathTextBlock") is { } pathTextBlock)
|
||||
@@ -118,4 +180,46 @@ public partial class ErrorDebugWindow : Window
|
||||
pathTextBlock.Text = string.IsNullOrEmpty(path) ? Strings.DebugDebug_NotSelected : path;
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshBackgroundImageDisplay(string? statusOverride = null)
|
||||
{
|
||||
var imageInfo = LauncherBackgroundService.LoadBackgroundImage();
|
||||
|
||||
if (this.FindControl<TextBlock>("BackgroundImagePathTextBlock") is { } pathTextBlock)
|
||||
{
|
||||
pathTextBlock.Text = imageInfo.Exists && !string.IsNullOrWhiteSpace(imageInfo.FilePath)
|
||||
? imageInfo.FilePath
|
||||
: Strings.DebugDebug_BackgroundImageNotSet;
|
||||
}
|
||||
|
||||
if (this.FindControl<TextBlock>("BackgroundImageStatusTextBlock") is { } statusTextBlock)
|
||||
{
|
||||
statusTextBlock.Text = statusOverride ?? ResolveBackgroundImageStatus(imageInfo);
|
||||
}
|
||||
|
||||
if (this.FindControl<Button>("ClearImageButton") is { } clearButton)
|
||||
{
|
||||
clearButton.IsEnabled = imageInfo.Exists;
|
||||
}
|
||||
}
|
||||
|
||||
private static string ResolveBackgroundImageStatus(LauncherBackgroundService.BackgroundImageInfo imageInfo)
|
||||
{
|
||||
if (imageInfo.IsValid)
|
||||
{
|
||||
return string.Format(
|
||||
Strings.DebugDebug_BackgroundImageReadyFormat,
|
||||
imageInfo.Width,
|
||||
imageInfo.Height);
|
||||
}
|
||||
|
||||
if (imageInfo.Exists)
|
||||
{
|
||||
return string.Format(
|
||||
Strings.DebugDebug_BackgroundImageInvalidFormat,
|
||||
imageInfo.ErrorMessage ?? string.Empty);
|
||||
}
|
||||
|
||||
return Strings.DebugDebug_BackgroundImageNotSet;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user