72 lines
1.8 KiB
C#
72 lines
1.8 KiB
C#
using CS2GSI;
|
|
using GlaxLogger;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace CSMediaControl;
|
|
using GSI = CS2GSI.CS2GSI;
|
|
|
|
public class Watchdog : IDisposable, IAsyncDisposable
|
|
{
|
|
private bool _keepRunning = true;
|
|
private readonly GSI _gsi;
|
|
private readonly Logger _logger;
|
|
private bool _mediaRunning;
|
|
|
|
public Watchdog(bool mediaRunning)
|
|
{
|
|
this._mediaRunning = mediaRunning;
|
|
this._logger = new Logger(LogLevel.Information, consoleOut: Console.Out);
|
|
this._gsi = new GSI(this._logger);
|
|
|
|
this._gsi.OnRoundStart += MusicStart;
|
|
this._gsi.OnRoundOver += MusicStop;
|
|
this._gsi.OnDeath += MusicStop;
|
|
|
|
Console.WriteLine("Press p to pause/play media.");
|
|
while (_keepRunning)
|
|
{
|
|
if (Console.KeyAvailable && Console.ReadKey(true).Key is ConsoleKey.P)
|
|
{
|
|
if(this._mediaRunning)
|
|
MusicStop(null);
|
|
else
|
|
MusicStart(null);
|
|
}else
|
|
Thread.Sleep(10);
|
|
}
|
|
this._logger.Log(LogLevel.Information, "Bye!");
|
|
}
|
|
|
|
private void MusicStop(CS2EventArgs? _)
|
|
{
|
|
if (_mediaRunning)
|
|
{
|
|
this._logger.Log(LogLevel.Information, "Music Pause");
|
|
MediaController.PlayPause();
|
|
this._mediaRunning = false;
|
|
}
|
|
}
|
|
|
|
private void MusicStart(CS2EventArgs? _)
|
|
{
|
|
if (!_mediaRunning)
|
|
{
|
|
this._logger.Log(LogLevel.Information, "Music Start");
|
|
MediaController.PlayPause();
|
|
this._mediaRunning = true;
|
|
}
|
|
}
|
|
|
|
|
|
public void Dispose()
|
|
{
|
|
this._keepRunning = false;
|
|
_logger.Dispose();
|
|
}
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
this._keepRunning = false;
|
|
await _logger.DisposeAsync();
|
|
}
|
|
} |