Local development improvements
This MR fixes a few small but annoying issues that mostly appear when you're working on the Vue app. Specifically:
- It handles overriding the HTTP API origin more nicely, so you don't have to type in an alternative origin every time you refresh your browser.
- It handles GPU preview settings better, so you don't have to re-enable the stream every time you refresh
- It cleans up some event handling/watching code relating to the IHI plugin and the GPU preview
Tasks
Things that need to happen before this can be merged:
-
Remove the need to re-type the origin URL when you hit "refresh". -
Remove the need to re-enable the image stream when you hit "refresh" if it's served from localhost.
Details
API Origin Override
When using the Vue dev server, you currently need to enter the API address every time you refresh, which is really tedious. This branch fixes that by:
- providing an option to save it with local storage (you'd still need to click "override origin" every time, but don't need to re-type the new origin)
- providing an option to specify it in the URL (no need to re-type or click anything, it starts up with the correct origin).
I deliberately haven't provided a way for local storage to set a new origin without confirmation, because at some point in the future that will lead to horribly hard-to-fix bugs.
Manually inspecting the URL is a bit kludgy, and it would be more elegant to use a "router" to handle this. However, adding a router is a fairly major change to the app, and it's really not justified for this feature. On discussion with @kasbah we've agreed it's the right approach for now, but if we need to do anything else with the URL, we should probably switch to using a proper router module.
Stream settings
Previously, there was some fairly ad-hoc code that would disable the image stream and enable the GPU preview if you were running on localhost. This had no "memory" and so was a bit rubbish if you were running a dev server on localhost, but not wanting the Raspberry Pi-specific GPU preview mode. It also means if you're using a Pi 4 and want to use the JPEG stream rather than the GPU preview (e.g. for better click-to-move support) you must enable this setting every time.
I've now improved the code so that the current behaviour is still the default, but the setting is remembered in local storage. That means you only have to set it to the desired behaviour once, and this will be remembered for the future.
In doing this, I realised there was some slightly messy/outdated code handling events related to the GPU preview, and I've cleaned this up to simply "watch" the store and use Vue's reactivity instead of sending events around. I think this is cleaner and clearer.