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"
    },
==
This commit is contained in:
Floris Bos 2021-11-23 02:53:50 +01:00
parent cde6d1eaa0
commit f5390c821a

View file

@ -1055,6 +1055,21 @@ ApplicationWindow {
return o["os_list"] 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() { function fetchOSlist() {
httpRequest(imageWriter.constantOsListUrl(), function (x) { httpRequest(imageWriter.constantOsListUrl(), function (x) {
var o = JSON.parse(x.responseText) var o = JSON.parse(x.responseText)
@ -1073,10 +1088,46 @@ ApplicationWindow {
updatepopup.openPopup() 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() { function newSublist() {
if (osswipeview.currentIndex == (osswipeview.count-1)) if (osswipeview.currentIndex == (osswipeview.count-1))
{ {