rollback local album and lyrics search methos to avoid slow response

This commit is contained in:
Zhe Fang
2025-08-12 15:15:04 -04:00
parent 7b6eca6ff6
commit 5f3aad4e99
22 changed files with 121 additions and 40 deletions

View File

@@ -12,7 +12,7 @@
<Identity
Name="37412.BetterLyrics"
Publisher="CN=E1428B0E-DC1D-4EA4-ACB1-4556569D5BA9"
Version="1.0.49.0" />
Version="1.0.50.0" />
<mp:PhoneIdentity PhoneProductId="ca4a4830-fc19-40d9-b823-53e2bff3d816" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

View File

@@ -84,13 +84,6 @@ namespace BetterLyrics.WinUI3
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
WindowHelper.OpenWindow<LyricsWindow>();
var lyricsWindow = WindowHelper.GetWindowByWindowType<LyricsWindow>();
if (lyricsWindow != null)
{
lyricsWindow.ViewModel.InitLockHotKey();
lyricsWindow.AutoSelectLyricsMode();
}
}
private static void ConfigureServices()

View File

@@ -70,6 +70,14 @@
<ToggleSwitch IsOn="{x:Bind ViewModel.AppSettings.GeneralSettings.IsDragEverywhereEnabled, Mode=TwoWay}" />
</controls:SettingsCard>
<controls:SettingsCard
x:Uid="SettingsPageExitOnLyricsWindowClosed"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource IconFontFamily},
Glyph=&#xE7E8;}"
Visibility="Collapsed">
<ToggleSwitch IsOn="{x:Bind ViewModel.AppSettings.GeneralSettings.ExitOnLyricsWindowClosed, Mode=TwoWay}" />
</controls:SettingsCard>
<!-- Desktop mode -->
<TextBlock x:Uid="SettingsPageAppDesktop" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />

View File

@@ -14,9 +14,9 @@
x:Name="TrayIcon"
x:FieldModifier="public"
ContextMenuMode="SecondWindow"
DoubleClickCommand="{x:Bind ViewModel.OpenLyricsWindowCommand}"
DoubleClickCommand="{x:Bind ViewModel.OpenLyricsCommand}"
IconSource="ms-appx:///Assets/Logo.ico"
LeftClickCommand="{x:Bind ViewModel.OpenLyricsWindowCommand}"
LeftClickCommand="{x:Bind ViewModel.OpenLyricsCommand}"
NoLeftClickDelay="True"
ToolTipText="{x:Bind ViewModel.ToolTipText, Mode=OneWay}">
<tb:TaskbarIcon.ContextFlyout>
@@ -24,6 +24,10 @@
AreOpenCloseAnimationsEnabled="True"
LightDismissOverlayMode="On"
ShowMode="TransientWithDismissOnPointerMoveAway">
<MenuFlyoutItem
x:Uid="SystemTrayLyrics"
Command="{x:Bind ViewModel.OpenLyricsCommand}"
Visibility="Collapsed" />
<MenuFlyoutItem x:Uid="SystemTrayMusicGallery" Command="{x:Bind ViewModel.OpenMusicGalleryCommand}" />
<MenuFlyoutItem x:Uid="SystemTraySettings" Command="{x:Bind ViewModel.OpenSettingsCommand}" />
<MenuFlyoutItem x:Uid="SystemTrayResetWindowPosition" Command="{x:Bind ViewModel.ResetWindowPositionCommand}" />

View File

@@ -46,7 +46,7 @@ namespace BetterLyrics.WinUI3.Helper
}
else
{
_easingType = Enums.EasingType.Linear;
_easingType = Enums.EasingType.EaseInOutQuad;
_interpolator = GetInterpolatorByEasingType(_easingType.Value);
}
}

View File

@@ -18,6 +18,10 @@ namespace BetterLyrics.WinUI3.Helper
public static void CloseWindow<T>()
{
if (typeof(T) == typeof(LyricsWindow))
{
EnsureDockModeReleased();
}
var window = _activeWindows.Find(w => w is T);
if (window is Window w)
{
@@ -64,6 +68,13 @@ namespace BetterLyrics.WinUI3.Helper
var castedWindow = (Window)window;
castedWindow.Restore();
castedWindow.Activate();
if (typeof(T) == typeof(LyricsWindow))
{
var lyricsWindow = (LyricsWindow)window;
lyricsWindow.ViewModel.InitLockHotKey();
lyricsWindow.AutoSelectLyricsMode();
}
}
public static void RestartApp(string args = "")
@@ -88,12 +99,17 @@ namespace BetterLyrics.WinUI3.Helper
public static void ExitApp()
{
LyricsWindow? lyricsWindow = WindowHelper.GetWindowByWindowType<LyricsWindow>();
EnsureDockModeReleased();
Environment.Exit(0);
}
private static void EnsureDockModeReleased()
{
LyricsWindow? lyricsWindow = GetWindowByWindowType<LyricsWindow>();
if (lyricsWindow != null)
{
DockModeHelper.Disable(lyricsWindow);
}
Environment.Exit(0);
}
private static void TrackWindow(object window)

View File

@@ -25,32 +25,32 @@ namespace BetterLyrics.WinUI3.Models
public ValueTransition<double> AngleTransition { get; set; } = new(
initialValue: 0,
durationSeconds: _animationDuration,
easingType: EasingType.EaseInOutSine
easingType: EasingType.EaseInOutQuad
);
public ValueTransition<double> BlurAmountTransition { get; set; } = new(
initialValue: 0,
durationSeconds: _animationDuration,
easingType: EasingType.EaseInOutSine
easingType: EasingType.EaseInOutQuad
);
public ValueTransition<double> HighlightOpacityTransition { get; set; } = new(
initialValue: 0,
durationSeconds: _animationDuration,
easingType: EasingType.EaseInOutSine
easingType: EasingType.EaseInOutQuad
);
public ValueTransition<double> OpacityTransition { get; set; } = new(
initialValue: 0,
durationSeconds: _animationDuration,
easingType: EasingType.EaseInOutSine
easingType: EasingType.EaseInOutQuad
);
public ValueTransition<double> ScaleTransition { get; set; } = new(
initialValue: 0.75,
durationSeconds: _animationDuration,
easingType: EasingType.EaseInOutSine
easingType: EasingType.EaseInOutQuad
);
public ValueTransition<double> YOffsetTransition { get; set; } = new(
initialValue: 0,
durationSeconds: 0.5,
easingType: EasingType.EaseInOutSine
easingType: EasingType.EaseInOutQuad
);
public CanvasTextLayout? CanvasTextLayout { get; private set; }

View File

@@ -9,13 +9,14 @@ namespace BetterLyrics.WinUI3.Models.Settings
public partial class AppSettings : ObservableRecipient
{
public string Version { get; set; } = Helper.MetadataHelper.AppVersion;
[ObservableProperty][NotifyPropertyChangedRecipients] public partial LyricsStyleSettings StandardLyricsStyleSettings { get; set; } = new LyricsStyleSettings(32, TextAlignmentType.Left, 0);
[ObservableProperty][NotifyPropertyChangedRecipients] public partial LyricsStyleSettings DesktopLyricsStyleSettings { get; set; } = new LyricsStyleSettings(28, TextAlignmentType.Center, 2);
[ObservableProperty][NotifyPropertyChangedRecipients] public partial LyricsStyleSettings DockLyricsStyleSettings { get; set; } = new LyricsStyleSettings(16, TextAlignmentType.Center, 0);
[ObservableProperty][NotifyPropertyChangedRecipients] public partial LyricsEffectSettings StandardLyricsEffectSettings { get; set; } = new LyricsEffectSettings(100, 500, 1000, EasingType.EaseInOutSine);
[ObservableProperty][NotifyPropertyChangedRecipients] public partial LyricsEffectSettings DesktopLyricsEffectSettings { get; set; } = new LyricsEffectSettings(500, 500, 500, EasingType.EaseInOutSine);
[ObservableProperty][NotifyPropertyChangedRecipients] public partial LyricsEffectSettings DockLyricsEffectSettings { get; set; } = new LyricsEffectSettings(500, 500, 500, EasingType.EaseInOutSine);
[ObservableProperty][NotifyPropertyChangedRecipients] public partial LyricsEffectSettings StandardLyricsEffectSettings { get; set; } = new LyricsEffectSettings(100, 500, 1000, EasingType.EaseInOutQuad);
[ObservableProperty][NotifyPropertyChangedRecipients] public partial LyricsEffectSettings DesktopLyricsEffectSettings { get; set; } = new LyricsEffectSettings(500, 500, 500, EasingType.EaseInOutQuad);
[ObservableProperty][NotifyPropertyChangedRecipients] public partial LyricsEffectSettings DockLyricsEffectSettings { get; set; } = new LyricsEffectSettings(500, 500, 500, EasingType.EaseInOutQuad);
[ObservableProperty][NotifyPropertyChangedRecipients] public partial StandardModeSettings StandardModeSettings { get; set; } = new StandardModeSettings();
[ObservableProperty][NotifyPropertyChangedRecipients] public partial DesktopModeSettings DesktopModeSettings { get; set; } = new DesktopModeSettings();

View File

@@ -18,6 +18,7 @@ namespace BetterLyrics.WinUI3.Models.Settings
[ObservableProperty][NotifyPropertyChangedRecipients] public partial bool IsDragEverywhereEnabled { get; set; } = false;
[ObservableProperty][NotifyPropertyChangedRecipients] public partial LyricsDisplayType DisplayType { get; set; } = LyricsDisplayType.SplitView;
[ObservableProperty][NotifyPropertyChangedRecipients] public partial bool IsImmersiveMode { get; set; } = false;
[ObservableProperty][NotifyPropertyChangedRecipients] public partial bool ExitOnLyricsWindowClosed { get; set; } = true;
public GeneralSettings() { }
}

View File

@@ -72,19 +72,21 @@ namespace BetterLyrics.WinUI3.Services.AlbumArtSearchService
{
foreach (var file in Directory.GetFiles(folder.Path, $"*.*", SearchOption.AllDirectories))
{
try
if (FileHelper.IsSwitchableNormalizedMatch(Path.GetFileNameWithoutExtension(file), artist, title))
{
Track track = new(file);
if (track.Artist == artist && track.Title == title)
try
{
Track track = new(file);
var bytes = track.EmbeddedPictures.FirstOrDefault()?.PictureData;
if (bytes != null)
{
return bytes;
}
}
catch (Exception)
{
}
}
catch (Exception) { }
}
}
}

View File

@@ -197,19 +197,20 @@ namespace BetterLyrics.WinUI3.Services.LyricsSearchService
{
foreach (var file in Directory.GetFiles(folder.Path, $"*.*", SearchOption.AllDirectories))
{
try
if (FileHelper.IsSwitchableNormalizedMatch(Path.GetFileNameWithoutExtension(file), title, artist))
{
Track track = new(file);
if (track.Artist == artist && track.Title == title)
try
{
var plain = TagLib.File.Create(file).Tag.Lyrics;
if (plain != null && plain != string.Empty)
if (!plain.IsNullOrEmpty())
{
return plain;
}
}
catch (Exception)
{
}
}
catch (Exception) { }
}
}
}

View File

@@ -562,6 +562,9 @@ If you encounter any problems, please go to the Settings page, About tab, and vi
<data name="SettingsPageEN.Content" xml:space="preserve">
<value>English</value>
</data>
<data name="SettingsPageExitOnLyricsWindowClosed.Header" xml:space="preserve">
<value>Exit the program when you close the lyrics window</value>
</data>
<data name="SettingsPageExportSettingsButton.Content" xml:space="preserve">
<value>Export settings</value>
</data>
@@ -973,6 +976,9 @@ If you encounter any problems, please go to the Settings page, About tab, and vi
<data name="SystemTrayExit.Text" xml:space="preserve">
<value>Exit</value>
</data>
<data name="SystemTrayLyrics.Text" xml:space="preserve">
<value>Open the lyrics window</value>
</data>
<data name="SystemTrayMusicGallery.Text" xml:space="preserve">
<value>Open music gallery</value>
</data>

View File

@@ -562,6 +562,9 @@
<data name="SettingsPageEN.Content" xml:space="preserve">
<value>English</value>
</data>
<data name="SettingsPageExitOnLyricsWindowClosed.Header" xml:space="preserve">
<value>歌詞ウィンドウを閉じてプログラムを終了してください</value>
</data>
<data name="SettingsPageExportSettingsButton.Content" xml:space="preserve">
<value>エクスポート設定</value>
</data>
@@ -973,6 +976,9 @@
<data name="SystemTrayExit.Text" xml:space="preserve">
<value>プログラムを終了します</value>
</data>
<data name="SystemTrayLyrics.Text" xml:space="preserve">
<value>歌詞ウィンドウを開きます</value>
</data>
<data name="SystemTrayMusicGallery.Text" xml:space="preserve">
<value>オープンミュージックギャラリー</value>
</data>

View File

@@ -562,6 +562,9 @@
<data name="SettingsPageEN.Content" xml:space="preserve">
<value>English</value>
</data>
<data name="SettingsPageExitOnLyricsWindowClosed.Header" xml:space="preserve">
<value>가사 창을 닫으면 프로그램을 종료하세요</value>
</data>
<data name="SettingsPageExportSettingsButton.Content" xml:space="preserve">
<value>내보내기 설정</value>
</data>
@@ -973,6 +976,9 @@
<data name="SystemTrayExit.Text" xml:space="preserve">
<value>프로그램을 종료하십시오</value>
</data>
<data name="SystemTrayLyrics.Text" xml:space="preserve">
<value>가사 창을 여세요</value>
</data>
<data name="SystemTrayMusicGallery.Text" xml:space="preserve">
<value>오픈 음악 갤러리</value>
</data>

View File

@@ -562,6 +562,9 @@
<data name="SettingsPageEN.Content" xml:space="preserve">
<value>English</value>
</data>
<data name="SettingsPageExitOnLyricsWindowClosed.Header" xml:space="preserve">
<value>关闭歌词窗口时退出程序</value>
</data>
<data name="SettingsPageExportSettingsButton.Content" xml:space="preserve">
<value>导出设置</value>
</data>
@@ -973,6 +976,9 @@
<data name="SystemTrayExit.Text" xml:space="preserve">
<value>退出程序</value>
</data>
<data name="SystemTrayLyrics.Text" xml:space="preserve">
<value>打开歌词窗口</value>
</data>
<data name="SystemTrayMusicGallery.Text" xml:space="preserve">
<value>打开音乐库</value>
</data>

View File

@@ -562,6 +562,9 @@
<data name="SettingsPageEN.Content" xml:space="preserve">
<value>English</value>
</data>
<data name="SettingsPageExitOnLyricsWindowClosed.Header" xml:space="preserve">
<value>關閉歌詞視窗時退出程式</value>
</data>
<data name="SettingsPageExportSettingsButton.Content" xml:space="preserve">
<value>導出設置</value>
</data>
@@ -973,6 +976,9 @@
<data name="SystemTrayExit.Text" xml:space="preserve">
<value>退出程序</value>
</data>
<data name="SystemTrayLyrics.Text" xml:space="preserve">
<value>開啟歌詞視窗</value>
</data>
<data name="SystemTrayMusicGallery.Text" xml:space="preserve">
<value>開啟音樂庫</value>
</data>

View File

@@ -15,7 +15,7 @@ namespace BetterLyrics.WinUI3.ViewModels.LyricsRendererViewModel
private readonly ValueTransition<double> _canvasYScrollTransition = new(
initialValue: 0f,
durationSeconds: 0.3f,
easingType: EasingType.EaseInOutSine
easingType: EasingType.EaseInOutQuad
);
private readonly ValueTransition<Color> _immersiveBgColorTransition = new(
@@ -38,25 +38,25 @@ namespace BetterLyrics.WinUI3.ViewModels.LyricsRendererViewModel
private readonly ValueTransition<double> _titleXTransition = new(
initialValue: 0f,
durationSeconds: 0.3f,
easingType: EasingType.EaseInOutBack
easingType: EasingType.EaseInOutQuad
);
private readonly ValueTransition<double> _titleYTransition = new(
initialValue: 0f,
durationSeconds: 0.3f,
easingType: EasingType.EaseInOutBack
easingType: EasingType.EaseInOutQuad
);
private readonly ValueTransition<double> _lyricsXTransition = new(
initialValue: 0f,
durationSeconds: 0.3f,
easingType: EasingType.EaseInOutBack
easingType: EasingType.EaseInOutQuad
);
private readonly ValueTransition<double> _lyricsYTransition = new(
initialValue: 0f,
durationSeconds: 0.3f,
easingType: EasingType.EaseInOutBack
easingType: EasingType.EaseInOutQuad
);
private readonly ValueTransition<double> _lyricsOpacityTransition = new(
@@ -77,13 +77,13 @@ namespace BetterLyrics.WinUI3.ViewModels.LyricsRendererViewModel
private readonly ValueTransition<double> _albumArtXTransition = new(
initialValue: 0f,
durationSeconds: 0.3f,
easingType: EasingType.EaseInOutBack
easingType: EasingType.EaseInOutQuad
);
private readonly ValueTransition<double> _albumArtYTransition = new(
initialValue: 0f,
durationSeconds: 0.3f,
easingType: EasingType.EaseInOutBack
easingType: EasingType.EaseInOutQuad
);
private readonly ValueTransition<double> _songInfoOpacityTransition = new(

View File

@@ -254,6 +254,18 @@ namespace BetterLyrics.WinUI3
ActivatedWindowAccentColor = ColorHelper.GetAccentColor(hwnd, _settingsService.AppSettings.DockModeSettings.DockMonitorDeviceName, mode).ToColor();
}
public void ExitOrClose()
{
if (_settingsService.AppSettings.GeneralSettings.ExitOnLyricsWindowClosed)
{
WindowHelper.ExitApp();
}
else
{
WindowHelper.CloseWindow<LyricsWindow>();
}
}
public void InitLockHotKey()
{
UpdateLockHotKey(_settingsService.AppSettings.DesktopModeSettings.LockHotKeyIndex);

View File

@@ -71,7 +71,7 @@ namespace BetterLyrics.WinUI3.ViewModels
}
[RelayCommand]
private static void OpenLyricsWindow()
private static void OpenLyrics()
{
WindowHelper.OpenWindow<LyricsWindow>();
}

View File

@@ -42,7 +42,7 @@ namespace BetterLyrics.WinUI3.Views
private void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs args)
{
WindowHelper.ExitApp();
ViewModel.ExitOrClose();
}
public void UpdateTitleBarArea()

View File

@@ -34,6 +34,12 @@ namespace BetterLyrics.WinUI3.Views
AppWindow.TitleBar.PreferredTheme = TitleBarTheme.UseDefaultAppMode;
AppWindow.SetIcons();
AppWindow.Closing += AppWindow_Closing;
}
private void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs args)
{
WindowHelper.CloseWindow<MusicGalleryWindow>();
}
}
}

View File

@@ -18,9 +18,16 @@ namespace BetterLyrics.WinUI3.Views
AppWindow.TitleBar.PreferredTheme = TitleBarTheme.UseDefaultAppMode;
AppWindow.SetIcons();
AppWindow.Closing += AppWindow_Closing;
RootFrame.Navigate(typeof(SettingsPage));
}
private void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs args)
{
WindowHelper.CloseWindow<SettingsWindow>();
}
private void TipContainerCenter_Loaded(object sender, RoutedEventArgs e)
{
App.Current.SettingsWindowNotificationPanel = TipContainerCenter;