feat: 处理系统恢复以重置媒体检测
This commit is contained in:
14
MainForm.cs
14
MainForm.cs
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace TimerApp
|
||||
{
|
||||
@@ -129,6 +130,8 @@ namespace TimerApp
|
||||
|
||||
_monitor.Start();
|
||||
|
||||
SystemEvents.PowerModeChanged += OnPowerModeChanged;
|
||||
|
||||
// Set tray icon
|
||||
try
|
||||
{
|
||||
@@ -550,6 +553,7 @@ namespace TimerApp
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemEvents.PowerModeChanged -= OnPowerModeChanged;
|
||||
notifyIcon1.Visible = false;
|
||||
notifyIcon1.Dispose();
|
||||
}
|
||||
@@ -615,5 +619,15 @@ namespace TimerApp
|
||||
{
|
||||
this.WindowState = FormWindowState.Minimized;
|
||||
}
|
||||
|
||||
private void OnPowerModeChanged(object sender, PowerModeChangedEventArgs e)
|
||||
{
|
||||
if (e.Mode == PowerModes.Resume)
|
||||
{
|
||||
// 系统唤醒时,强制重置媒体播放检测状态,
|
||||
// 避免因检测线程挂起导致一直误报“正在播放”而无法进入工作状态。
|
||||
NativeMethods.InvalidateMediaCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user