mirror of
https://github.com/jayfunc/BetterLyrics.git
synced 2026-01-12 19:08:33 +08:00
chores: Fix thread issue
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
<Identity
|
||||
Name="37412.BetterLyrics"
|
||||
Publisher="CN=E1428B0E-DC1D-4EA4-ACB1-4556569D5BA9"
|
||||
Version="1.0.124.0" />
|
||||
Version="1.0.127.0" />
|
||||
|
||||
<mp:PhoneIdentity PhoneProductId="ca4a4830-fc19-40d9-b823-53e2bff3d816" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
|
||||
|
||||
@@ -109,9 +109,13 @@
|
||||
</ItemGroup>
|
||||
<!--Disable Trimming for Specific Packages-->
|
||||
<ItemGroup>
|
||||
<TrimmerRootAssembly Include="TagLibSharp" />
|
||||
<TrimmerRootAssembly Include="NAudio.Wasapi" />
|
||||
<TrimmerRootAssembly Include="TagLibSharp" />
|
||||
<TrimmerRootAssembly Include="Vanara.PInvoke.DwmApi" />
|
||||
<TrimmerRootAssembly Include="Vanara.PInvoke.Gdi32" />
|
||||
<TrimmerRootAssembly Include="Vanara.PInvoke.Shell32" />
|
||||
<TrimmerRootAssembly Include="Vanara.PInvoke.User32" />
|
||||
<TrimmerRootAssembly Include="Vanara.Windows.Shell" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Update="Assets\AlbumArtPlaceholder.png">
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace BetterLyrics.WinUI3.Helper
|
||||
/// <typeparam name="TResult">返回类型</typeparam>
|
||||
/// <param name="func">要执行的函数</param>
|
||||
/// <returns>一个 Task,其结果是函数的返回值</returns>
|
||||
public static Task<TResult> RunAsStaTask<TResult>(Func<TResult> func)
|
||||
public static Task<TResult> RunAsSTATask<TResult>(Func<TResult> func)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<TResult>();
|
||||
var thread = new Thread(() =>
|
||||
@@ -42,9 +42,9 @@ namespace BetterLyrics.WinUI3.Helper
|
||||
/// </summary>
|
||||
/// <param name="action">要执行的 Action</param>
|
||||
/// <returns>一个 Task</returns>
|
||||
public static Task RunAsStaTask(Action action)
|
||||
public static Task RunAsSTATask(Action action)
|
||||
{
|
||||
return RunAsStaTask(() =>
|
||||
return RunAsSTATask(() =>
|
||||
{
|
||||
action();
|
||||
return true; // 返回一个虚拟结果
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user