Howto combine VintageNetWizard and own Phoenix application

Hello, I am trying to include VintageNet Wizard into project, which also has a Phoenix based webinterface. I am struggling with how to put it together, as app would normally start and then I am not able to start configuration wizard as Cowboy is already running. I am aware of the VintageNetWizard.run_wizard() being mentioned in the README. But even if I try something really similar to the README, I am not able to “switch” between wizard and my normal app.

To make things slightly more complicated, current structure of the project looks something like

├── firmware
├── mg_modbus_server
├── modbux
└── ui

Where firmware is the actual nerves piece, which has {:ui, path: "../ui"} in the deps. Thus there is also another problem with preventing bootstrap of the whole application tree (it seems, that app: false is getting close). Anyway, I have also tried to include VintageNetWizard.run_wizard() directly to ui project without a luck.

The only approach I’ve sort of came with is to abandon the standard standard Phoenix.Endpoint / Supervisor approach for the ui app and use DynamicSupervisor to spawn all children only if VintageNetWizard will not be necessary (basically, what they do within wizard ). But that seems a bit cumbersome. What am I missing?

1 Like

@mattludwigs is awesome, and provided solution on Slack:

So in your mix.exs file of your firmware project in the function release can you add a field to the key word list that looks like:

applications: [
  ui: :load
]

^ that assumes your ui app is named :ui. Also in your deps have: {:ui, path: "../ui" runtime: false, target: @all_targets} Doing these items will load the dep but not start it when your application starts.

Then you can do whatever logic to check if you need to start your ui or the wizard. If you need to start the ui you can run:

Application.ensure_all_started(:ui)

Also similar behavior can be achieve with :included_applications like

def application do
    [
      mod: {Firmware.Application, []},
      extra_applications: [:logger, :runtime_tools],
      included_applications: [:ui],
    ]
  end
3 Likes