diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3 (Package)/Package.appxmanifest b/BetterLyrics.WinUI3/BetterLyrics.WinUI3 (Package)/Package.appxmanifest index 38ef457..3bdff2b 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3 (Package)/Package.appxmanifest +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3 (Package)/Package.appxmanifest @@ -12,7 +12,7 @@ + Version="1.0.18.0" /> diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj index 19882fa..530146b 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj @@ -63,6 +63,7 @@ + diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/DesktopModeHelper.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/DesktopModeHelper.cs index ff918fd..ee3ecdc 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/DesktopModeHelper.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/DesktopModeHelper.cs @@ -19,10 +19,8 @@ namespace BetterLyrics.WinUI3.Helper private static readonly ISettingsService _settingsService = Ioc.Default.GetRequiredService(); private static readonly Dictionary _originalTopmostStates = []; - private static readonly Dictionary _oldWndProcs = new(); private static readonly Dictionary _originalWindowBounds = []; private static readonly Dictionary _originalWindowStyles = []; - private static List _interactiveRects = new(); private delegate nint WndProcDelegate(nint hWnd, uint msg, nint wParam, nint lParam); @@ -103,16 +101,6 @@ namespace BetterLyrics.WinUI3.Helper window.ToggleWindowStyle(true, WindowStyle.Popup | WindowStyle.Visible); User32.SetWindowLong(hwnd, User32.WindowLongFlags.GWL_EXSTYLE, exStyle | (int)User32.WindowStylesEx.WS_EX_TRANSPARENT | (int)User32.WindowStylesEx.WS_EX_LAYERED); - - //// 安装自定义WndProc - //if (!_oldWndProcs.ContainsKey(hwnd)) - //{ - // nint newWndProc = Marshal.GetFunctionPointerForDelegate((WndProcDelegate)((hWnd, msg, wParam, lParam) => - // CustomWndProc(hWnd, msg, wParam, lParam, hwnd) - // )); - // nint oldWndProc = User32.SetWindowLong(hwnd, User32.WindowLongFlags.GWLP_WNDPROC, newWndProc); - // _oldWndProcs[hwnd] = oldWndProc; - //} } else { @@ -123,51 +111,7 @@ namespace BetterLyrics.WinUI3.Helper window.SetWindowStyle(style); _originalWindowStyles.Remove(hwnd); } - - //// 恢复原WndProc - //if (_oldWndProcs.TryGetValue(hwnd, out var oldWndProc)) - //{ - // User32.SetWindowLong(hwnd, User32.WindowLongFlags.GWLP_WNDPROC, oldWndProc); - // _oldWndProcs.Remove(hwnd); - //} } } - - private static nint CustomWndProc(nint hWnd, uint msg, nint wParam, nint lParam, IntPtr hwnd) - { - const int WM_NCHITTEST = 0x84; - const int HTCLIENT = 1; - const int HTTRANSPARENT = -1; - - if (msg == WM_NCHITTEST) - { - int x = (short)(lParam.ToInt32() & 0xFFFF); - int y = (short)((lParam.ToInt32() >> 16) & 0xFFFF); - - // 转为窗口坐标 - POINT pt = new() { x = x, y = y }; - User32.ScreenToClient(hWnd, ref pt); - - foreach (var rect in _interactiveRects) - { - if (rect.Contains(pt.x, pt.y)) - return HTCLIENT; - } - return HTTRANSPARENT; - } - - // 调用原WndProc - if (_oldWndProcs.TryGetValue(hwnd, out var oldWndProc)) - { - return User32.CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam); - } - return User32.DefWindowProc(hWnd, msg, wParam, lParam); - } - - public static void SetInteractiveRects(IEnumerable rects) - { - _interactiveRects = rects.ToList(); - } - } } diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/DockModeHelper.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/DockModeHelper.cs index 4b442d8..0b14cad 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/DockModeHelper.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/DockModeHelper.cs @@ -31,11 +31,12 @@ namespace BetterLyrics.WinUI3.Helper window.SetIsAlwaysOnTop(false); UnregisterAppBar(hwnd); - RefreshWorkArea(); window.SetWindowStyle(_originalWindowStyle[hwnd]); _originalWindowStyle.Remove(hwnd); + window.ExtendsContentIntoTitleBar = true; + if (_originalPositions.TryGetValue(hwnd, out var rect)) { User32.SetWindowPos( @@ -54,7 +55,7 @@ namespace BetterLyrics.WinUI3.Helper public static void Enable(Window window, int appBarHeight, DockPlacement dockPlacement) { window.SetIsShownInSwitchers(false); - window.ExtendsContentIntoTitleBar = false; + //window.ExtendsContentIntoTitleBar = false; window.SetIsAlwaysOnTop(true); IntPtr hwnd = WindowNative.GetWindowHandle(window); @@ -63,7 +64,6 @@ namespace BetterLyrics.WinUI3.Helper { _originalWindowStyle[hwnd] = window.GetWindowStyle(); } - window.SetWindowStyle(WindowStyle.Popup | WindowStyle.Visible); if (!_originalPositions.ContainsKey(hwnd)) { @@ -78,6 +78,7 @@ namespace BetterLyrics.WinUI3.Helper int screenWidth = User32.GetSystemMetrics(User32.SystemMetric.SM_CXSCREEN); int screenHeight = User32.GetSystemMetrics(User32.SystemMetric.SM_CYSCREEN); int y = dockPlacement == DockPlacement.Top ? 0 : screenHeight - appBarHeight; + User32.SetWindowPos( hwnd, IntPtr.Zero, @@ -85,10 +86,11 @@ namespace BetterLyrics.WinUI3.Helper y, screenWidth, appBarHeight, - User32.SetWindowPosFlags.SWP_SHOWWINDOW + User32.SetWindowPosFlags.SWP_HIDEWINDOW ); - - RefreshWorkArea(); + window.ExtendsContentIntoTitleBar = false; + window.ToggleWindowStyle(true, WindowStyle.Popup); + window.Show(); } private static void RegisterAppBar(IntPtr hwnd, int height, DockPlacement dockPlacement) @@ -114,7 +116,9 @@ namespace BetterLyrics.WinUI3.Helper }, }; + // Ref: https://github.com/TwilightLemon/AppBarTest/blob/master/AppBarCreator.cs Shell32.SHAppBarMessage(Shell32.ABM.ABM_NEW, ref abd); + Shell32.SHAppBarMessage(Shell32.ABM.ABM_QUERYPOS, ref abd); Shell32.SHAppBarMessage(Shell32.ABM.ABM_SETPOS, ref abd); _registered.Add(hwnd); @@ -167,6 +171,7 @@ namespace BetterLyrics.WinUI3.Helper }, }; + Shell32.SHAppBarMessage(Shell32.ABM.ABM_QUERYPOS, ref abd); Shell32.SHAppBarMessage(Shell32.ABM.ABM_SETPOS, ref abd); // 鍚屾绐楀彛瀹為檯楂樺害鍜屼綅缃 @@ -178,10 +183,8 @@ namespace BetterLyrics.WinUI3.Helper y, User32.GetSystemMetrics(User32.SystemMetric.SM_CXSCREEN), newHeight, - User32.SetWindowPosFlags.SWP_SHOWWINDOW + newHeight == 0 ? User32.SetWindowPosFlags.SWP_HIDEWINDOW : User32.SetWindowPosFlags.SWP_SHOWWINDOW ); - - RefreshWorkArea(); }, TimeSpan.FromMilliseconds(100)); } } diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/FontHelper.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/FontHelper.cs new file mode 100644 index 0000000..ae52cc2 --- /dev/null +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/FontHelper.cs @@ -0,0 +1,20 @@ +锘縰sing BetterLyrics.WinUI3.Services; +using CommunityToolkit.Mvvm.DependencyInjection; +using Microsoft.Graphics.Canvas.Text; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BetterLyrics.WinUI3.Helper +{ + public static class FontHelper + { + private static readonly ISettingsService _settingsService = Ioc.Default.GetRequiredService(); + + public static string[] SystemFontFamilies => CanvasTextFormat.GetSystemFontFamilies(); + + public static string GetUserPreferredFontFamily() => SystemFontFamilies.ElementAtOrDefault(_settingsService.SelectedFontFamilyIndex) ?? "Segoe UI"; + } +} diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LyricsParser.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LyricsParser.cs index 94a0ddf..cec9601 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LyricsParser.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LyricsParser.cs @@ -47,7 +47,6 @@ namespace BetterLyrics.WinUI3.Helper break; } } - PostProcessLyricsLines(durationMs.Value); _lyricsDataArr.Add(new LyricsData()); // 涓烘満缈婚鐣 return _lyricsDataArr; } @@ -374,29 +373,5 @@ namespace BetterLyrics.WinUI3.Helper _lyricsDataArr.Add(new LyricsData(lyricsLines)); } - - private void PostProcessLyricsLines(int durationMs) - { - for (int langIdx = 0; langIdx < _lyricsDataArr.Count; langIdx++) - { - var lines = _lyricsDataArr[langIdx].LyricsLines; - if (lines.Count > 0) - { - if (lines[0].StartMs > 0) - { - lines.Insert( - 0, - new LyricsLine - { - StartMs = 0, - EndMs = lines[0].StartMs, - OriginalText = "鈼 鈼 鈼", - LyricsChars = [], - } - ); - } - } - } - } } } diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/IPlaybackService.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/IPlaybackService.cs index 8742cc5..3deef32 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/IPlaybackService.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/IPlaybackService.cs @@ -21,6 +21,6 @@ namespace BetterLyrics.WinUI3.Services Task NextAsync(); bool IsPlaying { get; } - + SongInfo? SongInfo { get; } } } diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/ISettingsService.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/ISettingsService.cs index 8724884..fb9741a 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/ISettingsService.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/ISettingsService.cs @@ -96,5 +96,10 @@ namespace BetterLyrics.WinUI3.Services bool IsImmersiveMode { get; set; } string LXMusicServer { get; set; } DockPlacement DockPlacement { get; set; } + bool HideWindowWhenNotPlaying { get; set; } + int DockWindowHeight { get; set; } + int SelectedFontFamilyIndex { get; set; } + string LyricsFontFamily { get; set; } + bool IsDragEverywhereEnabled { get; set; } } } diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/PlaybackService.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/PlaybackService.cs index add458a..a0ab78f 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/PlaybackService.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/PlaybackService.cs @@ -64,6 +64,7 @@ namespace BetterLyrics.WinUI3.Services } public bool IsPlaying => _cachedIsPlaying; + public SongInfo? SongInfo => _cachedSongInfo; private bool IsMediaSourceEnabled(string id) { diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/SettingsService.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/SettingsService.cs index 4ca3693..977b9a4 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/SettingsService.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/SettingsService.cs @@ -96,6 +96,12 @@ namespace BetterLyrics.WinUI3.Services private const string LockHotKeyIndexKey = "LockHotKeyIndex"; private const string DockPlacementKey = "DockPlacement"; private const string LyricsBgFontOpacityKey = "LyricsBgFontOpacity"; + private const string HideWindowWhenNotPlayingKey = "HideWindowWhenNotPlaying"; + private const string DockWindowHeightKey = "DockWindowHeight"; + + private const string SelectedFontFamilyIndexKey = "SelectedFontFamilyIndex"; + private const string LyricsFontFamilyKey = "LyricsFontFamily"; + private const string IsDragEverywhereEnabledKey = "IsDragEverywhereEnabled"; private readonly ApplicationDataContainer _localSettings; @@ -221,6 +227,41 @@ namespace BetterLyrics.WinUI3.Services SetDefault(LockHotKeyIndexKey, 'U' - 'A'); SetDefault(DockPlacementKey, (int)DockPlacement.Top); SetDefault(LyricsBgFontOpacityKey, 30); // 30% + SetDefault(HideWindowWhenNotPlayingKey, false); + SetDefault(DockWindowHeightKey, 64); // 64px + SetDefault(SelectedFontFamilyIndexKey, 0); + SetDefault(LyricsFontFamilyKey, FontHelper.SystemFontFamilies.ElementAtOrDefault(0)); + SetDefault(IsDragEverywhereEnabledKey, true); + } + + public bool IsDragEverywhereEnabled + { + get => GetValue(IsDragEverywhereEnabledKey); + set => SetValue(IsDragEverywhereEnabledKey, value); + } + + public string LyricsFontFamily + { + get => GetValue(LyricsFontFamilyKey)!; + set => SetValue(LyricsFontFamilyKey, value); + } + + public int SelectedFontFamilyIndex + { + get => GetValue(SelectedFontFamilyIndexKey); + set => SetValue(SelectedFontFamilyIndexKey, value); + } + + public bool HideWindowWhenNotPlaying + { + get => GetValue(HideWindowWhenNotPlayingKey); + set => SetValue(HideWindowWhenNotPlayingKey, value); + } + + public int DockWindowHeight + { + get => GetValue(DockWindowHeightKey); + set => SetValue(DockWindowHeightKey, value); } public int LyricsBgFontOpacity diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/en-US/Resources.resw b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/en-US/Resources.resw index 8057a49..b50a499 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/en-US/Resources.resw +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/en-US/Resources.resw @@ -775,4 +775,22 @@ If you encounter any problems, please go to the Settings page, About tab, and vi Unable to connect to LX Music server, please go to Settings - Advanced options to check if the link is entered correctly + + Auto-hide window + + + Automatically hide the window when no songs are playing in dock mode or desktop mode + + + Window height + + + Lyrics font family + + + Global drag + + + Extend the title bar to the entire page so that the window can be dragged in any non-interactive area + \ No newline at end of file diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ja-JP/Resources.resw b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ja-JP/Resources.resw index ddadf19..d238d04 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ja-JP/Resources.resw +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ja-JP/Resources.resw @@ -775,4 +775,22 @@ LX Music Server銇帴缍氥仹銇嶃仾銇勫牬鍚堛伅銆佽ō瀹氥伀绉诲嫊銇椼仸銇忋仩銇曘亜銆傘儶銉炽偗銇屾銇椼亸鍏ュ姏銇曘倢銇︺亜銈嬨亱銇┿亞銇嬨倰纰鸿獚銇欍倠銇熴倎銇珮搴︺仾銈儣銈枫儳銉炽伀绉诲嫊銇椼仸銇忋仩銇曘亜 + + 鑷嫊銉忋偆銉夈偊銈c兂銉夈偊 + + + 銉夈儍銈儮銉笺儔銈勩儑銈广偗銉堛儍銉椼儮銉笺儔銇у啀鐢熴仌銈屻仸銇勩倠鏇层亴銇亜銇ㄣ亶銇偊銈c兂銉夈偊銈掕嚜鍕曠殑銇潪琛ㄧず銇仚銈 + + + 绐撱伄楂樸仌 + + + 姝岃銉曘偐銉炽儓銉曘偂銉熴儶銉 + + + 銈般儹銉笺儛銉儔銉┿儍銈 + + + 銈裤偆銉堛儷銉愩兗銈掋儦銉笺偢鍏ㄤ綋銇嫛寮点仐銇︺併偊銈c兂銉夈偊銈掗潪瀵捐┍闋樺煙銇с儔銉┿儍銈般仹銇嶃倠銈堛亞銇仐銇俱仚 + \ No newline at end of file diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ko-KR/Resources.resw b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ko-KR/Resources.resw index 6a3f351..6ec6246 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ko-KR/Resources.resw +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/ko-KR/Resources.resw @@ -775,4 +775,22 @@ LX Music Server鞐 鞐瓣舶頃 靾 鞐嗢姷雼堧嫟. 靹れ爼鞙茧 鞚措彊頃橃嫮鞁滌槫 - 瓿犼笁 鞓奠厴鞚 毵來伂臧 鞓皵毳搓矊 鞛呺牓霅橃棃電旍 頇曥澑頃橃嫮鞁滌槫. + + 鞛愲彊 臧欤 彀 + + + 霃勴伂 氇摐 霕愲姅 雿办姢韥儜 氇摐鞐愳劀 鞛儩霅橃 鞎婌潉 霑岆姅 彀届潉 鞛愲彊鞙茧 靾赴瓿 鞛堨姷雼堧嫟. + + + 彀 雴掛澊 + + + 臧靷 旮昙 臧臁 + + + 旮搿滊矊 霌滊灅攴 + + + 牍 欷戧臣 鞓侅棴鞐愳劀 彀届潉 霌滊灅攴 頃 靾 鞛堧弰搿 鞝滊 響滌嫓 欷勳潉 鞝勳泊 韼橃澊歆搿 頇曥灔頃橃嫮鞁滌槫. + \ No newline at end of file diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-CN/Resources.resw b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-CN/Resources.resw index a20994a..e67bfdc 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-CN/Resources.resw +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-CN/Resources.resw @@ -775,4 +775,22 @@ 鏃犳硶杩炴帴鍒 LX 闊充箰鏈嶅姟鍣紝璇疯浆鍒拌缃 - 楂樼骇閫夐」浠ユ鏌ユ槸鍚︽纭緭鍏ラ摼鎺 + + 鑷姩闅愯棌绐楀彛 + + + 鍋滈潬妯″紡鎴栨闈㈡ā寮忎笅锛屾棤姝屾洸姝e湪鎾斁鏃讹紝鑷姩闅愯棌绐楀彛 + + + 绐楀彛楂樺害 + + + 姝岃瘝瀛椾綋 + + + 鍏ㄥ眬鎷栨嫿 + + + 灏嗘爣棰樻爮鎵╁睍鑷虫暣涓〉闈娇寰楀湪浠绘剰闈炰氦浜掑尯鍩熷潎鍙嫋鎷界獥鍙 + \ No newline at end of file diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-TW/Resources.resw b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-TW/Resources.resw index b022049..716bfa7 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-TW/Resources.resw +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Strings/zh-TW/Resources.resw @@ -775,4 +775,22 @@ 鐒℃硶閫f帴鍒 LX 闊虫▊鏈嶅嫏鍣紝璜嬭綁鍒拌ō缃 - 楂樼礆閬搁爡浠ユ鏌ユ槸鍚︽纰鸿几鍏ラ張鎺 + + 鑷嫊闅辫棌绐楀彛 + + + 鍋滈潬妯″紡鎴栨闈㈡ā寮忎笅锛岀劇姝屾洸姝e湪鎾斁鏅傦紝鑷嫊闅辫棌绐楀彛 + + + 绐楀彛楂樺害 + + + 姝岃瀛楅珨 + + + 鍏ㄥ煙鎷栨洺 + + + 灏囨椤屽垪鎿村睍鑷虫暣鍊嬮爜闈娇寰楀湪浠绘剰闈炰簰鍕曞崁鍩熷潎鍙嫋鏇崇獥鍙 + \ No newline at end of file diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsPageViewModel.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsPageViewModel.cs index 7fd1534..7302b6d 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsPageViewModel.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsPageViewModel.cs @@ -15,7 +15,10 @@ using System.Threading.Tasks; namespace BetterLyrics.WinUI3.ViewModels { - public partial class LyricsPageViewModel : BaseViewModel, IRecipient> + public partial class LyricsPageViewModel : BaseViewModel, + IRecipient>, + IRecipient>, + IRecipient> { private readonly IPlaybackService _playbackService; @@ -28,6 +31,8 @@ namespace BetterLyrics.WinUI3.ViewModels PositionOffset = _settingsService.PositionOffset; IsImmersiveMode = _settingsService.IsImmersiveMode; ShowTranslationOnly = _settingsService.ShowTranslationOnly; + LyricsFontSize = _settingsService.LyricsFontSize; + LyricsFontFamily = _settingsService.LyricsFontFamily; OnIsImmersiveModeChanged(IsImmersiveMode); @@ -63,6 +68,15 @@ namespace BetterLyrics.WinUI3.ViewModels //[ObservableProperty] //public partial int Volume { get; set; } + [ObservableProperty] + public partial string LyricsFontFamily { get; set; } + + [ObservableProperty] + public partial int LyricsFontSize { get; set; } + + [ObservableProperty] + public partial Vector3 BottomRightCommandGridTranslation { get; set; } = new Vector3(0, 0, 0); + [ObservableProperty] public partial Vector3 BottomCenterCommandGridTranslation { get; set; } = new Vector3(0, 0, 0); @@ -121,7 +135,6 @@ namespace BetterLyrics.WinUI3.ViewModels { DisplayType = _settingsService.DisplayType; } - BottomCommandGridMargin = message.NewValue ? new Thickness(0) : new Thickness(12); } else if (message.PropertyName == nameof(LyricsWindowViewModel.IsDesktopMode)) { @@ -204,6 +217,28 @@ namespace BetterLyrics.WinUI3.ViewModels _settingsService.ShowTranslationOnly = value; } + public void Receive(PropertyChangedMessage message) + { + if (message.Sender is SettingsPageViewModel) + { + if (message.PropertyName == nameof(SettingsPageViewModel.LyricsFontSize)) + { + LyricsFontSize = message.NewValue; + } + } + } + + public void Receive(PropertyChangedMessage message) + { + if (message.Sender is SettingsPageViewModel) + { + if (message.PropertyName == nameof(SettingsPageViewModel.LyricsFontFamily)) + { + LyricsFontFamily = message.NewValue; + } + } + } + //partial void OnVolumeChanged(int value) //{ // SystemVolumeHelper.SetMasterVolume(value); diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel.Ctor.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel.Ctor.cs index 8f5d6c7..ce3a2a3 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel.Ctor.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel.Ctor.cs @@ -26,6 +26,8 @@ namespace BetterLyrics.WinUI3.ViewModels _lyricsTextFormat.FontWeight = _settingsService.LyricsFontWeight.ToFontWeight(); + _lyricsTextFormat.FontFamily = _artistTextFormat.FontFamily = _titleTextFormat.FontFamily = _settingsService.LyricsFontFamily; + _lyricsAlignmentType = _settingsService.LyricsAlignmentType; _lyricsVerticalEdgeOpacity = _settingsService.LyricsVerticalEdgeOpacity; _lyricsLineSpacingFactor = _settingsService.LyricsLineSpacingFactor; diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel.Messages.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel.Messages.cs index aff3e2f..c5dabbb 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel.Messages.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel.Messages.cs @@ -12,6 +12,7 @@ namespace BetterLyrics.WinUI3.ViewModels { public partial class LyricsRendererViewModel : IRecipient>, + IRecipient>, IRecipient>, IRecipient>, IRecipient>, @@ -320,5 +321,17 @@ namespace BetterLyrics.WinUI3.ViewModels } } } + + public void Receive(PropertyChangedMessage message) + { + if (message.Sender is SettingsPageViewModel) + { + if (message.PropertyName == nameof(SettingsPageViewModel.LyricsFontFamily)) + { + _lyricsTextFormat.FontFamily = _artistTextFormat.FontFamily = _titleTextFormat.FontFamily = message.NewValue; + _isLayoutChanged = true; + } + } + } } } diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel.cs index 96d96c7..a5edd99 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsRendererViewModel.cs @@ -193,12 +193,14 @@ namespace BetterLyrics.WinUI3.ViewModels private int GetCurrentPlayingLineIndex() { + var totalMs = _totalTime.TotalMilliseconds + _positionOffset.TotalMilliseconds; + if (totalMs < _lyricsDataArr.ElementAtOrDefault(_langIndex)?.LyricsLines.FirstOrDefault()?.StartMs) return 0; + for (int i = 0; i < _lyricsDataArr.ElementAtOrDefault(_langIndex)?.LyricsLines.Count; i++) { var line = _lyricsDataArr.ElementAtOrDefault(_langIndex)?.LyricsLines.ElementAtOrDefault(i); if (line == null) continue; var nextLine = _lyricsDataArr.ElementAtOrDefault(_langIndex)?.LyricsLines.ElementAtOrDefault(i + 1); - var totalMs = _totalTime.TotalMilliseconds + _positionOffset.TotalMilliseconds; if (nextLine != null && line.StartMs <= totalMs && totalMs < nextLine.StartMs) { return i; @@ -411,7 +413,9 @@ namespace BetterLyrics.WinUI3.ViewModels { _logger.LogInformation("Showing translation for lyrics..."); string targetLangCode = LanguageHelper.GetUserTargetLanguageCode(); - string originalText = _lyricsDataArr[0].WrappedOriginalText; + string? originalText = _lyricsDataArr.FirstOrDefault()?.WrappedOriginalText; + if (originalText == null) return; + string? originalLangCode = LanguageHelper.DetectLanguageCode(originalText); if (originalLangCode == targetLangCode) @@ -530,6 +534,10 @@ namespace BetterLyrics.WinUI3.ViewModels foreach (var data in translationData) { data.LyricsLines = data.LyricsLines.Where(line => !string.IsNullOrWhiteSpace(line.OriginalText)).ToList(); + foreach (var item in data.LyricsLines) + { + if (item.OriginalText == "//") item.OriginalText = ""; + } } _lyricsDataArr = _lyricsDataArr.Concat(translationData).ToList(); } diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsWindowViewModel.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsWindowViewModel.cs index d9cde1b..de755dd 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsWindowViewModel.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsWindowViewModel.cs @@ -7,6 +7,7 @@ using BetterLyrics.WinUI3.Services; using BetterLyrics.WinUI3.ViewModels; using BetterLyrics.WinUI3.Views; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.DependencyInjection; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.Mvvm.Messaging.Messages; @@ -31,20 +32,29 @@ namespace BetterLyrics.WinUI3 IRecipient>, IRecipient> { + private readonly IPlaybackService _playbackService = Ioc.Default.GetRequiredService(); private ForegroundWindowWatcher? _windowWatcher = null; - private bool _ignoreFullscreenWindow = false; - private int _dockWindowMinHeight = 96; + private bool _ignoreFullscreenWindow; + private bool _hideWindowWhenNotPlaying; private DockPlacement _dockPlacement; - private int _lyricsFontSize; + private int _dockWindowHeight; public LyricsWindowViewModel(ISettingsService settingsService) : base(settingsService) { _ignoreFullscreenWindow = _settingsService.IgnoreFullscreenWindow; + _hideWindowWhenNotPlaying = _settingsService.HideWindowWhenNotPlaying; IsImmersiveMode = _settingsService.IsImmersiveMode; _dockPlacement = _settingsService.DockPlacement; - _lyricsFontSize = _settingsService.LyricsFontSize; + _dockWindowHeight = _settingsService.DockWindowHeight; OnIsImmersiveModeChanged(_settingsService.IsImmersiveMode); + + _playbackService.SongInfoChanged += PlaybackService_SongInfoChanged; + } + + private void PlaybackService_SongInfoChanged(object? sender, Events.SongInfoChangedEventArgs e) + { + AutoHideOrShowWindow(); } [ObservableProperty] @@ -83,12 +93,43 @@ namespace BetterLyrics.WinUI3 [ObservableProperty] public partial string LockHotKey { get; set; } = ""; + private void AutoHideOrShowWindow() + { + var window = WindowHelper.GetWindowByWindowType(); + if (window == null) return; + + var hwnd = WindowNative.GetWindowHandle(window); + + if (IsDockMode || IsDesktopMode) + { + if (_hideWindowWhenNotPlaying && _playbackService.SongInfo == null) + { + if (IsDockMode) + { + DockModeHelper.UpdateAppBarHeight(hwnd, 0, _dockPlacement); + } + window.Hide(); + } + else + { + if (IsDockMode) + { + DockModeHelper.UpdateAppBarHeight(hwnd, _dockWindowHeight, _dockPlacement); + } + window.Show(); + } + } + } + private void UpdateDockWindow() { var window = WindowHelper.GetWindowByWindowType(); if (window == null) return; - DockModeHelper.UpdateAppBarHeight(WindowNative.GetWindowHandle(window), Math.Max(_dockWindowMinHeight, _lyricsFontSize * 4), _dockPlacement); + if (!_hideWindowWhenNotPlaying || _playbackService.SongInfo != null) + { + DockModeHelper.UpdateAppBarHeight(WindowNative.GetWindowHandle(window), _dockWindowHeight, _dockPlacement); + } } partial void OnIsImmersiveModeChanged(bool value) @@ -121,6 +162,11 @@ namespace BetterLyrics.WinUI3 { _ignoreFullscreenWindow = message.NewValue; } + else if (message.PropertyName == nameof(SettingsPageViewModel.HideWindowWhenNotPlaying)) + { + _hideWindowWhenNotPlaying = message.NewValue; + AutoHideOrShowWindow(); + } } } @@ -139,9 +185,9 @@ namespace BetterLyrics.WinUI3 { if (message.Sender is SettingsPageViewModel) { - if (message.PropertyName == nameof(SettingsPageViewModel.LyricsFontSize)) + if (message.PropertyName == nameof(SettingsPageViewModel.DockWindowHeight)) { - _lyricsFontSize = message.NewValue; + _dockWindowHeight = message.NewValue; UpdateDockWindow(); } else if (message.Sender is SettingsPageViewModel) @@ -231,6 +277,8 @@ namespace BetterLyrics.WinUI3 IsLyricsWindowLocked = true; IsImmersiveMode = true; } + + AutoHideOrShowWindow(); } [RelayCommand] @@ -264,13 +312,15 @@ namespace BetterLyrics.WinUI3 IsDockMode = !IsDockMode; if (IsDockMode) { - DockModeHelper.Enable(window, Math.Max(_dockWindowMinHeight, _lyricsFontSize * 4), _dockPlacement); + DockModeHelper.Enable(window, _dockWindowHeight, _dockPlacement); StartWatchWindowColorChange(); } else { DockModeHelper.Disable(window); } + + AutoHideOrShowWindow(); } [RelayCommand] diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/SettingsPageViewModel.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/SettingsPageViewModel.cs index 0e0e30b..8a99b40 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/SettingsPageViewModel.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/SettingsPageViewModel.cs @@ -8,6 +8,7 @@ using BetterLyrics.WinUI3.Views; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; +using Microsoft.Graphics.Canvas.Text; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using ShadowViewer.Controls; @@ -97,6 +98,13 @@ namespace BetterLyrics.WinUI3.ViewModels LXMusicServer = _settingsService.LXMusicServer; DockPlacement = _settingsService.DockPlacement; LyricsBgFontOpacity = _settingsService.LyricsBgFontOpacity; + HideWindowWhenNotPlaying = _settingsService.HideWindowWhenNotPlaying; + DockWindowHeight = _settingsService.DockWindowHeight; + + SystemFontNames = [.. FontHelper.SystemFontFamilies]; + SelectedFontFamilyIndex = _settingsService.SelectedFontFamilyIndex; + LyricsFontFamily = _settingsService.LyricsFontFamily; + IsDragEverywhereEnabled = _settingsService.IsDragEverywhereEnabled; _playbackService.MediaSourceProvidersInfoChanged += PlaybackService_SessionIdsChanged; @@ -111,6 +119,21 @@ namespace BetterLyrics.WinUI3.ViewModels MediaSourceProvidersInfo = [.. e.MediaSourceProviersInfo]; } + [ObservableProperty] + public partial bool IsDragEverywhereEnabled { get; set; } + + [ObservableProperty] + [NotifyPropertyChangedRecipients] + public partial string LyricsFontFamily { get; set; } + + + [ObservableProperty] + public partial ObservableCollection SystemFontNames { get; set; } + + [ObservableProperty] + [NotifyPropertyChangedRecipients] + public partial int SelectedFontFamilyIndex { get; set; } + [ObservableProperty] [NotifyPropertyChangedRecipients] public partial DockPlacement DockPlacement { get; set; } @@ -294,6 +317,14 @@ namespace BetterLyrics.WinUI3.ViewModels [NotifyPropertyChangedRecipients] public partial string LXMusicServer { get; set; } + [ObservableProperty] + [NotifyPropertyChangedRecipients] + public partial bool HideWindowWhenNotPlaying { get; set; } + + [ObservableProperty] + [NotifyPropertyChangedRecipients] + public partial int DockWindowHeight { get; set; } + public void OnLyricsSearchProvidersReordered() { _settingsService.LyricsSearchProvidersInfo = [.. LyricsSearchProvidersInfo]; @@ -670,5 +701,32 @@ namespace BetterLyrics.WinUI3.ViewModels { _settingsService.LyricsBgFontOpacity = value; } + partial void OnHideWindowWhenNotPlayingChanged(bool value) + { + _settingsService.HideWindowWhenNotPlaying = value; + } + partial void OnDockWindowHeightChanged(int value) + { + _settingsService.DockWindowHeight = value; + } + partial void OnSelectedFontFamilyIndexChanged(int value) + { + _settingsService.SelectedFontFamilyIndex = value; + LyricsFontFamily = SystemFontNames[value]; + } + partial void OnLyricsFontFamilyChanged(string value) + { + _settingsService.LyricsFontFamily = value; + } + partial void OnIsDragEverywhereEnabledChanged(bool value) + { + _settingsService.IsDragEverywhereEnabled = value; + + LyricsWindow? lyricsWindow = WindowHelper.GetWindowByWindowType(); + if (lyricsWindow != null) + { + lyricsWindow.UpdateTitleBarArea(); + } + } } } diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsPage.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsPage.xaml index e7c6d1f..acd4b6b 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsPage.xaml +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsPage.xaml @@ -28,7 +28,8 @@ x:Uid="MainPageNoMusicPlaying" HorizontalAlignment="Center" VerticalAlignment="Center" - Style="{StaticResource TitleTextBlockStyle}" /> + FontFamily="{x:Bind ViewModel.LyricsFontFamily, Mode=OneWay}" + FontSize="{x:Bind ViewModel.LyricsFontSize, Mode=OneWay}" /> @@ -45,6 +46,18 @@ Value="{x:Null}"> + + + + + + @@ -145,6 +158,25 @@ + + + + + + + + + + + + + + Style="{StaticResource CardGridStyle}" + Translation="{x:Bind ViewModel.BottomRightCommandGridTranslation, Mode=OneWay}"> + + + - - -