Skip to content

Commit cc9bed9

Browse files
p-ouellettenerzhul
authored andcommittedFeb 18, 2019
Fix content store crash (#8244)
1 parent 6e7ba36 commit cc9bed9

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed
 

‎builtin/mainmenu/dlg_contentstore.lua

+10-26
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,7 @@ local function get_screenshot(package)
185185
if not success then
186186
core.log("warning", "Screenshot download failed for some reason")
187187
end
188-
189-
local ele = ui.childlist.store
190-
if ele and not ele.hidden then
191-
core.update_formspec(ele:formspec())
192-
else
193-
ele = ui.childlist.package_view
194-
if ele and not ele.hidden then
195-
core.update_formspec(ele:formspec())
196-
end
197-
end
188+
ui.update()
198189
end
199190
if core.handle_async(download_screenshot,
200191
{ dest = filepath, url = package.thumbnail }, callback) then
@@ -245,7 +236,7 @@ function package_dialog.get_formspec()
245236
return table.concat(formspec, "")
246237
end
247238

248-
function package_dialog.handle_submit(this, fields, tabname, tabdata)
239+
function package_dialog.handle_submit(this, fields)
249240
if fields.back then
250241
this:delete()
251242
return true
@@ -395,11 +386,11 @@ function store.filter_packages(query)
395386

396387
end
397388

398-
function store.get_formspec()
389+
function store.get_formspec(dlgdata)
399390
store.update_paths()
400391

401-
local pages = math.ceil(#store.packages / num_per_page)
402-
if cur_page > pages then
392+
dlgdata.pagemax = math.max(math.ceil(#store.packages / num_per_page), 1)
393+
if cur_page > dlgdata.pagemax then
403394
cur_page = 1
404395
end
405396

@@ -428,7 +419,7 @@ function store.get_formspec()
428419
"button[8.1,0;1,1;pback;<]",
429420
"label[9.2,0.2;",
430421
tonumber(cur_page), " / ",
431-
tonumber(pages), "]",
422+
tonumber(dlgdata.pagemax), "]",
432423
"button[10.1,0;1,1;pnext;>]",
433424
"button[11.1,0;1,1;pend;>>]",
434425
"container_end[]",
@@ -515,12 +506,11 @@ function store.get_formspec()
515506
return table.concat(formspec, "")
516507
end
517508

518-
function store.handle_submit(this, fields, tabname, tabdata)
509+
function store.handle_submit(this, fields)
519510
if fields.search or fields.key_enter_field == "search_string" then
520511
search_string = fields.search_string:trim()
521512
cur_page = 1
522513
store.filter_packages(search_string)
523-
core.update_formspec(store.get_formspec())
524514
return true
525515
end
526516

@@ -531,34 +521,28 @@ function store.handle_submit(this, fields, tabname, tabdata)
531521

532522
if fields.pstart then
533523
cur_page = 1
534-
core.update_formspec(store.get_formspec())
535524
return true
536525
end
537526

538527
if fields.pend then
539-
cur_page = math.ceil(#store.packages / num_per_page)
540-
core.update_formspec(store.get_formspec())
528+
cur_page = this.data.pagemax
541529
return true
542530
end
543531

544532
if fields.pnext then
545533
cur_page = cur_page + 1
546-
local pages = math.ceil(#store.packages / num_per_page)
547-
if cur_page > pages then
534+
if cur_page > this.data.pagemax then
548535
cur_page = 1
549536
end
550-
core.update_formspec(store.get_formspec())
551537
return true
552538
end
553539

554540
if fields.pback then
555541
if cur_page == 1 then
556-
local pages = math.ceil(#store.packages / num_per_page)
557-
cur_page = pages
542+
cur_page = this.data.pagemax
558543
else
559544
cur_page = cur_page - 1
560545
end
561-
core.update_formspec(store.get_formspec())
562546
return true
563547
end
564548

0 commit comments

Comments
 (0)
Please sign in to comment.