From f5390c821a989b4bde541f2fbf9aba876e8ef92f Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Tue, 23 Nov 2021 02:53:50 +0100 Subject: [PATCH] Allow specifying default OS selection and destination Allows specifying a default OS and destination (the last for Imager embedded only) in the repository json. Like: == "imager": { "latest_version": "1.6", "url": "https://www.raspberrypi.org/software/", "default_os": "Raspberry Pi OS (32-bit)", "embedded_default_destination": "/dev/mmcblk0p1" }, == --- main.qml | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/main.qml b/main.qml index 879fb54..4055f31 100644 --- a/main.qml +++ b/main.qml @@ -1055,6 +1055,21 @@ ApplicationWindow { return o["os_list"] } + function selectNamedOS(name, collection) + { + for (var i = 0; i < collection.count; i++) { + var os = collection.get(i) + + if (typeof(os.subitems) !== "undefined") { + selectNamedOS(name, os.subitems) + } + else if (typeof(os.url) !== "undefined" && name === os.name) { + selectOSitem(os, false) + break + } + } + } + function fetchOSlist() { httpRequest(imageWriter.constantOsListUrl(), function (x) { var o = JSON.parse(x.responseText) @@ -1073,10 +1088,46 @@ ApplicationWindow { updatepopup.openPopup() } } + if ("default_os" in imager) { + selectNamedOS(imager["default_os"], osmodel) + } + if (imageWriter.isEmbeddedMode()) { + if ("embedded_default_os" in imager) { + selectNamedOS(imager["embedded_default_os"], osmodel) + } + if ("embedded_default_destination" in imager) { + imageWriter.startDriveListPolling() + setDefaultDest.drive = imager["embedded_default_destination"] + setDefaultDest.start() + } + } } }) } + Timer { + /* Verify if default drive is in our list after 100 ms */ + id: setDefaultDest + property string drive : "" + interval: 100 + onTriggered: { + for (var i = 0; i < driveListModel.rowCount(); i++) + { + /* FIXME: there should be a better way to iterate drivelist than + fetch data by numeric role number */ + if (driveListModel.data(driveListModel.index(i,0), 0x101) === drive) { + selectDstItem({ + device: drive, + description: driveListModel.data(driveListModel.index(i,0), 0x102), + size: driveListModel.data(driveListModel.index(i,0), 0x103), + readonly: false + }) + break + } + } + } + } + function newSublist() { if (osswipeview.currentIndex == (osswipeview.count-1)) {