Custom Configs And Running Code Before Main.ts/.blocks

Hello,

I am trying to create a extension that may need to use the Microbit A/B buttons during startup depending on some settings and some runtime checks. The best way I found to do this is to ensure the setup code is ran before any user events get bound, as they can be used normally after the setup is done running, and should not fire during the startup.

Now the question is 2 part.

1: Can I force code to be run before the main code is ran, no matter if it’s blocks, javascript, python, etc? And if so, how?
2: I need to allow the user to be able to select which devices/modules are to be active. Is there a way to add custom settings in for example the project settings, and then read those out by the extension? Otherwise a block that sets these variable before or while the startup code is running.

Otherwise, if this is not possible. Can I at least force a startup block to be run before any events are bound like the input.onbuttonpress()? (Currently I can only get that to work in the javascript editor by manually moving the startup function to the top, but I need this to work in blocks)

The first part seems maybe possible.

The custom.ts in this example (could be in an extension) holds up main.ts if the logo is held within 2s, and until button B is pressed, button A plays a tone

The main blocks create their own button handlers.

I don’t know if this is a good idea though!