From 90c3479520fda8cc065c82ee1f5da63d8b91d5b0 Mon Sep 17 00:00:00 2001 From: grorp Date: Tue, 24 Jun 2025 11:50:12 +0200 Subject: [PATCH] ContentDB: Allow hitting "Install" before package info finishes loading (#16247) --- builtin/mainmenu/content/dlg_package.lua | 151 ++++++++++++----------- 1 file changed, 79 insertions(+), 72 deletions(-) diff --git a/builtin/mainmenu/content/dlg_package.lua b/builtin/mainmenu/content/dlg_package.lua index 500fb3f6c..1103f42a7 100644 --- a/builtin/mainmenu/content/dlg_package.lua +++ b/builtin/mainmenu/content/dlg_package.lua @@ -3,18 +3,61 @@ -- SPDX-License-Identifier: LGPL-2.1-or-later -local function get_info_formspec(size, padding, text) - return table.concat({ - "formspec_version[6]", - "size[", size.x, ",", size.y, "]", - "padding[0,0]", - "bgcolor[;true]", +local function get_description_hypertext(package, info, loading_error) + -- Screenshots and description + local hypertext = "" .. core.hypertext_escape(package.short_description) .. "\n" - "label[4,4.35;", text, "]", - "container[", padding.x, ",", size.y - 0.8 - padding.y, "]", - "button[0,0;2,0.8;back;", fgettext("Back"), "]", - "container_end[]", - }) + local screenshots = info and info.screenshots or {{url = package.thumbnail}} + + local winfo = core.get_window_info() + local fs_to_px = winfo.size.x / winfo.max_formspec_size.x + for i, ss in ipairs(screenshots) do + local path = get_screenshot(package, ss.url, 2) + hypertext = hypertext .. "" + if i ~= #screenshots then + hypertext = hypertext .. "" + end + end + + if info then + hypertext = hypertext .. "\n" .. info.long_description.head + + local first = true + local function add_link_button(label, name) + if info[name] then + if not first then + hypertext = hypertext .. " | " + end + hypertext = hypertext .. "" .. label .. "" + info.long_description.links["link_" .. name] = info[name] + first = false + end + end + + add_link_button(hgettext("Donate"), "donate_url") + add_link_button(hgettext("Website"), "website") + add_link_button(hgettext("Source"), "repo") + add_link_button(hgettext("Issue Tracker"), "issue_tracker") + add_link_button(hgettext("Translate"), "translation_url") + add_link_button(hgettext("Forum Topic"), "forum_url") + + hypertext = hypertext .. "\n\n" .. info.long_description.body + + elseif loading_error then + hypertext = hypertext .. "\n\n" .. hgettext("Error loading package information") + else + hypertext = hypertext .. "\n\n" .. hgettext("Loading...") + end + + -- Fix the path to blank.png. This is needed for bullet indentation, + -- and also used for screenshot spacing. + hypertext = hypertext:gsub("\n" - local winfo = core.get_window_info() - local fs_to_px = winfo.size.x / winfo.max_formspec_size.x - for i, ss in ipairs(info.screenshots) do - local path = get_screenshot(package, ss.url, 2) - hypertext = hypertext .. "" - if i ~= #info.screenshots then - hypertext = hypertext .. "" - end - end - hypertext = hypertext .. "\n" .. info.long_description.head - - local first = true - local function add_link_button(label, name) - if info[name] then - if not first then - hypertext = hypertext .. " | " - end - hypertext = hypertext .. "" .. core.hypertext_escape(label) .. "" - info.long_description.links["link_" .. name] = info[name] - first = false - end - end - - add_link_button(fgettext("Donate"), "donate_url") - add_link_button(fgettext("Website"), "website") - add_link_button(fgettext("Source"), "repo") - add_link_button(fgettext("Issue Tracker"), "issue_tracker") - add_link_button(fgettext("Translate"), "translation_url") - add_link_button(fgettext("Forum Topic"), "forum_url") - - hypertext = hypertext .. "\n\n" .. info.long_description.body - - -- Fix the path to blank.png. This is needed for bullet indentation. - hypertext = hypertext:gsub("