Allow the evaluation of id_firmware_version for the purpose of ShowIf conditions.
#368
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction and background
This PR addresses issues that arise when a developer has a board with firmware published and the relevant JSON merged in VIA, along with a certain amount of custom features, such as custom UI elements.
In the case where the developer adds new functionality on top of the older ones, an issue arises: conflicting expectations of supported features.
Suppose a new firmware adds functionality X on top of the original A, B, and C.
The original firmware and JSON have
id_s and code handling of them that match 1:1.An option for the developer is to update the JSON on the VIA upstream, adding the X elements, but if the board doesn't handle those values, errors come up in the VIA app in the form of broken rendering or mishandling of the UI, with the possibility of data corruption.
The solution for this, as of now, was to compile the new firmware with different PID/VID and upload a completely new JSON with the new elements and matching PID/VID.
This solution is wasteful and repetitive.
Changes targeting the issue
This PR allows the VIA app to pull the defined
VIA_FIRMWARE_VERSIONfrom the firmware and use that to selectively expose custom UI elements, sub-menus, and menus.With the simple addition of
"showIf": "{id_firmware_version} OPERATOR VALUE", the developer can now show custom elements only if the firmware version on the board satisfies the condition.Behavior based on elements
Single element (button, toggle, slider, etc)
If the condition is not satisfied, the element is not shown at all.
Top Menu
If the condition is not satisfied, the top menu icon is rendered as well as the name, but the user is presented with a message:
Sub Menu
If the condition is not satisfied, the sub-menu label is rendered, but the user is presented with a message (this holds in the case the submenu is a single submenu or part of a list of submenus):

Usage
Simply add the condition to the JSON, as an example:
End goal
With these changes, it is no longer necessary to make a duplicate JSON with the new PID/VID and the added JSON elements.
The developer can simply submit a PR integrating the new controls wrapped in the conditional
ShowIfwith the appropriate value of firmware version.Note
Precursor
id_s indexes must be maintained to not break the older support. In case a full reindexing was done for some reason in the new firmwares, it is important to then wrap the entire section that used the old index values and put the new ones in a new conditional block