JoystickGremlin icon indicating copy to clipboard operation
JoystickGremlin copied to clipboard

Callback on user script reload/unload

Open DOCaCola opened this issue 4 years ago • 3 comments

Is there way for a user script to register for a callback to listen when joystick gremlin unloads or reloads the script? I am currently using rtmidi in my user script to access midi devices. However i am unable to properly release access to the midi devices when joystick gremlin is shutdown or the joystick profile is being deactivated/activated. Since the device doesn't get properly released, i cannot reopen the device anymore because of this.

DOCaCola avatar Dec 18 '20 17:12 DOCaCola

There is definitely no way to react to a script being unloaded, as that is actually not something that ever happens. There are also no events defined for starting/stopping Gremlin or activating/deactivating it. Technically you could see if hooking into QT events for application termination allows you to attach code that is executed before Gremlin terminates so you can release the devices.

From memory, there is a quite unorthodox way of running code when a user plugin is activated due to how they work but I'd have to work out again how exactly that works, and this would only do anything meaningful when the profile is activated but not stopped or other actions of Gremlin.

WhiteMagic avatar Dec 22 '20 13:12 WhiteMagic

Yes, i was able to hook into application termination, however it doesn't really help when the user script is being reloaded, as the midi device will be locked from the previous execution of the user script.

Maybe such callback code is something you might consider. It would certainly be helpful when doing more complex user scripts where proper cleanup is required.

DOCaCola avatar Dec 23 '20 00:12 DOCaCola

Yeah that kind of event stuff has been on the list of things to add at some point for a while now, see #140. I'll see if I can figure out again how to run code upon executing a module on activating a profile as that should allow you to force a release of the device before grabbing them in your code.

WhiteMagic avatar Dec 29 '20 21:12 WhiteMagic