From 8979c8661e542792f01258772b4f3024069ee90c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Fri, 7 Apr 2023 11:17:28 -0300 Subject: [PATCH] qml: FirmwareUpdate: Sort firmware by version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- qml/FirmwareUpdate.qml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/qml/FirmwareUpdate.qml b/qml/FirmwareUpdate.qml index 3dd072de4..6901a09b8 100644 --- a/qml/FirmwareUpdate.qml +++ b/qml/FirmwareUpdate.qml @@ -122,8 +122,22 @@ RowLayout { PingComboBox { id: fwCombo + function sortPingFiles(firmwares) { + return Object.keys(firmwares).sort((first, second) => { + const regex = /Ping[-_](V\d+\.\d+)/i; + const firstMatch = first.match(regex); + const secondMatch = second.match(regex); + const firstVersion = firstMatch ? firstMatch[1] : "V0.0"; + const secondVersion = secondMatch ? secondMatch[1] : "V0.0"; + return secondVersion.localeCompare(firstVersion, undefined, { + "numeric": true, + "sensitivity": 'base' + }); + }); + } + visible: automaticUpdateCB.currentIndex === 0 - model: ping && ping.firmwaresAvailable ? Object.keys(ping.firmwaresAvailable) : [] + model: ping && ping.firmwaresAvailable ? sortPingFiles(ping.firmwaresAvailable) : [] Layout.minimumWidth: 220 }