From a5b4418e6c0b65f147392ff4076655164b351669 Mon Sep 17 00:00:00 2001 From: LanZhan Date: Mon, 22 Sep 2025 18:06:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- The Untamed Music Player/App.xaml.cs | 3 +-- .../Contracts/Services/IMaterialSelectorService.cs | 3 +-- The Untamed Music Player/Models/MusicLibrary.cs | 2 -- The Untamed Music Player/Models/PlaylistLibrary.cs | 1 - .../CloudMusicAPI/Helpers/CloudAlbumSearchHelper.cs | 2 -- .../Helpers/CloudArtistDetailSearchHelper.cs | 2 -- .../CloudMusicAPI/Helpers/CloudArtistSearchHelper.cs | 2 -- .../CloudMusicAPI/Helpers/CloudPlaylistSearchHelper.cs | 2 -- .../CloudMusicAPI/Helpers/CloudSongSearchHelper.cs | 2 -- The Untamed Music Player/Services/ActivationService.cs | 9 ++++----- .../Services/MaterialSelectorService.cs | 6 +----- .../Services/ThemeSelectorService.cs | 1 + 12 files changed, 8 insertions(+), 27 deletions(-) diff --git a/The Untamed Music Player/App.xaml.cs b/The Untamed Music Player/App.xaml.cs index ef8c9a9..13b0a2c 100644 --- a/The Untamed Music Player/App.xaml.cs +++ b/The Untamed Music Player/App.xaml.cs @@ -38,7 +38,7 @@ public partial class App : Application return service; } - public static WindowEx? MainWindow { get; private set; } + public static WindowEx? MainWindow { get; set; } public static UIElement? AppTitlebar { get; set; } @@ -120,7 +120,6 @@ public partial class App : Application protected async override void OnLaunched(LaunchActivatedEventArgs args) { base.OnLaunched(args); - MainWindow = new MainWindow(); await GetService().ActivateAsync(args); } diff --git a/The Untamed Music Player/Contracts/Services/IMaterialSelectorService.cs b/The Untamed Music Player/Contracts/Services/IMaterialSelectorService.cs index 31c204f..cd4d59f 100644 --- a/The Untamed Music Player/Contracts/Services/IMaterialSelectorService.cs +++ b/The Untamed Music Player/Contracts/Services/IMaterialSelectorService.cs @@ -8,8 +8,7 @@ public interface IMaterialSelectorService : IDisposable bool IsFallBack { get; set; } byte LuminosityOpacity { get; set; } Color TintColor { get; set; } - void InitializeSettings(); - Task InitializeMaterialAsync(); + Task InitializeAsync(); Task<(byte, Color)> SetMaterial( MaterialType material, bool firstStart = false, diff --git a/The Untamed Music Player/Models/MusicLibrary.cs b/The Untamed Music Player/Models/MusicLibrary.cs index eaf9679..2041c0e 100644 --- a/The Untamed Music Player/Models/MusicLibrary.cs +++ b/The Untamed Music Player/Models/MusicLibrary.cs @@ -180,7 +180,6 @@ public partial class MusicLibrary : ObservableRecipient _ = Task.Run(LoadCovers); _ = Task.Run(AddFolderWatcher); _librarySemaphore.Release(); - GC.Collect(2, GCCollectionMode.Forced, true, true); } }); } @@ -236,7 +235,6 @@ public partial class MusicLibrary : ObservableRecipient { _dispatcherQueue.TryEnqueue(() => IsProgressRingActive = false); _librarySemaphore.Release(); - GC.Collect(2, GCCollectionMode.Forced, true, true); } }); } diff --git a/The Untamed Music Player/Models/PlaylistLibrary.cs b/The Untamed Music Player/Models/PlaylistLibrary.cs index 8c45515..fa83367 100644 --- a/The Untamed Music Player/Models/PlaylistLibrary.cs +++ b/The Untamed Music Player/Models/PlaylistLibrary.cs @@ -33,7 +33,6 @@ public partial class PlaylistLibrary : ObservableRecipient { playlist.GetCover(); } - GC.Collect(2, GCCollectionMode.Forced, true, true); } public PlaylistInfo? NewPlaylist(string? name) diff --git a/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudAlbumSearchHelper.cs b/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudAlbumSearchHelper.cs index 65e7e73..fbc8ce1 100644 --- a/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudAlbumSearchHelper.cs +++ b/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudAlbumSearchHelper.cs @@ -74,7 +74,6 @@ public class CloudAlbumSearchHelper finally { _searchSemaphore.Release(); - GC.Collect(2, GCCollectionMode.Forced, true, true); } } @@ -117,7 +116,6 @@ public class CloudAlbumSearchHelper finally { _searchSemaphore.Release(); - GC.Collect(2, GCCollectionMode.Forced, true, true); } } diff --git a/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudArtistDetailSearchHelper.cs b/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudArtistDetailSearchHelper.cs index 42fe246..26825c3 100644 --- a/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudArtistDetailSearchHelper.cs +++ b/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudArtistDetailSearchHelper.cs @@ -71,7 +71,6 @@ public class CloudArtistDetailSearchHelper finally { _searchSemaphore.Release(); - GC.Collect(2, GCCollectionMode.Forced, true, true); } return info; } @@ -103,7 +102,6 @@ public class CloudArtistDetailSearchHelper finally { _searchSemaphore.Release(); - GC.Collect(2, GCCollectionMode.Forced, true, true); } } diff --git a/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudArtistSearchHelper.cs b/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudArtistSearchHelper.cs index 588f050..bba1e07 100644 --- a/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudArtistSearchHelper.cs +++ b/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudArtistSearchHelper.cs @@ -75,7 +75,6 @@ public class CloudArtistSearchHelper finally { _searchSemaphore.Release(); - GC.Collect(2, GCCollectionMode.Forced, true, true); } } @@ -118,7 +117,6 @@ public class CloudArtistSearchHelper finally { _searchSemaphore.Release(); - GC.Collect(2, GCCollectionMode.Forced, true, true); } } diff --git a/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudPlaylistSearchHelper.cs b/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudPlaylistSearchHelper.cs index 82a8162..9ca33c9 100644 --- a/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudPlaylistSearchHelper.cs +++ b/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudPlaylistSearchHelper.cs @@ -75,7 +75,6 @@ public class CloudPlaylistSearchHelper finally { _searchSemaphore.Release(); - GC.Collect(2, GCCollectionMode.Forced, true, true); } } @@ -118,7 +117,6 @@ public class CloudPlaylistSearchHelper finally { _searchSemaphore.Release(); - GC.Collect(2, GCCollectionMode.Forced, true, true); } } diff --git a/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudSongSearchHelper.cs b/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudSongSearchHelper.cs index a851e0b..be4c2d0 100644 --- a/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudSongSearchHelper.cs +++ b/The Untamed Music Player/OnlineAPIs/CloudMusicAPI/Helpers/CloudSongSearchHelper.cs @@ -73,7 +73,6 @@ public class CloudSongSearchHelper finally { _searchSemaphore.Release(); - GC.Collect(2, GCCollectionMode.Forced, true, true); } } @@ -116,7 +115,6 @@ public class CloudSongSearchHelper finally { _searchSemaphore.Release(); - GC.Collect(2, GCCollectionMode.Forced, true, true); } } diff --git a/The Untamed Music Player/Services/ActivationService.cs b/The Untamed Music Player/Services/ActivationService.cs index 236e7c3..618f029 100644 --- a/The Untamed Music Player/Services/ActivationService.cs +++ b/The Untamed Music Player/Services/ActivationService.cs @@ -18,17 +18,18 @@ public class ActivationService(IEnumerable activationHandler public async Task ActivateAsync(object activationArgs) { + await Settings.InitializeAsync(); // 初始化设置 + App.MainWindow = new MainWindow(); await InitializeAsync(); // 在激活之前执行的任务 await HandleActivationAsync(activationArgs); // 通过 ActivationHandlers 处理激活 - App.MainWindow?.Activate(); // 打开 MainWindow + App.MainWindow.Activate(); // 打开 MainWindow await StartupAsync(); // 在激活之后执行的任务 } private async Task InitializeAsync() { - await Settings.InitializeAsync().ConfigureAwait(false); _themeSelectorService.Initialize(); - _materialSelectorService.InitializeSettings(); + await _materialSelectorService.InitializeAsync(); } private async Task HandleActivationAsync(object activationArgs) @@ -45,8 +46,6 @@ public class ActivationService(IEnumerable activationHandler private async Task StartupAsync() { - _themeSelectorService.SetRequestedThemeAsync(); - await _materialSelectorService.InitializeMaterialAsync(); await _dynamicBackgroundService.InitializeAsync(); } } diff --git a/The Untamed Music Player/Services/MaterialSelectorService.cs b/The Untamed Music Player/Services/MaterialSelectorService.cs index da39bdb..6456506 100644 --- a/The Untamed Music Player/Services/MaterialSelectorService.cs +++ b/The Untamed Music Player/Services/MaterialSelectorService.cs @@ -64,16 +64,12 @@ public partial class MaterialSelectorService : IMaterialSelectorService } } - public void InitializeSettings() + public async Task InitializeAsync() { Material = Settings.Material; IsFallBack = Settings.IsFallBack; LuminosityOpacity = Settings.LuminosityOpacity; TintColor = Settings.TintColor; - } - - public async Task InitializeMaterialAsync() - { _mainWindow = App.MainWindow!; _mainWindow.Activated += MainWindow_Activated; ((FrameworkElement)_mainWindow.Content).ActualThemeChanged += Window_ThemeChanged; diff --git a/The Untamed Music Player/Services/ThemeSelectorService.cs b/The Untamed Music Player/Services/ThemeSelectorService.cs index 6adc751..4b80f6a 100644 --- a/The Untamed Music Player/Services/ThemeSelectorService.cs +++ b/The Untamed Music Player/Services/ThemeSelectorService.cs @@ -27,6 +27,7 @@ public class ThemeSelectorService : IThemeSelectorService public void Initialize() { Theme = Settings.Theme; + SetRequestedThemeAsync(); } public void SetThemeAsync(ElementTheme theme)