Intercepting "start-print" API-Call

currently the SpoolManager-Plugin overwrites the Print-Button in the UI via JavaScript.
So, each time a print should start, the javascript prevents this, ask the plugin in the backend about the needed filament and if everything is fine, the orig. start function in called in the UI. Works and is simple to implement.

But I received this feature request: Choose spool popup instead of confirm popup? · Issue #85 · OllisGit/OctoPrint-SpoolManager · GitHub
The problem is that the print is started from the slicer via an API-Call and now I am looking for a "nice/clean" way to intercept this call to do the needed filament-check.

I have some (dirty) solutions in my mind:

  • Listen for the event STATE_STARTING, stop/pause the print via printer.pause_print(...), do the check (inform user via _plugin_manager.send_plugin_message(...)) and cancel or resume the print.


  • Listening for special G-Code at the beginning of the file. E.g. M117 checking filament, pause print do the check and cancel or resume the print

Of course, one challenge is to wait for the feedback from the user to confirm continuing printing, if the browser is not open and the web socket-call could not send the message to the browser. Then I need to stop the whole print.

Is there a better way?
Any ideas?


This is how PSUControl currently MITMs the upload API call to turn the PSU on before printing. It is blocking though so keep that it mind. Might do what you need.

Thx, a lot! Looks promising!

Blocking....hmmm...thats tricky...also I think if my "check" takes to long, the API-Client receives an timeout.

I will think about it :wink: