Skip to content

Commit 53b99f4

Browse files
committed
fix: Capture filename BEFORE closing dialog to prevent nil
The onCloseWidget callback was clearing browser._custom_filename when the dialog closed. But the download callbacks were reading the filename AFTER closing the dialog, so they got nil, which caused DownloadManager to fall back to server filename. Fix: Capture browser._custom_filename into a local variable BEFORE calling UIManager:close() on the dialogs.
1 parent 9b841c1 commit 53b99f4

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

ui/dialogs/book_info_dialog.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,15 @@ local function showFormatSelectionDialog(browser, item, downloadable, add_to_que
153153
{
154154
text = text,
155155
callback = function()
156+
-- IMPORTANT: Capture filename BEFORE closing dialogs
157+
-- because onCloseWidget clears browser._custom_filename
158+
local filename = browser._custom_filename
159+
156160
UIManager:close(browser.format_dialog)
157161
if parent_dialog then
158162
UIManager:close(parent_dialog)
159163
end
160164

161-
-- Get the current filename at download time (not dialog creation time)
162-
local filename = browser._custom_filename
163165
local local_path = DownloadManager.getLocalDownloadPath(
164166
browser, filename, dl.filetype, dl.acquisition.href)
165167

@@ -473,9 +475,11 @@ function BookInfoDialog.build(browser, item)
473475
table.insert(action_row, {
474476
text = Constants.ICONS.DOWNLOAD .. " " .. _("Download") .. " (" .. string.upper(dl.filetype) .. ")",
475477
callback = function()
478+
-- Capture filename BEFORE closing dialog
479+
local filename = browser._custom_filename
476480
UIManager:close(browser.book_info_dialog)
477481
local local_path = DownloadManager.getLocalDownloadPath(
478-
browser, browser._custom_filename, dl.filetype, dl.acquisition.href)
482+
browser, filename, dl.filetype, dl.acquisition.href)
479483
DownloadManager.checkDownloadFile(browser, local_path, dl.acquisition.href,
480484
browser.root_catalog_username, browser.root_catalog_password,
481485
browser.file_downloaded_callback)
@@ -496,9 +500,11 @@ function BookInfoDialog.build(browser, item)
496500
table.insert(action_row, {
497501
text = "+" .. " " .. _("Queue"),
498502
callback = function()
503+
-- Capture filename BEFORE closing dialog
504+
local filename = browser._custom_filename
499505
UIManager:close(browser.book_info_dialog)
500506
local local_path = DownloadManager.getLocalDownloadPath(
501-
browser, browser._custom_filename, dl.filetype, dl.acquisition.href)
507+
browser, filename, dl.filetype, dl.acquisition.href)
502508
DownloadManager.addToDownloadQueue(browser, {
503509
file = local_path,
504510
url = dl.acquisition.href,

0 commit comments

Comments
 (0)