mullvad / windows-service-rs

Windows services in Rust
Apache License 2.0
513 stars 83 forks source link

feat: handle device event in service handler #132

Open vthib opened 3 weeks ago

vthib commented 3 weeks ago

I have recently needed to receive device events as a windows service, and found out that I couldn't with the current version of windows-service. This PR is here to make this possible.

To receive those events, a call to RegisterDeviceNotification must be done. This is of course not done in this crate and let instead to the user.

Then, instead of parsing the event data for every subtype of device events, I've chosen to keep the event data in raw form, and let the user of the crate do this parsing. This does not seem to be quite how the rest of the service event handler is written, but this is by far the simplest:

So all in all, it's imho much simpler and also efficient to let the user handle the conversion of this event data into rust. For example in my case, I only need to handle device arrival, and only some subset of those events.

Let me know what you think, or if you would prefer parsing those events to provide a nicer experience to the user. Also, thanks for your work on this crate :)


This change is Reviewable