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/Controls/ShortcutTextBox.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShortcutTextBox.xaml
new file mode 100644
index 0000000..bec30c7
--- /dev/null
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShortcutTextBox.xaml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShortcutTextBox.xaml.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShortcutTextBox.xaml.cs
new file mode 100644
index 0000000..bf59f81
--- /dev/null
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShortcutTextBox.xaml.cs
@@ -0,0 +1,95 @@
+using Microsoft.UI.Input;
+using Microsoft.UI.Xaml;
+using Microsoft.UI.Xaml.Controls;
+using Microsoft.UI.Xaml.Controls.Primitives;
+using Microsoft.UI.Xaml.Data;
+using Microsoft.UI.Xaml.Input;
+using Microsoft.UI.Xaml.Media;
+using Microsoft.UI.Xaml.Navigation;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices.WindowsRuntime;
+using Windows.Foundation;
+using Windows.Foundation.Collections;
+using Windows.UI.Core;
+
+// To learn more about WinUI, the WinUI project structure,
+// and more about our project templates, see: http://aka.ms/winui-project-info.
+
+namespace BetterLyrics.WinUI3.Controls
+{
+ public sealed partial class ShortcutTextBox : UserControl
+ {
+ public ShortcutTextBox()
+ {
+ InitializeComponent();
+ }
+
+ public static readonly DependencyProperty ShortcutProperty =
+ DependencyProperty.Register(nameof(Shortcut), typeof(List), typeof(ShortcutTextBox), new PropertyMetadata(default));
+
+ public List Shortcut
+ {
+ get => (List)GetValue(ShortcutProperty);
+ set => SetValue(ShortcutProperty, value);
+ }
+
+ private void TextBox_KeyDown(object sender, KeyRoutedEventArgs e)
+ {
+ List shortcut = [];
+
+ bool ctrl = InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
+ bool shift = InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
+ bool alt = InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down);
+ bool win = InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.LeftWindows).HasFlag(CoreVirtualKeyStates.Down) ||
+ InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.RightWindows).HasFlag(CoreVirtualKeyStates.Down);
+
+ if (ctrl)
+ {
+ shortcut.Add("Ctrl");
+ }
+ if (shift)
+ {
+ shortcut.Add("Shift");
+ }
+ if (alt)
+ {
+ shortcut.Add("Alt");
+ }
+ if (win)
+ {
+ shortcut.Add("Win");
+ }
+
+ if (e.Key != Windows.System.VirtualKey.Control &&
+ e.Key != Windows.System.VirtualKey.Shift &&
+ e.Key != Windows.System.VirtualKey.Menu &&
+ e.Key != Windows.System.VirtualKey.LeftWindows &&
+ e.Key != Windows.System.VirtualKey.RightWindows)
+ {
+ shortcut.Add(e.Key.ToString());
+ }
+ Shortcut = shortcut;
+
+ UpdateTextBox();
+ }
+
+ private void UpdateTextBox()
+ {
+ TextBox.Text = string.Join(" + ", Shortcut);
+ }
+
+ private void TextBox_Loaded(object sender, RoutedEventArgs e)
+ {
+ UpdateTextBox();
+ }
+
+ private void ClearButton_Click(object sender, RoutedEventArgs e)
+ {
+ Shortcut = [];
+ UpdateTextBox();
+ }
+ }
+}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/SystemTray.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/SystemTray.xaml
index f8a363c..ee35b3f 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/SystemTray.xaml
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/SystemTray.xaml
@@ -32,34 +32,41 @@
+ Icon="{ui:FontIcon FontFamily={StaticResource IconFontFamily},
+ Glyph=}" />
+ Icon="{ui:FontIcon FontFamily={StaticResource IconFontFamily},
+ Glyph=}" />
+ Icon="{ui:FontIcon FontFamily={StaticResource IconFontFamily},
+ Glyph=}" />
+ Icon="{ui:FontIcon FontFamily={StaticResource IconFontFamily},
+ Glyph=}" />
+ Icon="{ui:FontIcon FontFamily={StaticResource IconFontFamily},
+ Glyph=}" />
+ Icon="{ui:FontIcon FontFamily={StaticResource IconFontFamily},
+ Glyph=}" />
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Converter/ShortcutToStringConverter.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Converter/ShortcutToStringConverter.cs
new file mode 100644
index 0000000..4296134
--- /dev/null
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Converter/ShortcutToStringConverter.cs
@@ -0,0 +1,26 @@
+using Microsoft.UI.Xaml.Data;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BetterLyrics.WinUI3.Converter
+{
+ public class ShortcutToStringConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, string language)
+ {
+ if (value is List shortcut)
+ {
+ return string.Join(" + ", shortcut);
+ }
+ return "";
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, string language)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Enums/ShortcutID.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Enums/ShortcutID.cs
new file mode 100644
index 0000000..4e09b86
--- /dev/null
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Enums/ShortcutID.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BetterLyrics.WinUI3.Enums
+{
+ public enum ShortcutID
+ {
+ DesktopLock,
+ DesktopToggle,
+ DockToggle,
+ PictureInPictureToggle,
+ PlayOrPauseSong,
+ NextSong,
+ PreviousSong,
+ }
+}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/BackgroundTaskRunner.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/BackgroundTaskRunner.cs
new file mode 100644
index 0000000..022ebdd
--- /dev/null
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/BackgroundTaskRunner.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace BetterLyrics.WinUI3.Helper
+{
+ public class BackgroundTaskRunner
+ {
+ private CancellationTokenSource? _cts;
+
+ public void Run(Func taskFactory)
+ {
+ _cts?.Cancel();
+ _cts?.Dispose();
+
+ _cts = new CancellationTokenSource();
+ var token = _cts.Token;
+
+ _ = Task.Run(async () =>
+ {
+ try
+ {
+ await taskFactory(token);
+ }
+ catch (OperationCanceledException)
+ {
+ }
+ catch (Exception)
+ {
+ }
+ }, token);
+ }
+ }
+}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/DirectoryHelper.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/DirectoryHelper.cs
new file mode 100644
index 0000000..c75c7f3
--- /dev/null
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/DirectoryHelper.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BetterLyrics.WinUI3.Helper
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Linq;
+ using System.Text;
+ using System.Threading.Tasks;
+
+ namespace BetterLyrics.WinUI3.Helper
+ {
+ public class DirectoryHelper
+ {
+ ///
+ /// 递归查找指定文件夹下所有文件(包括子文件夹)。
+ ///
+ /// 要查找的文件夹路径
+ /// 所有文件的完整路径列表
+ public static List GetAllFiles(string folderPath, string searchPattern = "*")
+ {
+ var files = new List();
+ if (!Directory.Exists(folderPath))
+ return files;
+
+ try
+ {
+ files.AddRange(Directory.GetFiles(folderPath, searchPattern));
+ foreach (var dir in Directory.GetDirectories(folderPath))
+ {
+ files.AddRange(GetAllFiles(dir, searchPattern));
+ }
+ }
+ catch (Exception)
+ {
+ // 可根据需要处理异常,如权限不足等
+ }
+ return files;
+ }
+ }
+ }
+}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/FileHelper.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/FileHelper.cs
index 95c9c34..f5b6ccd 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/FileHelper.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/FileHelper.cs
@@ -4,6 +4,7 @@ using BetterLyrics.WinUI3.Enums;
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Text;
using Ude;
@@ -78,5 +79,14 @@ namespace BetterLyrics.WinUI3.Helper
return normFileName == normQ1 + normQ2
|| normFileName == normQ2 + normQ1;
}
+
+ public static readonly string[] MusicExtensions = {
+ ".mp3", ".aac", ".m4a", ".ogg", ".opus", ".wma", ".amr",
+ ".flac", ".alac", ".ape", ".wv", ".tak",
+ ".wav", ".aiff", ".aif", ".pcm", ".cda", ".dsf", ".dff", ".au", ".snd",
+ ".mid", ".midi", ".mod", ".xm", ".it", ".s3m"
+ };
+
+ public static string MusicSearchPattern => string.Join("|", MusicExtensions.Select(x => $"*{x}"));
}
}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/GlobalHotKeyHelper.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/GlobalHotKeyHelper.cs
index fc828c7..f45d2f6 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/GlobalHotKeyHelper.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/GlobalHotKeyHelper.cs
@@ -1,4 +1,5 @@
-using Microsoft.UI.Xaml;
+using BetterLyrics.WinUI3.Enums;
+using Microsoft.UI.Xaml;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -13,24 +14,70 @@ namespace BetterLyrics.WinUI3.Helper
public class GlobalHotKeyHelper
{
private static Dictionary _hotKeyActions = [];
- private static int _nextId = 0;
- public static void RegisterHotKey(Window window, User32.HotKeyModifiers modifiers, uint key, Action action)
+ ///
+ /// Register a global hotkey for a specific window type
+ ///
+ /// Target window type
+ ///
+ ///
+ ///
+ public static void RegisterHotKey(ShortcutID id, List keys, Action action)
{
+ if (keys.Count == 0) return;
+
+ var window = WindowHelper.GetWindowByWindowType();
+ if (window == null) return;
+
HWND hwnd = WindowNative.GetWindowHandle(window);
- int id = _nextId++;
- User32.RegisterHotKey(hwnd, id, modifiers, key);
- _hotKeyActions[id] = action;
+ User32.HotKeyModifiers modifiers = User32.HotKeyModifiers.MOD_NONE;
+ VirtualKey key = VirtualKey.None;
+ foreach (var item in keys)
+ {
+ if (item == "Ctrl")
+ {
+ modifiers |= User32.HotKeyModifiers.MOD_CONTROL;
+ }
+ else if (item == "Shift")
+ {
+ modifiers |= User32.HotKeyModifiers.MOD_SHIFT;
+ }
+ else if (item == "Alt")
+ {
+ modifiers |= User32.HotKeyModifiers.MOD_ALT;
+ }
+ else if (item == "Win")
+ {
+ modifiers |= User32.HotKeyModifiers.MOD_WIN;
+ }
+ else
+ {
+ key = (VirtualKey)Enum.Parse(typeof(VirtualKey), item, true);
+ }
+ }
+ User32.RegisterHotKey(hwnd, (int)id, modifiers, (uint)key);
+ _hotKeyActions[(int)id] = action;
}
- public static void UnregisterAllHotKeys(Window window)
+ public static void UnregisterHotKey(ShortcutID id)
{
+ var window = WindowHelper.GetWindowByWindowType();
+ if (window == null) return;
+
HWND hwnd = WindowNative.GetWindowHandle(window);
- foreach (var id in _hotKeyActions.Keys.ToList())
- {
- User32.UnregisterHotKey(hwnd, id);
- _hotKeyActions.Remove(id);
- }
+ User32.UnregisterHotKey(hwnd, (int)id);
+ _hotKeyActions.Remove((int)id);
+ }
+
+ public static void UpdateHotKey(ShortcutID id, List keys, Action action)
+ {
+ UnregisterHotKey(id);
+ RegisterHotKey(id, keys, action);
+ }
+
+ public static bool TryInvokeAction(ShortcutID id)
+ {
+ return TryInvokeAction((int)id);
}
public static bool TryInvokeAction(int id)
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LatestOnlyTaskRunner.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LatestOnlyTaskRunner.cs
deleted file mode 100644
index eff577e..0000000
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LatestOnlyTaskRunner.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-using Nito.AsyncEx;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace BetterLyrics.WinUI3.Helper
-{
- public class LatestOnlyTaskRunner
- {
- private readonly AsyncLock _mutex = new();
- private CancellationTokenSource _cts;
-
- public async Task RunAsync(Func action)
- {
- CancellationTokenSource oldCts;
-
- // 使用 AsyncLock 保证线程安全
- using (await _mutex.LockAsync())
- {
- // 取消旧的
- oldCts = _cts;
- _cts = new CancellationTokenSource();
- }
-
- oldCts?.Cancel();
- oldCts?.Dispose();
-
- CancellationToken token = _cts.Token;
-
- try
- {
- await action(token);
- }
- catch (OperationCanceledException)
- {
- // 可以选择忽略取消异常
- }
- }
- }
-}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/MetadataHelper.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/MetadataHelper.cs
index 57f9db3..bf1804c 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/MetadataHelper.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/MetadataHelper.cs
@@ -1,17 +1,9 @@
// 2025/6/23 by Zhe Fang
+using Windows.ApplicationModel;
+
namespace BetterLyrics.WinUI3.Helper
{
- using BetterLyrics.WinUI3.Models;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Reflection;
- using System.Threading.Tasks;
- using Windows.ApplicationModel;
- using Windows.Storage;
- using Windows.Storage.FileProperties;
-
public static class MetadataHelper
{
public static string AppVersion
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/WindowHelper.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/WindowHelper.cs
index 08fd637..13c1bc4 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/WindowHelper.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/WindowHelper.cs
@@ -71,7 +71,7 @@ namespace BetterLyrics.WinUI3.Helper
if (typeof(T) == typeof(LyricsWindow))
{
var lyricsWindow = (LyricsWindow)window;
- lyricsWindow.ViewModel.InitLockHotKey();
+ lyricsWindow.ViewModel.InitShortcuts();
lyricsWindow.AutoSelectLyricsMode();
}
}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/LocalLyricsFolder.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/LocalLyricsFolder.cs
index a523ef8..ab51d19 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/LocalLyricsFolder.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/LocalLyricsFolder.cs
@@ -6,15 +6,15 @@ namespace BetterLyrics.WinUI3.Models
{
public partial class LocalMediaFolder : ObservableRecipient
{
- [ObservableProperty][NotifyPropertyChangedRecipients] public partial bool IsEnabled { get; set; }
+ [ObservableProperty][NotifyPropertyChangedRecipients] public partial bool IsEnabled { get; set; } = true;
+ [ObservableProperty][NotifyPropertyChangedRecipients] public partial bool IsRealTimeWatchEnabled { get; set; } = false;
[ObservableProperty][NotifyPropertyChangedRecipients] public partial string Path { get; set; }
public LocalMediaFolder() { }
- public LocalMediaFolder(string path, bool isEnabled)
+ public LocalMediaFolder(string path)
{
Path = path;
- IsEnabled = isEnabled;
}
}
}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/DesktopModeSettings.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/DesktopModeSettings.cs
index be9bf4c..5a69532 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/DesktopModeSettings.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/DesktopModeSettings.cs
@@ -13,7 +13,8 @@ namespace BetterLyrics.WinUI3.Models.Settings
{
[ObservableProperty][NotifyPropertyChangedRecipients] public partial Rect WindowBounds { get; set; } = new Rect(100, 100, 400, 200);
[ObservableProperty][NotifyPropertyChangedRecipients] public partial bool AutoLockOnDesktopMode { get; set; } = false;
- [ObservableProperty][NotifyPropertyChangedRecipients] public partial int LockHotKeyIndex { get; set; } = 'U' - 'A'; // Default to 'U' key
+ [ObservableProperty][NotifyPropertyChangedRecipients] public partial List LockShortcut { get; set; } = new List() { "Ctrl", "Alt", "U" };
+ [ObservableProperty][NotifyPropertyChangedRecipients] public partial List ToggleShortcut { get; set; } = new List() { "Ctrl", "Alt", "D" };
public DesktopModeSettings()
{
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/DockModeSettings.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/DockModeSettings.cs
index ba4ec6f..e7e6b78 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/DockModeSettings.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/DockModeSettings.cs
@@ -14,7 +14,8 @@ namespace BetterLyrics.WinUI3.Models.Settings
[ObservableProperty][NotifyPropertyChangedRecipients] public partial DockPlacement DockPlacement { get; set; } = DockPlacement.Top;
[ObservableProperty][NotifyPropertyChangedRecipients] public partial int DockWindowHeight { get; set; } = 64;
[ObservableProperty][NotifyPropertyChangedRecipients] public partial string DockMonitorDeviceName { get; set; } = MonitorHelper.GetPrimaryMonitorDeviceName();
-
+ [ObservableProperty][NotifyPropertyChangedRecipients] public partial List ToggleShortcut { get; set; } = new List { "Ctrl", "Shift", "D" };
+
public DockModeSettings()
{
LyricsDisplayType = LyricsDisplayType.LyricsOnly;
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/GeneralSettings.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/GeneralSettings.cs
index 0eab1c8..4feeae7 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/GeneralSettings.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/GeneralSettings.cs
@@ -18,6 +18,9 @@ namespace BetterLyrics.WinUI3.Models.Settings
[ObservableProperty][NotifyPropertyChangedRecipients] public partial bool IsDragEverywhereEnabled { get; set; } = false;
[ObservableProperty][NotifyPropertyChangedRecipients] public partial bool IsImmersiveMode { get; set; } = false;
[ObservableProperty][NotifyPropertyChangedRecipients] public partial bool ExitOnLyricsWindowClosed { get; set; } = true;
+ [ObservableProperty][NotifyPropertyChangedRecipients] public partial List PlayOrPauseShortcut { get; set; } = new List { "Ctrl", "Alt", "P" };
+ [ObservableProperty][NotifyPropertyChangedRecipients] public partial List NextSongShortcut { get; set; } = new List { "Ctrl", "Alt", "Right" };
+ [ObservableProperty][NotifyPropertyChangedRecipients] public partial List PreviousSongShortcut { get; set; } = new List { "Ctrl", "Alt", "Left" };
public GeneralSettings() { }
}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/PictureInPictureModeSettings.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/PictureInPictureModeSettings.cs
index 227fe44..272d0ec 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/PictureInPictureModeSettings.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Models/Settings/PictureInPictureModeSettings.cs
@@ -1,4 +1,5 @@
-using System;
+using CommunityToolkit.Mvvm.ComponentModel;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -8,6 +9,8 @@ namespace BetterLyrics.WinUI3.Models.Settings
{
public partial class PictureInPictureModeSettings : BaseModeSettings
{
+ [ObservableProperty][NotifyPropertyChangedRecipients] public partial List ToggleShortcut { get; set; } = new List() { "Ctrl", "Shift", "P" };
+
public PictureInPictureModeSettings()
{
LyricsDisplayType = Enums.LyricsDisplayType.SplitView;
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/AlbumArtSearchService/AlbumArtSearchService.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/AlbumArtSearchService/AlbumArtSearchService.cs
index 2fd5d93..d5a2a69 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/AlbumArtSearchService/AlbumArtSearchService.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/AlbumArtSearchService/AlbumArtSearchService.cs
@@ -1,6 +1,7 @@
using ATL;
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Helper;
+using BetterLyrics.WinUI3.Helper.BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Services.SettingsService;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.Extensions.Logging;
@@ -33,34 +34,41 @@ namespace BetterLyrics.WinUI3.Services.AlbumArtSearchService
{
byte[]? result = null;
- foreach (var provider in _settingsService.AppSettings.MediaSourceProvidersInfo.Where(x => x.Provider == mediaSessionId).FirstOrDefault()?.AlbumArtSearchProvidersInfo ?? [])
+ try
{
- if (!provider.IsEnabled)
+ foreach (var provider in _settingsService.AppSettings.MediaSourceProvidersInfo.Where(x => x.Provider == mediaSessionId).FirstOrDefault()?.AlbumArtSearchProvidersInfo ?? [])
{
- continue;
- }
+ if (!provider.IsEnabled)
+ {
+ continue;
+ }
- switch (provider.Provider)
- {
- case AlbumArtSearchProvider.Local:
- result = SearchFile(artist, title);
- break;
- case AlbumArtSearchProvider.SMTC:
- result = bytesFromSMTC;
- break;
- case AlbumArtSearchProvider.iTunes:
- foreach (string countryCode in new List() { "us", "cn", "jp", "kr" })
- {
- result = await SearchiTunesAsync(artist, album, title, countryCode);
- if (result != null) break;
- }
- break;
- default:
- break;
- }
+ switch (provider.Provider)
+ {
+ case AlbumArtSearchProvider.Local:
+ result = SearchFile(artist, title);
+ break;
+ case AlbumArtSearchProvider.SMTC:
+ result = bytesFromSMTC;
+ break;
+ case AlbumArtSearchProvider.iTunes:
+ foreach (string countryCode in new List() { "us", "cn", "jp", "kr" })
+ {
+ result = await SearchiTunesAsync(artist, album, title, countryCode);
+ if (result != null) break;
+ }
+ break;
+ default:
+ break;
+ }
- if (result != null) return result;
+ if (result != null) return result;
+ }
}
+ catch (Exception)
+ {
+ }
+
return null;
}
@@ -70,9 +78,9 @@ namespace BetterLyrics.WinUI3.Services.AlbumArtSearchService
{
if (Directory.Exists(folder.Path) && folder.IsEnabled)
{
- try
+ foreach (var file in DirectoryHelper.GetAllFiles(folder.Path))
{
- foreach (var file in Directory.GetFiles(folder.Path, $"*.*", SearchOption.AllDirectories))
+ if (FileHelper.MusicExtensions.Contains(Path.GetExtension(file)))
{
Track track = new(file);
if ((track.Title == title && track.Artist == artist) || FileHelper.IsSwitchableNormalizedMatch(Path.GetFileNameWithoutExtension(file), artist, title))
@@ -85,9 +93,6 @@ namespace BetterLyrics.WinUI3.Services.AlbumArtSearchService
}
}
}
- catch (Exception)
- {
- }
}
}
return null;
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/LibWatcherService/LibWatcherService.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/LibWatcherService/LibWatcherService.cs
index 263e816..3a3ee75 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/LibWatcherService/LibWatcherService.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/LibWatcherService/LibWatcherService.cs
@@ -52,7 +52,7 @@ namespace BetterLyrics.WinUI3.Services.LibWatcherService
// 移除不再监听的
foreach (var key in _watchers.Keys.ToList())
{
- if (!folders.Any(x => x.Path == key && x.IsEnabled))
+ if (!folders.Any(x => x.Path == key && x.IsEnabled && x.IsRealTimeWatchEnabled))
{
_watchers[key].Dispose();
_watchers.Remove(key);
@@ -62,11 +62,7 @@ namespace BetterLyrics.WinUI3.Services.LibWatcherService
// 添加新的监听
foreach (var folder in folders)
{
- if (
- !_watchers.ContainsKey(folder.Path)
- && Directory.Exists(folder.Path)
- && folder.IsEnabled
- )
+ if (!_watchers.ContainsKey(folder.Path) && Directory.Exists(folder.Path) && folder.IsEnabled && folder.IsRealTimeWatchEnabled)
{
var watcher = new FileSystemWatcher(folder.Path)
{
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/LyricsSearchService/LyricsSearchService.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/LyricsSearchService/LyricsSearchService.cs
index df642c5..58ad6c1 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/LyricsSearchService/LyricsSearchService.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/LyricsSearchService/LyricsSearchService.cs
@@ -3,6 +3,7 @@
using ATL;
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Helper;
+using BetterLyrics.WinUI3.Helper.BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Services.SettingsService;
using CommunityToolkit.Mvvm.DependencyInjection;
using Lyricify.Lyrics.Providers.Web.Kugou;
@@ -175,7 +176,7 @@ namespace BetterLyrics.WinUI3.Services.LyricsSearchService
{
try
{
- foreach (var file in Directory.GetFiles(folder.Path, $"*{format.ToFileExtension()}", SearchOption.AllDirectories))
+ foreach (var file in DirectoryHelper.GetAllFiles(folder.Path, $"*{format.ToFileExtension()}"))
{
if (FileHelper.IsSwitchableNormalizedMatch(Path.GetFileNameWithoutExtension(file), title, artist))
{
@@ -201,30 +202,21 @@ namespace BetterLyrics.WinUI3.Services.LyricsSearchService
{
if (Directory.Exists(folder.Path) && folder.IsEnabled)
{
- try
+ foreach (var file in DirectoryHelper.GetAllFiles(folder.Path))
{
- foreach (var file in Directory.GetFiles(folder.Path, $"*.*", SearchOption.AllDirectories))
+ if (FileHelper.MusicExtensions.Contains(Path.GetExtension(file)))
{
var track = new Track(file);
if ((track.Title == title && track.Artist == artist) || FileHelper.IsSwitchableNormalizedMatch(Path.GetFileNameWithoutExtension(file), title, artist))
{
- try
- {
- var plain = TagLib.File.Create(file).Tag.Lyrics;
- if (!plain.IsNullOrEmpty())
- {
- return plain;
- }
- }
- catch (Exception)
+ var plain = TagLib.File.Create(file).Tag.Lyrics;
+ if (!plain.IsNullOrEmpty())
{
+ return plain;
}
}
}
}
- catch (Exception)
- {
- }
}
}
return null;
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/MediaSessionsService/MediaSessionsService.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/MediaSessionsService/MediaSessionsService.cs
index fc890b4..5f2cd4b 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/MediaSessionsService/MediaSessionsService.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/MediaSessionsService/MediaSessionsService.cs
@@ -10,6 +10,7 @@ using BetterLyrics.WinUI3.Services.AlbumArtSearchService;
using BetterLyrics.WinUI3.Services.LastFMService;
using BetterLyrics.WinUI3.Services.SettingsService;
using BetterLyrics.WinUI3.ViewModels;
+using BetterLyrics.WinUI3.Views;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
@@ -36,6 +37,7 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
{
public partial class MediaSessionsService : BaseViewModel, IMediaSessionsService,
IRecipient>,
+ IRecipient>>,
IRecipient>>
{
private readonly IAlbumArtSearchService _albumArtSearchService;
@@ -52,8 +54,8 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
private readonly MediaManager _mediaManager = new();
- private readonly LatestOnlyTaskRunner _albumArtRefreshRunner = new();
- private readonly LatestOnlyTaskRunner _onAnyMediaPropertyChangedRunner = new();
+ private readonly BackgroundTaskRunner _albumArtRefreshRunner = new();
+ private readonly BackgroundTaskRunner _onAnyMediaPropertyChangedRunner = new();
private SongInfo? _cachedSongInfo;
private byte[]? _SMTCAlbumArtBytes = null;
@@ -75,22 +77,55 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
_settingsService.AppSettings.LocalMediaFolders.ItemPropertyChanged += LocalMediaFolders_ItemPropertyChanged;
InitMediaManager();
+ InitPlaybackShortcuts();
+ }
+
+ private void InitPlaybackShortcuts()
+ {
+ UpdatePlayOrPauseSongShortcut();
+ UpdatePreviousSongShortcut();
+ UpdateNextSongShortcut();
+ }
+
+ private void UpdatePlayOrPauseSongShortcut()
+ {
+ GlobalHotKeyHelper.UpdateHotKey(ShortcutID.PlayOrPauseSong, _settingsService.AppSettings.GeneralSettings.PlayOrPauseShortcut, () =>
+ {
+ if (_cachedIsPlaying)
+ {
+ _ = PauseAsync();
+ }
+ else
+ {
+ _ = PlayAsync();
+ }
+ });
+ }
+
+ private void UpdatePreviousSongShortcut()
+ {
+ GlobalHotKeyHelper.UpdateHotKey(ShortcutID.PreviousSong, _settingsService.AppSettings.GeneralSettings.PreviousSongShortcut, () =>
+ {
+ _ = PreviousAsync();
+ });
+ }
+
+ private void UpdateNextSongShortcut()
+ {
+ GlobalHotKeyHelper.UpdateHotKey(ShortcutID.NextSong, _settingsService.AppSettings.GeneralSettings.NextSongShortcut, () =>
+ {
+ _ = NextAsync();
+ });
}
private void LocalMediaFolders_ItemPropertyChanged(object? sender, ItemPropertyChangedEventArgs e)
{
- _ = _albumArtRefreshRunner.RunAsync(async token =>
- {
- await UpdateAlbumArtRelated(token);
- });
+ UpdateAlbumArtRelated();
}
private void LocalMediaFolders_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
- _ = _albumArtRefreshRunner.RunAsync(async token =>
- {
- await UpdateAlbumArtRelated(token);
- });
+ UpdateAlbumArtRelated();
}
private void MediaSourceProvidersInfo_ItemPropertyChanged(object? sender, ItemPropertyChangedEventArgs e)
@@ -98,10 +133,7 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
switch (e.PropertyName)
{
case nameof(MediaSourceProviderInfo.AlbumArtSearchProvidersInfo):
- _ = _albumArtRefreshRunner.RunAsync(async tokne =>
- {
- await UpdateAlbumArtRelated(tokne);
- });
+ UpdateAlbumArtRelated();
break;
default:
break;
@@ -213,7 +245,7 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
{
_cachedSongInfo = null;
- _onAnyMediaPropertyChangedRunner.RunAsync(async token =>
+ _onAnyMediaPropertyChangedRunner.Run(async token =>
{
_logger.LogInformation("Media properties changed: Title: {Title}, Artist: {Artist}, Album: {Album}",
mediaProperties.Title, mediaProperties.Artist, mediaProperties.AlbumTitle);
@@ -225,10 +257,7 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
_SMTCAlbumArtBytes = null;
- await _albumArtRefreshRunner.RunAsync(async tokne =>
- {
- await UpdateAlbumArtRelated(tokne);
- });
+ UpdateAlbumArtRelated();
if (!token.IsCancellationRequested)
{
@@ -237,7 +266,7 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
SongInfoChanged?.Invoke(this, new SongInfoChangedEventArgs(_cachedSongInfo));
});
}
- }).ConfigureAwait(false);
+ });
}
else
{
@@ -261,7 +290,7 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
_cachedSongInfo.Duration = (int)(_cachedSongInfo.DurationMs / 1000f);
- _onAnyMediaPropertyChangedRunner.RunAsync(async token =>
+ _onAnyMediaPropertyChangedRunner.Run(async token =>
{
_logger.LogInformation("Media properties changed: Title: {Title}, Artist: {Artist}, Album: {Album}",
mediaProperties.Title, mediaProperties.Artist, mediaProperties.AlbumTitle);
@@ -284,10 +313,7 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
_SMTCAlbumArtBytes = null;
}
- await _albumArtRefreshRunner.RunAsync(async tokne =>
- {
- await UpdateAlbumArtRelated(tokne);
- });
+ UpdateAlbumArtRelated();
if (!token.IsCancellationRequested)
{
@@ -296,7 +322,7 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
SongInfoChanged?.Invoke(this, new SongInfoChangedEventArgs(_cachedSongInfo));
});
}
- }).ConfigureAwait(false);
+ });
}
}
@@ -361,47 +387,51 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
MediaManager_OnAnyPlaybackStateChanged(focusedSession, focusedSession.ControlSession.GetPlaybackInfo());
}
- private async Task UpdateAlbumArtRelated(CancellationToken token)
+ private void UpdateAlbumArtRelated()
{
- if (_cachedSongInfo == null)
+ _albumArtRefreshRunner.Run(async (token) =>
{
- _logger.LogWarning("Cached song info is null, cannot update album art.");
- return;
- }
+ if (_cachedSongInfo == null)
+ {
+ _logger.LogWarning("Cached song info is null, cannot update album art.");
+ return;
+ }
- byte[]? bytes = await _albumArtSearchService.SearchAsync(
- SongInfo?.SourceAppUserModelId ?? "",
- _cachedSongInfo.Title,
- _cachedSongInfo.Artist,
- _cachedSongInfo?.Album ?? string.Empty,
- _SMTCAlbumArtBytes
- );
- token.ThrowIfCancellationRequested();
-
- if (bytes == null)
- {
- bytes = await ImageHelper.CreateTextPlaceholderBytesAsync(500, 500);
+ byte[]? bytes = await _albumArtSearchService.SearchAsync(
+ SongInfo?.SourceAppUserModelId ?? "",
+ _cachedSongInfo.Title,
+ _cachedSongInfo.Artist,
+ _cachedSongInfo?.Album ?? string.Empty,
+ _SMTCAlbumArtBytes
+ );
token.ThrowIfCancellationRequested();
- }
- bytes = ImageHelper.MakeSquareWithThemeColor(bytes);
+ if (bytes == null)
+ {
+ bytes = await ImageHelper.CreateTextPlaceholderBytesAsync(500, 500);
+ token.ThrowIfCancellationRequested();
+ }
- using var stream = new InMemoryRandomAccessStream();
- await stream.WriteAsync(bytes.AsBuffer());
- token.ThrowIfCancellationRequested();
+ bytes = ImageHelper.MakeSquareWithThemeColor(bytes);
- var decoder = await BitmapDecoder.CreateAsync(stream);
- token.ThrowIfCancellationRequested();
+ using var stream = new InMemoryRandomAccessStream();
+ await stream.WriteAsync(bytes.AsBuffer());
+ token.ThrowIfCancellationRequested();
- var albumArtSwBitmap = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied);
- token.ThrowIfCancellationRequested();
+ var decoder = await BitmapDecoder.CreateAsync(stream);
+ token.ThrowIfCancellationRequested();
- var albumArtLightAccentColor = ImageHelper.GetAccentColorsFromByte(bytes, 1, false).FirstOrDefault();
- var albumArtDarkAccentColor = ImageHelper.GetAccentColorsFromByte(bytes, 1, true).FirstOrDefault();
+ var albumArtSwBitmap = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied);
+ token.ThrowIfCancellationRequested();
+
+ var albumArtLightAccentColor = ImageHelper.GetAccentColorsFromByte(bytes, 1, false).FirstOrDefault();
+ var albumArtDarkAccentColor = ImageHelper.GetAccentColorsFromByte(bytes, 1, true).FirstOrDefault();
+
+ _dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () =>
+ {
+ AlbumArtChangedChanged?.Invoke(this, new AlbumArtChangedEventArgs(null, albumArtSwBitmap, albumArtLightAccentColor, albumArtDarkAccentColor));
+ });
- _dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () =>
- {
- AlbumArtChangedChanged?.Invoke(this, new AlbumArtChangedEventArgs(null, albumArtSwBitmap, albumArtLightAccentColor, albumArtDarkAccentColor));
});
}
@@ -517,7 +547,7 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
return _settingsService.AppSettings.MediaSourceProvidersInfo.Where(x => x.Provider == _cachedSongInfo?.SourceAppUserModelId)?.FirstOrDefault();
}
- public async void Receive(PropertyChangedMessage message)
+ public void Receive(PropertyChangedMessage message)
{
if (message.Sender is MediaSourceProviderInfo)
{
@@ -530,10 +560,7 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
{
if (message.PropertyName == nameof(AlbumArtSearchProviderInfo.IsEnabled))
{
- await _albumArtRefreshRunner.RunAsync(async tokne =>
- {
- await UpdateAlbumArtRelated(tokne);
- });
+ UpdateAlbumArtRelated();
}
}
}
@@ -541,5 +568,24 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
public void Receive(PropertyChangedMessage> message)
{
}
+
+ public void Receive(PropertyChangedMessage> message)
+ {
+ if (message.Sender is GeneralSettings)
+ {
+ if (message.PropertyName == nameof(GeneralSettings.PlayOrPauseShortcut))
+ {
+ UpdatePlayOrPauseSongShortcut();
+ }
+ else if (message.PropertyName == nameof(GeneralSettings.PreviousSongShortcut))
+ {
+ UpdatePreviousSongShortcut();
+ }
+ else if (message.PropertyName == nameof(GeneralSettings.NextSongShortcut))
+ {
+ UpdateNextSongShortcut();
+ }
+ }
+ }
}
}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/en-US/Resources.resw b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/en-US/Resources.resw
index e833316..66ab008 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/en-US/Resources.resw
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/en-US/Resources.resw
@@ -178,7 +178,7 @@
Dock mode
- To unlock after locking, go to the system tray to unlock or press
+ Lock
More
@@ -871,6 +871,12 @@ If you encounter any problems, please go to the Settings page, About tab, and vi
Local media library
+
+ Listen to file changes in real time
+
+
+ Next track shortcut keys
+
None
@@ -895,9 +901,18 @@ If you encounter any problems, please go to the Settings page, About tab, and vi
No playback source captured
+
+ Play
+
Play "Cut To The Feeling" on "soundcloud.com"
+
+ Play and Pause Shortcuts
+
+
+ Shortcut keys for the previous track
+
QQ feedback & chat group
@@ -982,6 +997,9 @@ If you encounter any problems, please go to the Settings page, About tab, and vi
Title bar size
+
+ Switch in and cut out shortcut keys
+
Lyrics translation
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ja-JP/Resources.resw b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ja-JP/Resources.resw
index d3f8c82..e8f1f69 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ja-JP/Resources.resw
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ja-JP/Resources.resw
@@ -178,7 +178,7 @@
ドックモード
- ロック後にロックを解除するには、システムトレイに移動してロックを解除または押します
+ ロック
もっと
@@ -871,6 +871,12 @@
地元のメディア図書館
+
+ ファイルの変更をリアルタイムで聞いてください
+
+
+ 次のトラックショートカットキー
+
なし
@@ -895,9 +901,18 @@
キャプチャされた再生ソースはありません
+
+ 遊ぶ
+
「SoundCloud.com」で「Cut to the Feeling」を再生する
+
+ ショートカットを再生して一時停止します
+
+
+ 前のトラックのショートカットキー
+
QQフィードバック&チャットグループ
@@ -982,6 +997,9 @@
タイトルバーサイズ
+
+ ショートカットキーを切り込んで切り取ります
+
歌詞翻訳
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ko-KR/Resources.resw b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ko-KR/Resources.resw
index f94689e..522142f 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ko-KR/Resources.resw
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ko-KR/Resources.resw
@@ -178,7 +178,7 @@
도크 모드
- 잠금 잠금을 해제하려면 시스템 트레이로 이동하여 잠금을 해제하거나 누릅니다.
+ 잠금
더
@@ -871,6 +871,12 @@
로컬 미디어 라이브러리
+
+ 실시간으로 파일 변경을 듣습니다
+
+
+ 다음 트랙 바로 가기 키
+
없음
@@ -895,9 +901,18 @@
재생 소스가 캡처되지 않았습니다
+
+ 놀다
+
"soundcloud.com"에서 "Fut to the Feeling"을 재생하십시오.
+
+ 바로 가기를 재생하고 일시 중지합니다
+
+
+ 이전 트랙의 바로 가기 키
+
QQ 피드백 및 채팅 그룹
@@ -982,6 +997,9 @@
제목 바 크기
+
+ 바로 가기 키를 자르고 잘라냅니다
+
가사 번역
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-CN/Resources.resw b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-CN/Resources.resw
index 5457f2a..fc1e48d 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-CN/Resources.resw
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-CN/Resources.resw
@@ -178,7 +178,7 @@
停靠模式
- 锁定后解锁,请转到系统托盘解锁或按下
+ 锁定
更多
@@ -871,6 +871,12 @@
本地媒体库
+
+ 实时监听文件变化
+
+
+ 下一首曲目快捷键
+
无
@@ -895,9 +901,18 @@
没有捕获的播放源
+
+ 播放
+
在 “soundcloud.com” 上播放 “Cut to the Feeling”
+
+ 播放与暂停快捷键
+
+
+ 上一首曲目快捷键
+
QQ 反馈交流群
@@ -982,6 +997,9 @@
标题栏大小
+
+ 切入与切出快捷键
+
歌词翻译
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-TW/Resources.resw b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-TW/Resources.resw
index 4c15459..dc832a6 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-TW/Resources.resw
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-TW/Resources.resw
@@ -178,7 +178,7 @@
停靠模式
- 鎖定後解鎖,請轉到系統托盤解鎖或按下
+ 鎖定
更多
@@ -871,6 +871,12 @@
本地音樂資料庫
+
+ 實時監聽文件變化
+
+
+ 下一首曲目快捷鍵
+
無
@@ -895,9 +901,18 @@
沒有捕獲的播放源
+
+ 播放
+
在 “soundcloud.com” 上播放 “Cut to the Feeling”
+
+ 播放與暫停快捷鍵
+
+
+ 上一首曲目快捷鍵
+
QQ 回饋交流群
@@ -982,6 +997,9 @@
標題列大小
+
+ 切入與切出快捷鍵
+
歌詞翻譯
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel/LyricsRendererViewModel.Ctor.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel/LyricsRendererViewModel.Ctor.cs
index aaa1958..04c2d61 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel/LyricsRendererViewModel.Ctor.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel/LyricsRendererViewModel.Ctor.cs
@@ -64,7 +64,7 @@ namespace BetterLyrics.WinUI3.ViewModels.LyricsRendererViewModel
{
// Music lib changed, re-fetch lyrics
_logger.LogInformation("Local lyrics folders changed, refreshing lyrics.");
- _ = _refreshLyricsRunner.RunAsync(async tokne =>
+ _refreshLyricsRunner.Run(async tokne =>
{
await RefreshLyricsAsync(tokne);
});
@@ -74,7 +74,7 @@ namespace BetterLyrics.WinUI3.ViewModels.LyricsRendererViewModel
{
// Music lib changed, re-fetch lyrics
_logger.LogInformation("Local lyrics folders changed, refreshing lyrics.");
- _ = _refreshLyricsRunner.RunAsync(async tokne =>
+ _refreshLyricsRunner.Run(async tokne =>
{
await RefreshLyricsAsync(tokne);
});
@@ -86,7 +86,7 @@ namespace BetterLyrics.WinUI3.ViewModels.LyricsRendererViewModel
{
case nameof(MediaSourceProviderInfo.LyricsSearchProvidersInfo):
_logger.LogInformation("MediaSourceProviderInfo.LyricsSearchProvidersInfo changed, refreshing lyrics.");
- _ = _refreshLyricsRunner.RunAsync(async token =>
+ _refreshLyricsRunner.Run(async token =>
{
await RefreshLyricsAsync(token);
});
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel/LyricsRendererViewModel.Messages.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel/LyricsRendererViewModel.Messages.cs
index 111ddff..05731be 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel/LyricsRendererViewModel.Messages.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel/LyricsRendererViewModel.Messages.cs
@@ -94,7 +94,7 @@ namespace BetterLyrics.WinUI3.ViewModels.LyricsRendererViewModel
if (message.PropertyName == nameof(LyricsSearchProviderInfo.IsEnabled))
{
_logger.LogInformation("LyricsSearchProviderInfo.IsEnabled changed, refreshing lyrics.");
- _ = _refreshLyricsRunner.RunAsync(async token =>
+ _refreshLyricsRunner.Run(async token =>
{
await RefreshLyricsAsync(token);
});
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel/LyricsRendererViewModel.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel/LyricsRendererViewModel.cs
index d20b521..f801790 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel/LyricsRendererViewModel.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel/LyricsRendererViewModel.cs
@@ -178,8 +178,8 @@ namespace BetterLyrics.WinUI3.ViewModels.LyricsRendererViewModel
FontWeight = FontWeights.ExtraBlack,
};
- private LatestOnlyTaskRunner _refreshLyricsRunner = new();
- private LatestOnlyTaskRunner _showTranslationsRunner = new();
+ private BackgroundTaskRunner _refreshLyricsRunner = new();
+ private BackgroundTaskRunner _showTranslationsRunner = new();
private LyricsLayoutOrientation _lyricsLayoutOrientation;
@@ -322,7 +322,7 @@ namespace BetterLyrics.WinUI3.ViewModels.LyricsRendererViewModel
private void LibWatcherService_MusicLibraryFilesChanged(object? sender, LibChangedEventArgs e)
{
_logger.LogInformation("Music library files changed: {ChangeType} {FilePath}, refreshing lyrics...", e.ChangeType, e.FilePath);
- _ = _refreshLyricsRunner.RunAsync(async token =>
+ _refreshLyricsRunner.Run(async token =>
{
await RefreshLyricsAsync(token);
});
@@ -374,7 +374,7 @@ namespace BetterLyrics.WinUI3.ViewModels.LyricsRendererViewModel
_songInfoOpacityTransition.StartTransition(1f);
_logger.LogInformation("Song info changed: Title={Title}, Artist={Artist}, refreshing lyrics...", _songTitle, _songArtist);
- _ = _refreshLyricsRunner.RunAsync(async token =>
+ _refreshLyricsRunner.Run(async token =>
{
await RefreshLyricsAsync(token);
});
@@ -430,7 +430,7 @@ namespace BetterLyrics.WinUI3.ViewModels.LyricsRendererViewModel
IsTranslating = true;
if (_settingsService.AppSettings.TranslationSettings.IsTranslationEnabled)
{
- _ = _refreshLyricsRunner.RunAsync(async token =>
+ _refreshLyricsRunner.Run(async token =>
{
await SetDisplayedAlongWithTranslationsAsync(token);
IsTranslating = false;
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsWindowViewModel.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsWindowViewModel.cs
index 6a08ff3..f955561 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsWindowViewModel.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsWindowViewModel.cs
@@ -18,6 +18,8 @@ using CommunityToolkit.Mvvm.Messaging.Messages;
using CommunityToolkit.WinUI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
+using Microsoft.UI.Xaml.Controls;
+using System.Collections.Generic;
using Vanara.PInvoke;
using Windows.System;
using Windows.UI;
@@ -29,6 +31,7 @@ namespace BetterLyrics.WinUI3
public partial class LyricsWindowViewModel
: BaseWindowViewModel,
IRecipient>,
+ IRecipient>>,
IRecipient>,
IRecipient>,
IRecipient>,
@@ -52,6 +55,7 @@ namespace BetterLyrics.WinUI3
_mediaSessionsService = mediaSessionsService;
_liveStatesService = liveStatesService;
+ AppSettings = _settingsService.AppSettings;
LiveStates = _liveStatesService.LiveStates;
_dockMonitorDeviceName = _settingsService.AppSettings.DockModeSettings.DockMonitorDeviceName;
@@ -70,6 +74,9 @@ namespace BetterLyrics.WinUI3
UpdateDockOrDesktopWindow();
}
+ [ObservableProperty]
+ public partial AppSettings AppSettings { get; set; }
+
[ObservableProperty]
public partial LiveStates LiveStates { get; set; }
@@ -98,8 +105,18 @@ namespace BetterLyrics.WinUI3
[NotifyPropertyChangedRecipients]
public partial bool IsMouseWithinWindow { get; set; } = false;
- [ObservableProperty]
- public partial string LockHotKey { get; set; } = "";
+ [ObservableProperty] public partial Visibility AOTFlyoutItemVisibility { get; set; } = Visibility.Visible;
+ [ObservableProperty] public partial Visibility FullScreenFlyoutItemVisibility { get; set; } = Visibility.Visible;
+ [ObservableProperty] public partial Visibility LockButtonVisibility { get; set; } = Visibility.Visible;
+ [ObservableProperty] public partial Visibility DesktopFlyoutItemVisibility { get; set; } = Visibility.Visible;
+ [ObservableProperty] public partial Visibility PIPFlyoutItemVisibility { get; set; } = Visibility.Visible;
+ [ObservableProperty] public partial Visibility DockFlyoutItemVisibility { get; set; } = Visibility.Visible;
+
+ [ObservableProperty] public partial bool IsAOTFlyoutItemChecked { get; set; } = false;
+ [ObservableProperty] public partial bool IsFullScreenFlyoutItemChecked { get; set; } = false;
+ [ObservableProperty] public partial bool IsDesktopFlyoutItemChecked { get; set; } = false;
+ [ObservableProperty] public partial bool IsPIPFlyoutItemChecked { get; set; } = false;
+ [ObservableProperty] public partial bool IsDockFlyoutItemChecked { get; set; } = false;
private void UpdateDockOrDesktopWindow()
{
@@ -188,34 +205,129 @@ namespace BetterLyrics.WinUI3
UpdateDockOrDesktopWindow();
}
}
- else if (message.Sender is DesktopModeSettings)
- {
- if (message.PropertyName == nameof(DesktopModeSettings.LockHotKeyIndex))
- {
- UpdateLockHotKey(message.NewValue);
- }
- }
}
- private void UpdateLockHotKey(int hotKeyIndex)
+ public void InitShortcuts()
{
- var window = WindowHelper.GetWindowByWindowType();
- if (window == null) return;
+ UpdateDesktopLockShortcut();
+ UpdateDesktopToggleShortcut();
+ UpdateDockToggleShortcut();
+ UpdatePictureInPictureToggleShortcut();
+ }
- GlobalHotKeyHelper.UnregisterAllHotKeys(window);
- GlobalHotKeyHelper.RegisterHotKey(
- window,
- User32.HotKeyModifiers.MOD_CONTROL | User32.HotKeyModifiers.MOD_ALT,
- (uint)(hotKeyIndex + (int)VirtualKey.A),
+ private void UpdateDesktopLockShortcut()
+ {
+ GlobalHotKeyHelper.UnregisterHotKey(ShortcutID.DesktopLock);
+ GlobalHotKeyHelper.RegisterHotKey(ShortcutID.DesktopLock,
+ _settingsService.AppSettings.DesktopModeSettings.LockShortcut,
() =>
{
if (LiveStates.CurrentLyricsWindowMode == LyricsWindowMode.DesktopMode)
{
- ToggleLockWindowCommand.Execute(null);
+ ToggleLockWindow();
}
}
);
- LockHotKey = ((VirtualKey)(hotKeyIndex + (int)VirtualKey.A)).ToString();
+ }
+
+ private void UpdateDesktopToggleShortcut()
+ {
+ GlobalHotKeyHelper.UnregisterHotKey(ShortcutID.DesktopToggle);
+ GlobalHotKeyHelper.RegisterHotKey(ShortcutID.DesktopToggle,
+ _settingsService.AppSettings.DesktopModeSettings.ToggleShortcut,
+ () =>
+ {
+ if (LiveStates.CurrentLyricsWindowMode == LyricsWindowMode.DesktopMode ||
+ LiveStates.CurrentLyricsWindowMode == LyricsWindowMode.StandardMode)
+ {
+ ToggleDesktopMode();
+ }
+ }
+ );
+ }
+
+ private void UpdateDockToggleShortcut()
+ {
+ GlobalHotKeyHelper.UnregisterHotKey(ShortcutID.DockToggle);
+ GlobalHotKeyHelper.RegisterHotKey(ShortcutID.DockToggle,
+ _settingsService.AppSettings.DockModeSettings.ToggleShortcut,
+ () =>
+ {
+ if (LiveStates.CurrentLyricsWindowMode == LyricsWindowMode.DockMode ||
+ LiveStates.CurrentLyricsWindowMode == LyricsWindowMode.StandardMode)
+ {
+ ToggleDockMode();
+ }
+ }
+ );
+ }
+
+ private void UpdatePictureInPictureToggleShortcut()
+ {
+ GlobalHotKeyHelper.UnregisterHotKey(ShortcutID.PictureInPictureToggle);
+ GlobalHotKeyHelper.RegisterHotKey(ShortcutID.PictureInPictureToggle,
+ _settingsService.AppSettings.PictureInPictureModeSettings.ToggleShortcut,
+ () =>
+ {
+ if (LiveStates.CurrentLyricsWindowMode == LyricsWindowMode.PictureInPictureMode ||
+ LiveStates.CurrentLyricsWindowMode == LyricsWindowMode.StandardMode)
+ {
+ TogglePictureInPictureMode();
+ }
+ }
+ );
+ }
+
+ private void SetFullscreenTitleBarControlsStatus()
+ {
+ AOTFlyoutItemVisibility = LockButtonVisibility = DesktopFlyoutItemVisibility = PIPFlyoutItemVisibility = DockFlyoutItemVisibility = Visibility.Collapsed;
+ IsFullScreenFlyoutItemChecked = true;
+ IsImmersiveMode = true;
+ }
+
+ private void SetPIPModeTitleBarControlsStatus()
+ {
+ AOTFlyoutItemVisibility = DesktopFlyoutItemVisibility = FullScreenFlyoutItemVisibility = DockFlyoutItemVisibility = LockButtonVisibility = Visibility.Collapsed;
+ IsImmersiveMode = true;
+ IsPIPFlyoutItemChecked = true;
+ }
+
+ private void SetDockModeTitleBarControlsStatus()
+ {
+ var window = WindowHelper.GetWindowByWindowType();
+ if (window == null) return;
+ var overlappedPresenter = (OverlappedPresenter)window.AppWindow.Presenter;
+
+ overlappedPresenter.IsMinimizable = overlappedPresenter.IsMaximizable = false;
+ AOTFlyoutItemVisibility = DesktopFlyoutItemVisibility = LockButtonVisibility = FullScreenFlyoutItemVisibility = PIPFlyoutItemVisibility = Visibility.Collapsed;
+ IsImmersiveMode = true;
+ IsDockFlyoutItemChecked = true;
+ }
+
+ private void SetDesktopModeTitleBarControlsStatus()
+ {
+ var window = WindowHelper.GetWindowByWindowType();
+ if (window == null) return;
+ var overlappedPresenter = (OverlappedPresenter)window.AppWindow.Presenter;
+
+ overlappedPresenter.IsMinimizable = overlappedPresenter.IsMaximizable = false;
+ DockFlyoutItemVisibility = AOTFlyoutItemVisibility = FullScreenFlyoutItemVisibility = PIPFlyoutItemVisibility = Visibility.Collapsed;
+ LockButtonVisibility = Visibility.Visible;
+ IsDesktopFlyoutItemChecked = true;
+ }
+
+ public void SetStandardModeTitleBarControlsStatus()
+ {
+ var window = WindowHelper.GetWindowByWindowType();
+ if (window == null) return;
+ var overlappedPresenter = (OverlappedPresenter)window.AppWindow.Presenter;
+
+ overlappedPresenter.IsMinimizable = overlappedPresenter.IsMaximizable = true;
+ AOTFlyoutItemVisibility = DesktopFlyoutItemVisibility = DockFlyoutItemVisibility = PIPFlyoutItemVisibility = FullScreenFlyoutItemVisibility = Visibility.Visible;
+ LockButtonVisibility = Visibility.Collapsed;
+ IsFullScreenFlyoutItemChecked = IsDesktopFlyoutItemChecked = IsDockFlyoutItemChecked = IsPIPFlyoutItemChecked = false;
+ IsAOTFlyoutItemChecked = overlappedPresenter.IsAlwaysOnTop;
+ IsImmersiveMode = _settingsService.AppSettings.GeneralSettings.IsImmersiveMode;
}
public void StartWatchWindowColorChange()
@@ -267,13 +379,7 @@ namespace BetterLyrics.WinUI3
}
}
- public void InitLockHotKey()
- {
- UpdateLockHotKey(_settingsService.AppSettings.DesktopModeSettings.LockHotKeyIndex);
- }
-
- [RelayCommand]
- private void ToggleLockWindow()
+ public void ToggleLockWindow()
{
var window = WindowHelper.GetWindowByWindowType();
if (window == null) return;
@@ -294,8 +400,7 @@ namespace BetterLyrics.WinUI3
UpdateDockOrDesktopWindow();
}
- [RelayCommand]
- private void ToggleDesktopMode()
+ public void ToggleDesktopMode()
{
var window = WindowHelper.GetWindowByWindowType();
if (window == null) return;
@@ -307,15 +412,24 @@ namespace BetterLyrics.WinUI3
{
DesktopModeHelper.Enable(window);
StartWatchWindowColorChange();
+ if (_settingsService.AppSettings.DesktopModeSettings.AutoLockOnDesktopMode)
+ {
+ ToggleLockWindow();
+ }
+ SetDesktopModeTitleBarControlsStatus();
}
else
{
+ if (IsLyricsWindowLocked)
+ {
+ ToggleLockWindow();
+ }
DesktopModeHelper.Disable(window);
+ SetStandardModeTitleBarControlsStatus();
}
}
- [RelayCommand]
- private void ToggleDockMode()
+ public void ToggleDockMode()
{
var window = WindowHelper.GetWindowByWindowType();
if (window == null) return;
@@ -328,19 +442,65 @@ namespace BetterLyrics.WinUI3
window.Restore();
DockModeHelper.Enable(window, _dockMonitorDeviceName, _dockWindowHeight, _dockPlacement);
StartWatchWindowColorChange();
+ SetDockModeTitleBarControlsStatus();
}
else
{
DockModeHelper.Disable(window);
+ SetStandardModeTitleBarControlsStatus();
}
UpdateDockOrDesktopWindow();
}
- [RelayCommand]
- private void TogglePictureInPictureMode()
+ public void TogglePictureInPictureMode()
{
+ var window = WindowHelper.GetWindowByWindowType();
+ if (window == null) return;
+
LiveStates.ToggleLyricsWindowMode(LyricsWindowMode.PictureInPictureMode);
+ if (LiveStates.CurrentLyricsWindowMode == LyricsWindowMode.PictureInPictureMode)
+ {
+ window.AppWindow.SetPresenter(AppWindowPresenterKind.CompactOverlay);
+ SetPIPModeTitleBarControlsStatus();
+ }
+ else
+ {
+ window.AppWindow.SetPresenter(AppWindowPresenterKind.Overlapped);
+ SetStandardModeTitleBarControlsStatus();
+ }
+ }
+
+ public void ToggleAlwaysOnTop()
+ {
+ var window = WindowHelper.GetWindowByWindowType();
+ if (window == null) return;
+
+ if (window.AppWindow.Presenter is OverlappedPresenter presenter)
+ {
+ presenter.IsAlwaysOnTop = !presenter.IsAlwaysOnTop;
+ IsAOTFlyoutItemChecked = presenter.IsAlwaysOnTop;
+ }
+ }
+
+ public void ToggleFullscreen()
+ {
+ var window = WindowHelper.GetWindowByWindowType();
+ if (window == null) return;
+
+ switch (window.AppWindow.Presenter.Kind)
+ {
+ case AppWindowPresenterKind.FullScreen:
+ window.AppWindow.SetPresenter(AppWindowPresenterKind.Overlapped);
+ SetStandardModeTitleBarControlsStatus();
+ break;
+ case AppWindowPresenterKind.Overlapped:
+ window.AppWindow.SetPresenter(AppWindowPresenterKind.FullScreen);
+ SetFullscreenTitleBarControlsStatus();
+ break;
+ default:
+ break;
+ }
}
[RelayCommand]
@@ -372,5 +532,37 @@ namespace BetterLyrics.WinUI3
}
}
}
+
+ public void Receive(PropertyChangedMessage> message)
+ {
+ if (message.Sender is DesktopModeSettings)
+ {
+ if (message.PropertyName == nameof(DesktopModeSettings.LockShortcut))
+ {
+ UpdateDesktopLockShortcut();
+ }
+ }
+ else if (message.Sender is DockModeSettings)
+ {
+ if (message.PropertyName == nameof(DockModeSettings.ToggleShortcut))
+ {
+ UpdateDockToggleShortcut();
+ }
+ }
+ else if (message.Sender is PictureInPictureModeSettings)
+ {
+ if (message.PropertyName == nameof(PictureInPictureModeSettings.ToggleShortcut))
+ {
+ UpdatePictureInPictureToggleShortcut();
+ }
+ }
+ else if (message.Sender is DesktopModeSettings)
+ {
+ if (message.PropertyName == nameof(DesktopModeSettings.ToggleShortcut))
+ {
+ UpdateDesktopToggleShortcut();
+ }
+ }
+ }
}
}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/MediaSettingsControlViewModel.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/MediaSettingsControlViewModel.cs
index 7253300..842f4c5 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/MediaSettingsControlViewModel.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/MediaSettingsControlViewModel.cs
@@ -72,7 +72,7 @@ namespace BetterLyrics.WinUI3.ViewModels
}
else
{
- AppSettings.LocalMediaFolders.Add(new LocalMediaFolder(path, true));
+ AppSettings.LocalMediaFolders.Add(new LocalMediaFolder(path));
}
}
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/MusicGalleryViewModel.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/MusicGalleryViewModel.cs
index 92f98c7..3642153 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/MusicGalleryViewModel.cs
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/MusicGalleryViewModel.cs
@@ -2,6 +2,7 @@
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Extensions;
using BetterLyrics.WinUI3.Helper;
+using BetterLyrics.WinUI3.Helper.BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Models.Settings;
using BetterLyrics.WinUI3.Services;
@@ -265,31 +266,27 @@ namespace BetterLyrics.WinUI3.ViewModels
Task.Run(() =>
{
- foreach (var folder in _settingsService.AppSettings.LocalMediaFolders)
+ try
{
- if (Directory.Exists(folder.Path) && folder.IsEnabled)
+ foreach (var folder in _settingsService.AppSettings.LocalMediaFolders)
{
- try
+ if (Directory.Exists(folder.Path) && folder.IsEnabled)
{
- foreach (var file in Directory.GetFiles(folder.Path, $"*.*", SearchOption.AllDirectories))
+ foreach (var file in DirectoryHelper.GetAllFiles(folder.Path))
{
- try
+ if (FileHelper.MusicExtensions.Contains(Path.GetExtension(file)))
{
Track track = new(file);
if (track.Duration <= 0) continue;
_tracks.Add(track);
}
- catch (Exception)
- {
- continue;
- }
}
}
- catch (Exception)
- {
- }
}
}
+ catch (Exception)
+ {
+ }
_dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () =>
{
diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsWindow.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsWindow.xaml
index 4c7a0ff..c8d99d1 100644
--- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsWindow.xaml
+++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsWindow.xaml
@@ -48,7 +48,8 @@
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)