From f681b43e9630e5f2e2009a8b941e9eae608ccd6a Mon Sep 17 00:00:00 2001 From: Zhe Fang Date: Sat, 16 Aug 2025 20:23:11 -0400 Subject: [PATCH] update shortcuts, add background task runner --- .../Package.appxmanifest | 2 +- .../BetterLyrics.WinUI3/App.xaml | 3 +- .../BetterLyrics.WinUI3.csproj | 7 +- .../Controls/AppSettingsControl.xaml | 63 ++--- .../LyricsBavkgroundSettingsControl.xaml | 2 +- .../Controls/LyricsSettingsControl.xaml | 2 +- .../Controls/MediaSettingsControl.xaml | 113 ++++---- .../Controls/ShortcutTextBox.xaml | 29 ++ .../Controls/ShortcutTextBox.xaml.cs | 95 +++++++ .../Controls/SystemTray.xaml | 21 +- .../Converter/ShortcutToStringConverter.cs | 26 ++ .../BetterLyrics.WinUI3/Enums/ShortcutID.cs | 19 ++ .../Helper/BackgroundTaskRunner.cs | 37 +++ .../Helper/DirectoryHelper.cs | 47 ++++ .../BetterLyrics.WinUI3/Helper/FileHelper.cs | 10 + .../Helper/GlobalHotKeyHelper.cs | 71 ++++- .../Helper/LatestOnlyTaskRunner.cs | 43 --- .../Helper/MetadataHelper.cs | 12 +- .../Helper/WindowHelper.cs | 2 +- .../Models/LocalLyricsFolder.cs | 6 +- .../Models/Settings/DesktopModeSettings.cs | 3 +- .../Models/Settings/DockModeSettings.cs | 3 +- .../Models/Settings/GeneralSettings.cs | 3 + .../Settings/PictureInPictureModeSettings.cs | 5 +- .../AlbumArtSearchService.cs | 61 +++-- .../LibWatcherService/LibWatcherService.cs | 8 +- .../LyricsSearchService.cs | 22 +- .../MediaSessionsService.cs | 170 +++++++----- .../Strings/en-US/Resources.resw | 20 +- .../Strings/ja-JP/Resources.resw | 20 +- .../Strings/ko-KR/Resources.resw | 20 +- .../Strings/zh-CN/Resources.resw | 20 +- .../Strings/zh-TW/Resources.resw | 20 +- .../LyricsRendererViewModel.Ctor.cs | 6 +- .../LyricsRendererViewModel.Messages.cs | 2 +- .../LyricsRendererViewModel.cs | 10 +- .../ViewModels/LyricsWindowViewModel.cs | 256 +++++++++++++++--- .../MediaSettingsControlViewModel.cs | 2 +- .../ViewModels/MusicGalleryViewModel.cs | 21 +- .../Views/LyricsWindow.xaml | 52 ++-- .../Views/LyricsWindow.xaml.cs | 136 +--------- 41 files changed, 982 insertions(+), 488 deletions(-) create mode 100644 BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShortcutTextBox.xaml create mode 100644 BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShortcutTextBox.xaml.cs create mode 100644 BetterLyrics.WinUI3/BetterLyrics.WinUI3/Converter/ShortcutToStringConverter.cs create mode 100644 BetterLyrics.WinUI3/BetterLyrics.WinUI3/Enums/ShortcutID.cs create mode 100644 BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/BackgroundTaskRunner.cs create mode 100644 BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/DirectoryHelper.cs delete mode 100644 BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LatestOnlyTaskRunner.cs diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3 (Package)/Package.appxmanifest b/BetterLyrics.WinUI3/BetterLyrics.WinUI3 (Package)/Package.appxmanifest index 93d5c20..8077198 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3 (Package)/Package.appxmanifest +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3 (Package)/Package.appxmanifest @@ -12,7 +12,7 @@ + Version="1.0.53.0" /> diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/App.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/App.xaml index 99c3653..bbed9d9 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/App.xaml +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/App.xaml @@ -10,10 +10,10 @@ + - @@ -54,6 +54,7 @@ + diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj index f0d0dab..5ab5f88 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj @@ -30,6 +30,7 @@ + @@ -58,7 +59,6 @@ - @@ -186,6 +186,11 @@ Always + + + MSBuild:Compile + + MSBuild:Compile diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/AppSettingsControl.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/AppSettingsControl.xaml index 9e96f7e..c40ce82 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/AppSettingsControl.xaml +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/AppSettingsControl.xaml @@ -90,6 +90,10 @@ + + + + @@ -103,46 +107,17 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -184,6 +159,10 @@ + + + + @@ -192,6 +171,22 @@ + + + + + + + + + + + + + + + + diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/LyricsBavkgroundSettingsControl.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/LyricsBavkgroundSettingsControl.xaml index a03eac0..73ccbdd 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/LyricsBavkgroundSettingsControl.xaml +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/LyricsBavkgroundSettingsControl.xaml @@ -55,7 +55,7 @@ Value="{x:Bind ViewModel.AppSettings.LyricsBackgroundSettings.CoverOverlaySpeed, Mode=TwoWay}" /> - + - + - + - - + + + + + + + + + + + + + + + + - - + + - - - - - - + + + + + + + + + + + + + - - - + + - + + diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsWindow.xaml.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsWindow.xaml.cs index 24685af..906918f 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsWindow.xaml.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsWindow.xaml.cs @@ -69,25 +69,20 @@ namespace BetterLyrics.WinUI3.Views public LyricsWindowViewModel ViewModel { get; private set; } = Ioc.Default.GetRequiredService(); - public void AutoSelectLyricsMode(LyricsWindowMode? type = null, bool? autoLook = null) + public void AutoSelectLyricsMode(LyricsWindowMode? type = null) { type ??= _settingsService.AppSettings.GeneralSettings.AutoStartWindowType; switch (type!) { case LyricsWindowMode.StandardMode: AppWindow.MoveAndResize(_settingsService.AppSettings.StandardModeSettings.WindowBounds.ToRectInt32()); + ViewModel.SetStandardModeTitleBarControlsStatus(); break; case LyricsWindowMode.DockMode: - DockFlyoutItem.IsChecked = true; - ViewModel.ToggleDockModeCommand.Execute(null); + ViewModel.ToggleDockMode(); break; case LyricsWindowMode.DesktopMode: - DesktopFlyoutItem.IsChecked = true; - ViewModel.ToggleDesktopModeCommand.Execute(null); - if (autoLook == null && _settingsService.AppSettings.DesktopModeSettings.AutoLockOnDesktopMode) - { - ViewModel.ToggleLockWindowCommand.Execute(null); - } + ViewModel.ToggleDesktopMode(); break; default: break; @@ -96,15 +91,11 @@ namespace BetterLyrics.WinUI3.Views private void AOTFlyoutItem_Click(object sender, RoutedEventArgs e) { - var overlappedPresenter = (OverlappedPresenter)AppWindow.Presenter; - overlappedPresenter.IsAlwaysOnTop = !overlappedPresenter.IsAlwaysOnTop; + ViewModel.ToggleAlwaysOnTop(); } private void AppWindow_Changed(AppWindow sender, AppWindowChangedEventArgs args) { - if (args.DidPresenterChange) - UpdateTitleBarWindowButtonsVisibility(); - if (args.DidPositionChange || args.DidSizeChange) { var size = AppWindow.Size; @@ -120,10 +111,7 @@ namespace BetterLyrics.WinUI3.Views { _settingsService.AppSettings.DesktopModeSettings.WindowBounds = new Windows.Foundation.Rect(rect.X, rect.Y, size.Width, size.Height); } - else if (ViewModel.LiveStates.CurrentLyricsWindowMode == LyricsWindowMode.DockMode) - { - - } + else if (ViewModel.LiveStates.CurrentLyricsWindowMode == LyricsWindowMode.DockMode) { } else { _settingsService.AppSettings.StandardModeSettings.WindowBounds = new Windows.Foundation.Rect(rect.X, rect.Y, size.Width, size.Height); @@ -134,34 +122,13 @@ namespace BetterLyrics.WinUI3.Views private void FullScreenFlyoutItem_Click(object sender, RoutedEventArgs e) { - switch (AppWindow.Presenter.Kind) - { - case AppWindowPresenterKind.Default: - break; - case AppWindowPresenterKind.CompactOverlay: - break; - case AppWindowPresenterKind.FullScreen: - AppWindow.SetPresenter(AppWindowPresenterKind.Overlapped); - break; - case AppWindowPresenterKind.Overlapped: - AppWindow.SetPresenter(AppWindowPresenterKind.FullScreen); - break; - default: - break; - } + + ViewModel.ToggleFullscreen(); } - private void MiniFlyoutItem_Click(object sender, RoutedEventArgs e) + private void PIPFlyoutItem_Click(object sender, RoutedEventArgs e) { - ViewModel.TogglePictureInPictureModeCommand.Execute(null); - if (MiniFlyoutItem.IsChecked) - { - AppWindow.SetPresenter(AppWindowPresenterKind.CompactOverlay); - } - else - { - AppWindow.SetPresenter(AppWindowPresenterKind.Overlapped); - } + ViewModel.TogglePictureInPictureMode(); } private void SettingsMenuFlyoutItem_Click(object sender, RoutedEventArgs e) @@ -169,82 +136,6 @@ namespace BetterLyrics.WinUI3.Views WindowHelper.OpenWindow(); } - private void UpdateTitleBarWindowButtonsVisibility() - { - switch (AppWindow.Presenter.Kind) - { - case AppWindowPresenterKind.Default: - break; - case AppWindowPresenterKind.CompactOverlay: - AOTFlyoutItem.Visibility = DesktopFlyoutItem.Visibility = FullScreenFlyoutItem.Visibility = DockFlyoutItem.Visibility = - ClickThroughButton.Visibility = Visibility.Collapsed; - - ViewModel.IsImmersiveMode = true; - break; - case AppWindowPresenterKind.FullScreen: - - AOTFlyoutItem.Visibility = - ClickThroughButton.Visibility = - DesktopFlyoutItem.Visibility = - MiniFlyoutItem.Visibility = - DockFlyoutItem.Visibility = - Visibility.Collapsed; - FullScreenFlyoutItem.IsChecked = true; - ViewModel.IsImmersiveMode = true; - break; - case AppWindowPresenterKind.Overlapped: - DockFlyoutItem.Visibility = Visibility.Visible; - var overlappedPresenter = (OverlappedPresenter)AppWindow.Presenter; - if (DockFlyoutItem.IsChecked) - { - overlappedPresenter.IsMinimizable = - overlappedPresenter.IsMaximizable = false; - - AOTFlyoutItem.Visibility = - DesktopFlyoutItem.Visibility = - ClickThroughButton.Visibility = - FullScreenFlyoutItem.Visibility = - MiniFlyoutItem.Visibility = - Visibility.Collapsed; - - ViewModel.IsImmersiveMode = true; - } - else if (DesktopFlyoutItem.IsChecked) - { - overlappedPresenter.IsMinimizable = - overlappedPresenter.IsMaximizable = false; - - DockFlyoutItem.Visibility = - AOTFlyoutItem.Visibility = - FullScreenFlyoutItem.Visibility = - MiniFlyoutItem.Visibility = - Visibility.Collapsed; - - ClickThroughButton.Visibility = Visibility.Visible; - } - else - { - overlappedPresenter.IsMinimizable = - overlappedPresenter.IsMaximizable = true; - - AOTFlyoutItem.Visibility = - DesktopFlyoutItem.Visibility = - DockFlyoutItem.Visibility = - MiniFlyoutItem.Visibility = - FullScreenFlyoutItem.Visibility = - Visibility.Visible; - FullScreenFlyoutItem.IsChecked = false; - ClickThroughButton.Visibility = Visibility.Collapsed; - AOTFlyoutItem.IsChecked = overlappedPresenter.IsAlwaysOnTop; - - ViewModel.IsImmersiveMode = _settingsService.AppSettings.GeneralSettings.IsImmersiveMode; - } - break; - default: - break; - } - } - private void TopCommandGrid_PointerEntered(object sender, PointerRoutedEventArgs e) { if (ViewModel.IsImmersiveMode) @@ -279,18 +170,17 @@ namespace BetterLyrics.WinUI3.Views private void ClickThroughButton_Click(object sender, RoutedEventArgs e) { - ViewModel.ToggleLockWindowCommand.Execute(null); + ViewModel.ToggleLockWindow(); } private void DockFlyoutItem_Click(object sender, RoutedEventArgs e) { - ViewModel.ToggleDockModeCommand.Execute(null); + ViewModel.ToggleDockMode(); } private void DesktopFlyoutItem_Click(object sender, RoutedEventArgs e) { - ViewModel.ToggleDesktopModeCommand.Execute(null); - UpdateTitleBarWindowButtonsVisibility(); + ViewModel.ToggleDesktopMode(); } private void MusicGalleryMenuFlyoutItem_Click(object sender, RoutedEventArgs e)