Basically, I would like to add a download progress bar to this Luci script. How should I write the code?

The "entry" function seems to be usable only within controllers, making it cumbersome for controllers to obtain variables from CBI models for the HTTP interfaces they create.

How can interface in controllers fetch variables from CBI models effectively?

Will it be easier to draw a progress bar on the front-end when migrating to JS?
CBI models seem to only be able to draw relatively simple buttons, will JS have stronger front-end support?

For any kind of dynamic view updates in the client you will need to write JavaScript code which polls the server side for updated information.

Like with any CGI application, you can't progressively update the client side view purely from the server side.

It doesn't look like moving to JS will make any big changes either, so I wonder how I can get the lua code in controllers to read the variables holding the download progress from CBI models?

Or can CBI models also create HTTP interfaces using the entry function?

You can't read variables holding download progress from controllers. There is no persistent state and there is no concurrency or multi threading. While your model is downloading stuff, it is blocking, while it is blocking, no other code runs. The next request spawns another instance with it's own private state which has no relation to the previous one.

The only way to achieve what you want deferring the long running task to a background process which publishes it's progress information somewhere, e.g. via ubus or by writing it into a temporary file, then poll that information by repeatedly fetching it (from JavaScript) and updating the ui view accordingly.

1 Like