Skip to content

Commit f90ca96

Browse files
authored
Make ContentDB downloads not block the UI (#9948)
1 parent 58f523e commit f90ca96

1 file changed

Lines changed: 22 additions & 41 deletions

File tree

builtin/mainmenu/dlg_contentstore.lua

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ local filter_types_type = {
4646
local function download_package(param)
4747
if core.download_file(param.package.url, param.filename) then
4848
return {
49-
package = param.package,
5049
filename = param.filename,
5150
successful = true,
5251
}
5352
else
5453
core.log("error", "downloading " .. dump(param.package.url) .. " failed")
5554
return {
56-
package = param.package,
5755
successful = false,
5856
}
5957
end
@@ -67,43 +65,43 @@ local function start_install(calling_dialog, package)
6765

6866
local function callback(result)
6967
if result.successful then
70-
local path, msg = pkgmgr.install(result.package.type,
71-
result.filename, result.package.name,
72-
result.package.path)
68+
local path, msg = pkgmgr.install(package.type,
69+
result.filename, package.name,
70+
package.path)
7371
if not path then
7472
gamedata.errormessage = msg
7573
else
7674
core.log("action", "Installed package to " .. path)
7775

7876
local conf_path
7977
local name_is_title = false
80-
if result.package.type == "mod" then
78+
if package.type == "mod" then
8179
local actual_type = pkgmgr.get_folder_type(path)
8280
if actual_type.type == "modpack" then
8381
conf_path = path .. DIR_DELIM .. "modpack.conf"
8482
else
8583
conf_path = path .. DIR_DELIM .. "mod.conf"
8684
end
87-
elseif result.package.type == "game" then
85+
elseif package.type == "game" then
8886
conf_path = path .. DIR_DELIM .. "game.conf"
8987
name_is_title = true
90-
elseif result.package.type == "txp" then
88+
elseif package.type == "txp" then
9189
conf_path = path .. DIR_DELIM .. "texture_pack.conf"
9290
end
9391

9492
if conf_path then
9593
local conf = Settings(conf_path)
9694
if name_is_title then
97-
conf:set("name", result.package.title)
95+
conf:set("name", package.title)
9896
else
99-
conf:set("title", result.package.title)
100-
conf:set("name", result.package.name)
97+
conf:set("title", package.title)
98+
conf:set("name", package.name)
10199
end
102100
if not conf:get("description") then
103-
conf:set("description", result.package.short_description)
101+
conf:set("description", package.short_description)
104102
end
105-
conf:set("author", result.package.author)
106-
conf:set("release", result.package.release)
103+
conf:set("author", package.author)
104+
conf:set("release", package.release)
107105
conf:write()
108106
end
109107
end
@@ -112,37 +110,17 @@ local function start_install(calling_dialog, package)
112110
gamedata.errormessage = fgettext("Failed to download $1", package.name)
113111
end
114112

115-
if gamedata.errormessage == nil then
116-
core.button_handler({btn_hidden_close_download=result})
117-
else
118-
core.button_handler({btn_hidden_close_download={successful=false}})
119-
end
113+
package.downloading = false
114+
ui.update()
120115
end
121116

117+
package.downloading = true
118+
122119
if not core.handle_async(download_package, params, callback) then
123120
core.log("error", "ERROR: async event failed")
124121
gamedata.errormessage = fgettext("Failed to download $1", package.name)
122+
return
125123
end
126-
127-
local new_dlg = dialog_create("store_downloading",
128-
function(data)
129-
return "size[7,2]label[0.25,0.75;" ..
130-
fgettext("Downloading and installing $1, please wait...", data.title) .. "]"
131-
end,
132-
function(this,fields)
133-
if fields["btn_hidden_close_download"] ~= nil then
134-
this:delete()
135-
return true
136-
end
137-
138-
return false
139-
end,
140-
nil)
141-
142-
new_dlg:set_parent(calling_dialog)
143-
new_dlg.data.title = package.title
144-
calling_dialog:hide()
145-
new_dlg:show()
146124
end
147125

148126
local function get_screenshot(package)
@@ -392,9 +370,12 @@ function store.get_formspec(dlgdata)
392370
minetest.colorize("#BFBFBF", " by " .. package.author))
393371
formspec[#formspec + 1] = "]"
394372

395-
-- buttons
396373
local description_width = 7.5
397-
if not package.path then
374+
if package.downloading then
375+
formspec[#formspec + 1] = "label[8.4,0.2;"
376+
formspec[#formspec + 1] = fgettext("Downloading...")
377+
formspec[#formspec + 1] = "]"
378+
elseif not package.path then
398379
formspec[#formspec + 1] = "button[8.4,0;1.5,1;install_"
399380
formspec[#formspec + 1] = tostring(i)
400381
formspec[#formspec + 1] = ";"

0 commit comments

Comments
 (0)