diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3 (Package)/Package.appxmanifest b/BetterLyrics.WinUI3/BetterLyrics.WinUI3 (Package)/Package.appxmanifest index 03b978d..6339c8b 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3 (Package)/Package.appxmanifest +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3 (Package)/Package.appxmanifest @@ -12,7 +12,7 @@ + Version="1.0.127.0" /> diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj index 48d0aee..a28c12b 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj @@ -109,9 +109,13 @@ - + + + + + diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Extensions/StringExtensions.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Extensions/StringExtensions.cs index 19c3cc0..282ec17 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Extensions/StringExtensions.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Extensions/StringExtensions.cs @@ -27,7 +27,7 @@ namespace BetterLyrics.WinUI3.Extensions { public string[] SplitByCommonSplitter() { - var splitter = _splitter.Where(str.Contains).FirstOrDefault(); + var splitter = _splitter.FirstOrDefault(str.Contains); if (splitter != null) { return str.Split(splitter); diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LyricsParser.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LyricsParser.cs index 5ba7d07..d8df627 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LyricsParser.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LyricsParser.cs @@ -24,11 +24,10 @@ namespace BetterLyrics.WinUI3.Helper var overridenAlbum = songInfo.Album; var found = mappedSongSearchQueries - .Where(x => + .FirstOrDefault(x => x.OriginalTitle == overridenTitle && x.OriginalArtist == overridenArtist.Join(ATL.Settings.DisplayValueSeparator.ToString()) && - x.OriginalAlbum == overridenAlbum) - .FirstOrDefault(); + x.OriginalAlbum == overridenAlbum); if (found != null) { @@ -119,7 +118,7 @@ namespace BetterLyrics.WinUI3.Helper private void FillRomanizationLyricsData() { - var chinese = LyricsDataArr.Where(x => x.LanguageCode == "zh").FirstOrDefault(); + var chinese = LyricsDataArr.FirstOrDefault(x => x.LanguageCode == "zh"); if (chinese != null) { LyricsDataArr.Add(new LyricsData @@ -157,7 +156,7 @@ namespace BetterLyrics.WinUI3.Helper }).ToList() }); } - var japanese = LyricsDataArr.Where(x => x.LanguageCode == "ja").FirstOrDefault(); + var japanese = LyricsDataArr.FirstOrDefault(x => x.LanguageCode == "ja"); if (japanese != null) { LyricsDataArr.Add(new LyricsData diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/STATaskHelper.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/STATaskHelper.cs index 8f2978e..e212e46 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/STATaskHelper.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/STATaskHelper.cs @@ -14,7 +14,7 @@ namespace BetterLyrics.WinUI3.Helper /// 返回类型 /// 要执行的函数 /// 一个 Task,其结果是函数的返回值 - public static Task RunAsStaTask(Func func) + public static Task RunAsSTATask(Func func) { var tcs = new TaskCompletionSource(); var thread = new Thread(() => @@ -42,9 +42,9 @@ namespace BetterLyrics.WinUI3.Helper /// /// 要执行的 Action /// 一个 Task - public static Task RunAsStaTask(Action action) + public static Task RunAsSTATask(Action action) { - return RunAsStaTask(() => + return RunAsSTATask(() => { action(); return true; // 返回一个虚拟结果 diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Hooks/AppHook.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Hooks/AppHook.cs index 639df23..68bdbf2 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Hooks/AppHook.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Hooks/AppHook.cs @@ -70,7 +70,8 @@ namespace BetterLyrics.WinUI3.Hooks catch { var shellFolder = new ShellFolder(KNOWNFOLDERID.FOLDERID_AppsFolder); - return shellFolder.Where(x => x.ParsingName?.Contains(aumid) == true).FirstOrDefault(); + var found = shellFolder.FirstOrDefault(x => x.ParsingName?.EndsWith(aumid) == true); + return found; } } diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/MediaSourceProviderInfo.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/MediaSourceProviderInfo.cs index 0c8912c..c6ecd8f 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/MediaSourceProviderInfo.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/MediaSourceProviderInfo.cs @@ -115,24 +115,33 @@ namespace BetterLyrics.WinUI3.Models partial void OnProviderChanged(string value) { - var shellItem = AppHook.GetShellItem(Provider); - if (shellItem != null) + var dispatcherQueue = App.Current.Resources.DispatcherQueue; + + STATaskHelper.RunAsSTATask(() => { - DisplayName = AppHook.GetDisplayName(shellItem); - - var icon = AppHook.GetIcon(shellItem); - - shellItem.Dispose(); - - if (icon != null) + var shellItem = AppHook.GetShellItem(Provider); + if (shellItem != null) { - App.Current.Resources.DispatcherQueue.TryEnqueue(async () => - { - Logo = await AppHook.ToBitmapImageAsync(icon.Value); - }); - } - } + var displayName = AppHook.GetDisplayName(shellItem); + dispatcherQueue.TryEnqueue(async () => + { + DisplayName = displayName; + }); + + var icon = AppHook.GetIcon(shellItem); + + shellItem.Dispose(); + + if (icon != null) + { + dispatcherQueue.TryEnqueue(async () => + { + Logo = await AppHook.ToBitmapImageAsync(icon.Value); + }); + } + } + }); } } } diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/AlbumArtSearchService/AlbumArtSearchService.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/AlbumArtSearchService/AlbumArtSearchService.cs index 1d47ae7..c7c4a22 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/AlbumArtSearchService/AlbumArtSearchService.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/AlbumArtSearchService/AlbumArtSearchService.cs @@ -39,7 +39,7 @@ namespace BetterLyrics.WinUI3.Services.AlbumArtSearchService try { - foreach (var provider in _settingsService.AppSettings.MediaSourceProvidersInfo.Where(x => x.Provider == songInfo.PlayerId).FirstOrDefault()?.AlbumArtSearchProvidersInfo ?? []) + foreach (var provider in _settingsService.AppSettings.MediaSourceProvidersInfo.FirstOrDefault(x => x.Provider == songInfo.PlayerId)?.AlbumArtSearchProvidersInfo ?? []) { if (!provider.IsEnabled) { diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/LyricsSearchService/LyricsSearchService.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/LyricsSearchService/LyricsSearchService.cs index 9a985bb..038df98 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/LyricsSearchService/LyricsSearchService.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/LyricsSearchService/LyricsSearchService.cs @@ -102,11 +102,10 @@ namespace BetterLyrics.WinUI3.Services.LyricsSearchService _logger.LogInformation("SearchSmartlyAsync {SongInfo}", songInfo); var found = _settingsService.AppSettings.MappedSongSearchQueries - .Where(x => + .FirstOrDefault(x => x.OriginalTitle == overridenTitle && x.OriginalArtist == overridenArtists.Join(ATL.Settings.DisplayValueSeparator.ToString()) && - x.OriginalAlbum == overridenAlbum) - .FirstOrDefault(); + x.OriginalAlbum == overridenAlbum); if (found != null) { @@ -138,7 +137,7 @@ namespace BetterLyrics.WinUI3.Services.LyricsSearchService } } - foreach (var provider in _settingsService.AppSettings.MediaSourceProvidersInfo.Where(x => x.Provider == songInfo.PlayerId).FirstOrDefault()?.LyricsSearchProvidersInfo ?? []) + foreach (var provider in _settingsService.AppSettings.MediaSourceProvidersInfo.FirstOrDefault(x => x.Provider == songInfo.PlayerId)?.LyricsSearchProvidersInfo ?? []) { if (!provider.IsEnabled) { diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/MediaSessionsService/MediaSessionsService.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/MediaSessionsService/MediaSessionsService.cs index 1a206c9..29e3ce9 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/MediaSessionsService/MediaSessionsService.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/MediaSessionsService/MediaSessionsService.cs @@ -326,12 +326,12 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService else if (PlayerIDMatcher.IsNeteaseFamily(sessionId)) { songId = mediaProperties?.Genres - .Where(x => x.StartsWith(ExtendedGenreFiled.NetEaseCloudMusicTrackID))?.FirstOrDefault()? + .FirstOrDefault(x => x.StartsWith(ExtendedGenreFiled.NetEaseCloudMusicTrackID))? .Replace(ExtendedGenreFiled.NetEaseCloudMusicTrackID, ""); } var linkedFileName = mediaProperties?.Genres - .Where(x => x.StartsWith(ExtendedGenreFiled.FileName))?.FirstOrDefault()? + .FirstOrDefault(x => x.StartsWith(ExtendedGenreFiled.FileName))? .Replace(ExtendedGenreFiled.FileName, ""); CurrentSongInfo = new SongInfo diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsSearchControlViewModel.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsSearchControlViewModel.cs index 44a51fb..802445a 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsSearchControlViewModel.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsSearchControlViewModel.cs @@ -90,12 +90,12 @@ namespace BetterLyrics.WinUI3.ViewModels } var found = AppSettings.MappedSongSearchQueries - .Where(x => + .FirstOrDefault(x => x.OriginalTitle == _mediaSessionsService.CurrentSongInfo.Title && x.OriginalArtist == _mediaSessionsService.CurrentSongInfo.DisplayArtists && x.OriginalAlbum == _mediaSessionsService.CurrentSongInfo.Album); - return found.FirstOrDefault(); + return found; } [RelayCommand] diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/MusicGalleryViewModel.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/MusicGalleryViewModel.cs index d79fef5..c666fc6 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/MusicGalleryViewModel.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/MusicGalleryViewModel.cs @@ -410,8 +410,7 @@ namespace BetterLyrics.WinUI3.ViewModels public void UpdateSelectedPlaylist(SongsTabInfo playlist) { - var found = SongsTabInfoList.Where(x => x.FilterProperty == playlist.FilterProperty && x.FilterValue == playlist.FilterValue) - .ToList().FirstOrDefault(); + var found = SongsTabInfoList.FirstOrDefault(x => x.FilterProperty == playlist.FilterProperty && x.FilterValue == playlist.FilterValue); if (found == null) { SongsTabInfoList.Add(playlist);