feat: save album art to local

This commit is contained in:
Zhe Fang
2025-12-19 16:10:14 -05:00
parent 76aa5ee8d0
commit f76ef87167
6 changed files with 60 additions and 2 deletions

View File

@@ -356,7 +356,7 @@
Padding="8,4"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}"
Background="{ThemeResource LayerOnMicaBaseAltFillColorDefaultBrush}"
CornerRadius="6"
Opacity="{x:Bind ViewModel.TimelineSliderThumbOpacity, Mode=OneWay}">
<Grid.OpacityTransition>

View File

@@ -190,7 +190,7 @@ public sealed partial class NowPlayingBar : UserControl,
private void TimelineSliderOverlay_PointerEntered(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
ViewModel.TimelineSliderThumbOpacity = 0.7f;
ViewModel.TimelineSliderThumbOpacity = 1f;
}
private void TimelineSliderOverlay_PointerExited(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)

View File

@@ -1,5 +1,6 @@
using BetterLyrics.WinUI3.Hooks;
using DevWinUI;
using Microsoft.UI.Xaml;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -45,6 +46,12 @@ namespace BetterLyrics.WinUI3.Helper
public static async Task<StorageFile?> PickSaveFileAsync<T>(IDictionary<string, IList<string>> fileTypeChoices)
{
var window = WindowHook.GetWindow<T>();
return await PickSaveFileAsync(window, fileTypeChoices);
}
public static async Task<StorageFile?> PickSaveFileAsync<T>(T? window, IDictionary<string, IList<string>> fileTypeChoices)
{
if (window == null) return null;
var picker = new Windows.Storage.Pickers.FileSavePicker();

View File

@@ -1,10 +1,16 @@
// 2025/6/23 by Zhe Fang
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Hooks;
using BetterLyrics.WinUI3.Services.MediaSessionsService;
using BetterLyrics.WinUI3.Views;
using CommunityToolkit.Mvvm.Input;
using System.Collections.Generic;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;
using WinRT.Interop;
namespace BetterLyrics.WinUI3.ViewModels
{

View File

@@ -74,6 +74,17 @@
ShadowAmount="{x:Bind LyricsWindowStatus.AlbumArtLayoutSettings.CoverImageShadowAmount, Mode=OneWay}"
Source="{x:Bind ViewModel.MediaSessionsService.AlbumArtBitmapImage, Mode=OneWay}"
SwitchType="{x:Bind LyricsWindowStatus.AlbumArtAreaEffectSettings.ImageSwitchType, Mode=OneWay}" />
<Grid.ContextFlyout>
<Flyout FlyoutPresenterStyle="{StaticResource FlyoutGhostStyle}">
<StackPanel>
<StackPanel Margin="16,8">
<uc:PropertyRow x:Uid="SettingsPageWidth" Value="{x:Bind ViewModel.MediaSessionsService.AlbumArtBitmapImage.PixelWidth, Mode=OneWay}" />
<uc:PropertyRow x:Uid="SettingsPageHeight" Value="{x:Bind ViewModel.MediaSessionsService.AlbumArtBitmapImage.PixelHeight, Mode=OneWay}" />
</StackPanel>
<Button Click="SaveAlbumArtButton_Click" HorizontalAlignment="Stretch" Content="{ui:FontIcon FontFamily={StaticResource IconFontFamily}, FontSize=16, Glyph=&#xE74E;}" />
</StackPanel>
</Flyout>
</Grid.ContextFlyout>
</Grid>
<!-- Song info -->

View File

@@ -3,6 +3,7 @@
using BetterLyrics.WinUI3.Controls;
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Hooks;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Models.Settings;
using BetterLyrics.WinUI3.Services.MediaSessionsService;
@@ -17,7 +18,11 @@ using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Documents;
using Microsoft.UI.Xaml.Media;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;
namespace BetterLyrics.WinUI3.Views
{
@@ -652,5 +657,34 @@ namespace BetterLyrics.WinUI3.Views
}
}
private async void SaveAlbumArtButton_Click(object sender, RoutedEventArgs e)
{
var sourceStream = ViewModel.MediaSessionsService.AlbumArtBitmapStream;
if (sourceStream == null) return;
var window = WindowHook.GetWindows<NowPlayingWindow>().FirstOrDefault(x => x.LyricsWindowStatus == LyricsWindowStatus);
if (window == null) return;
IDictionary<string, IList<string>> fileTypeChoices = new Dictionary<string, IList<string>>()
{
{ "PNG", new List<string>() { ".png" } },
{ "JPEG", new List<string>() { ".jpg", ".jpeg" } }
};
var file = await PickerHelper.PickSaveFileAsync(window, fileTypeChoices);
if (file != null)
{
using (IRandomAccessStream destStream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
sourceStream.Seek(0);
await RandomAccessStream.CopyAsync(sourceStream, destStream);
await destStream.FlushAsync();
ToastHelper.ShowToast("ActionCompleted", null, InfoBarSeverity.Success);
}
}
}
}
}