1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

handle unplugging devices properly

This commit is contained in:
Diogo Trindade 2025-02-15 15:48:31 +00:00
parent 17e6c655ff
commit c82f86aed3
2 changed files with 9 additions and 4 deletions

View File

@ -1,20 +1,24 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Serilog;
namespace Artemis.UI.Linux.Providers.Input; namespace Artemis.UI.Linux.Providers.Input;
internal class LinuxInputDeviceReader internal class LinuxInputDeviceReader
{ {
private readonly ILogger _logger;
private readonly byte[] _buffer; private readonly byte[] _buffer;
private readonly CancellationTokenSource _cts; private readonly CancellationTokenSource _cts;
private readonly FileStream _stream; private readonly FileStream _stream;
private readonly Task _task; private readonly Task _task;
public LinuxInputDeviceReader(LinuxInputDevice inputDevice) public LinuxInputDeviceReader(LinuxInputDevice inputDevice, ILogger logger)
{ {
_logger = logger;
InputDevice = inputDevice; InputDevice = inputDevice;
_buffer = new byte[Marshal.SizeOf<LinuxInputEventArgs>()]; _buffer = new byte[Marshal.SizeOf<LinuxInputEventArgs>()];
@ -50,9 +54,10 @@ internal class LinuxInputDeviceReader
InputEvent?.Invoke(this, MemoryMarshal.Read<LinuxInputEventArgs>(_buffer)); InputEvent?.Invoke(this, MemoryMarshal.Read<LinuxInputEventArgs>(_buffer));
} }
catch catch(Exception e)
{ {
// ignored _logger.Error("Error reading device input from {fileName}. Did you unplug a device? Stopping reader. {e}", InputDevice.EventPath, e);
return;
} }
} }
} }

View File

@ -21,7 +21,7 @@ public class LinuxInputProvider : InputProvider
foreach (LinuxInputDevice deviceDefinition in LinuxInputDeviceFinder.Find()) foreach (LinuxInputDevice deviceDefinition in LinuxInputDeviceFinder.Find())
{ {
LinuxInputDeviceReader? reader = new(deviceDefinition); LinuxInputDeviceReader? reader = new(deviceDefinition, logger);
reader.InputEvent += OnInputEvent; reader.InputEvent += OnInputEvent;
_readers.Add(reader); _readers.Add(reader);
} }