mirror of
https://github.com/jayfunc/BetterLyrics.git
synced 2026-01-13 03:34:55 +08:00
fix #16
This commit is contained in:
@@ -16,9 +16,6 @@ namespace BetterLyrics.WinUI3.Helper
|
||||
private readonly List<User32.HWINEVENTHOOK> _hooks = new();
|
||||
private HWND _currentForeground = HWND.NULL;
|
||||
private readonly IntPtr _selfHwnd;
|
||||
private readonly DispatcherTimer _pollingTimer;
|
||||
private DateTime _lastEventTime = DateTime.MinValue;
|
||||
private const int ThrottleIntervalMs = 1000;
|
||||
|
||||
public delegate void WindowChangedHandler(HWND hwnd);
|
||||
private readonly WindowChangedHandler _onWindowChanged;
|
||||
@@ -28,13 +25,6 @@ namespace BetterLyrics.WinUI3.Helper
|
||||
_selfHwnd = selfHwnd;
|
||||
_onWindowChanged = onWindowChanged;
|
||||
_winEventDelegate = new User32.WinEventProc(WinEventProc);
|
||||
|
||||
_pollingTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(200) };
|
||||
_pollingTimer.Tick += (_, _) =>
|
||||
{
|
||||
if (_currentForeground != IntPtr.Zero && _currentForeground != _selfHwnd)
|
||||
_onWindowChanged?.Invoke(_currentForeground);
|
||||
};
|
||||
}
|
||||
|
||||
public void Start()
|
||||
@@ -64,8 +54,6 @@ namespace BetterLyrics.WinUI3.Helper
|
||||
User32.WINEVENT.WINEVENT_OUTOFCONTEXT
|
||||
)
|
||||
);
|
||||
|
||||
_pollingTimer.Start();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
@@ -74,7 +62,6 @@ namespace BetterLyrics.WinUI3.Helper
|
||||
User32.UnhookWinEvent(hook);
|
||||
|
||||
_hooks.Clear();
|
||||
_pollingTimer.Stop();
|
||||
}
|
||||
|
||||
private void WinEventProc(
|
||||
@@ -87,15 +74,9 @@ namespace BetterLyrics.WinUI3.Helper
|
||||
uint dwmsEventTime
|
||||
)
|
||||
{
|
||||
if (hwnd == IntPtr.Zero || hwnd == _selfHwnd)
|
||||
if (hwnd == IntPtr.Zero)
|
||||
return;
|
||||
|
||||
var now = DateTime.Now;
|
||||
if ((now - _lastEventTime).TotalMilliseconds < ThrottleIntervalMs)
|
||||
return;
|
||||
|
||||
_lastEventTime = now;
|
||||
|
||||
if (eventType == User32.EventConstants.EVENT_SYSTEM_FOREGROUND)
|
||||
{
|
||||
_currentForeground = hwnd;
|
||||
|
||||
@@ -79,10 +79,12 @@ namespace BetterLyrics.WinUI3.ViewModels
|
||||
if (message.PropertyName == nameof(LyricsWindowViewModel.IsDockMode))
|
||||
{
|
||||
_isDockMode = message.NewValue;
|
||||
UpdateFontColor();
|
||||
}
|
||||
else if (message.PropertyName == nameof(LyricsWindowViewModel.IsDesktopMode))
|
||||
{
|
||||
_isDesktopMode = message.NewValue;
|
||||
UpdateFontColor();
|
||||
}
|
||||
}
|
||||
else if (message.Sender is LyricsPageViewModel)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// 2025/6/23 by Zhe Fang
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using BetterLyrics.WinUI3.Enums;
|
||||
using BetterLyrics.WinUI3.Helper;
|
||||
@@ -148,6 +149,7 @@ namespace BetterLyrics.WinUI3
|
||||
|
||||
DesktopModeHelper.Lock(window);
|
||||
IsLyricsWindowLocked = true;
|
||||
StartWatchWindowColorChange(WindowColorSampleMode.WindowEdge);
|
||||
}
|
||||
|
||||
private void StopWatchWindowColorChange()
|
||||
@@ -167,7 +169,6 @@ namespace BetterLyrics.WinUI3
|
||||
IsDesktopMode = !IsDesktopMode;
|
||||
if (IsDesktopMode)
|
||||
{
|
||||
StartWatchWindowColorChange(WindowColorSampleMode.WindowEdge);
|
||||
DesktopModeHelper.Enable(window);
|
||||
}
|
||||
else
|
||||
@@ -187,8 +188,8 @@ namespace BetterLyrics.WinUI3
|
||||
IsDockMode = !IsDockMode;
|
||||
if (IsDockMode)
|
||||
{
|
||||
StartWatchWindowColorChange(WindowColorSampleMode.BelowWindow);
|
||||
DockModeHelper.Enable(window, _settingsService.LyricsFontSize * 4);
|
||||
StartWatchWindowColorChange(WindowColorSampleMode.BelowWindow);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user