Skip to content

Verify downloaded book opening fix is implemented#46

Closed
Copilot wants to merge 1 commit into
mainfrom
copilot/fix-downloaded-book-opening
Closed

Verify downloaded book opening fix is implemented#46
Copilot wants to merge 1 commit into
mainfrom
copilot/fix-downloaded-book-opening

Conversation

Copilot AI commented Dec 7, 2025

Copy link
Copy Markdown
Contributor

The problem statement describes a critical issue where downloaded books fail to open after placeholder replacement, leaving users with blank screens. Investigation reveals this fix was already implemented in PR #45.

Verification Results

The required fix exists at opdsbrowser.koplugin/main.lua:496-509:

-- Open the downloaded book IMMEDIATELY (no delay to prevent empty UI)
local ReaderUI = require("apps/reader/readerui")
ReaderUI:showReader(filepath)

-- Background: Refresh file manager and force cache clearing
UIManager:scheduleIn(1, function()
    local FileManager = require("apps/filemanager/filemanager")
    if FileManager.instance then
        FileManager.instance:onRefresh()
        logger.info("OPDS: Background file manager refresh complete")
    end
end)

Current Flow

  1. Placeholder opens → download completes → placeholder reader closes
  2. File operations: delete placeholder, rename temp file, clear caches
  3. Downloaded book opens immediately via ReaderUI:showReader(filepath)
  4. File manager refreshes in background

Status

No code changes needed. The implementation matches problem statement requirements exactly. Syntax validated with luac5.3.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Critical Issue: Downloaded book not opened after placeholder replacement

Problem

When a placeholder book is opened and the OPDS download completes successfully, the placeholder file is deleted and the downloaded book is saved correctly, but the downloaded book is never opened. The user sees the placeholder re-open or gets a blank screen, and when they reload, they still see the placeholder (even though it was actually deleted and replaced).

Root Cause

After analyzing the code in opdsbrowser.koplugin/main.lua, the _finishPlaceholderDownload function successfully:

  1. ✅ Closes the placeholder reader
  2. ✅ Downloads the book to a temp file
  3. ✅ Validates the download is not a placeholder
  4. ✅ Deletes the placeholder file
  5. ✅ Renames temp file to final location
  6. ✅ Validates the final file is correct
  7. ✅ Clears all caches (placeholder badge, document settings)
  8. ✅ Logs "Successfully downloaded book, opening: [filepath]"
  9. MISSING: Actually calls ReaderUI:showReader(filepath) to open the downloaded book

The code around line 493 logs that it will open the book but appears to be missing the actual call to ReaderUI:showReader(filepath).

Required Fix

At the end of the _finishPlaceholderDownload function in opdsbrowser.koplugin/main.lua, after all validation and cache clearing is complete (around line 493), add:

-- Open the downloaded book IMMEDIATELY (no delay to prevent empty UI)
local ReaderUI = require("apps/reader/readerui")
ReaderUI:showReader(filepath)

-- Background: Refresh file manager after book opens
UIManager:scheduleIn(1, function()
    local FileManager = require("apps/filemanager/filemanager")
    if FileManager.instance then
        FileManager.instance:onRefresh()
        logger.info("OPDS: Background file manager refresh complete")
    end
end)

This will:

  1. Immediately open the downloaded book in the reader
  2. Schedule a background refresh of the file manager so the library view updates
  3. Provide immediate user feedback (book opens right away)

Expected Behavior After Fix

  1. User opens placeholder
  2. Download message appears
  3. Placeholder closes
  4. Downloaded book immediately opens ← This is what's missing
  5. User can start reading the real book
  6. If user exits and reloads, they see the real book (not placeholder)

Testing

After this fix:

  • Opening a placeholder should immediately show the downloaded book
  • The placeholder file should be gone from disk
  • Reloading should always show the real book
  • No blank screens or re-opening of placeholders

This is a simple fix - just need to add the missing ReaderUI:showReader(filepath) call at the end of the function.

This pull request was created as a result of the following prompt from Copilot chat.

Critical Issue: Downloaded book not opened after placeholder replacement

Problem

When a placeholder book is opened and the OPDS download completes successfully, the placeholder file is deleted and the downloaded book is saved correctly, but the downloaded book is never opened. The user sees the placeholder re-open or gets a blank screen, and when they reload, they still see the placeholder (even though it was actually deleted and replaced).

Root Cause

After analyzing the code in opdsbrowser.koplugin/main.lua, the _finishPlaceholderDownload function successfully:

  1. ✅ Closes the placeholder reader
  2. ✅ Downloads the book to a temp file
  3. ✅ Validates the download is not a placeholder
  4. ✅ Deletes the placeholder file
  5. ✅ Renames temp file to final location
  6. ✅ Validates the final file is correct
  7. ✅ Clears all caches (placeholder badge, document settings)
  8. ✅ Logs "Successfully downloaded book, opening: [filepath]"
  9. MISSING: Actually calls ReaderUI:showReader(filepath) to open the downloaded book

The code around line 493 logs that it will open the book but appears to be missing the actual call to ReaderUI:showReader(filepath).

Required Fix

At the end of the _finishPlaceholderDownload function in opdsbrowser.koplugin/main.lua, after all validation and cache clearing is complete (around line 493), add:

-- Open the downloaded book IMMEDIATELY (no delay to prevent empty UI)
local ReaderUI = require("apps/reader/readerui")
ReaderUI:showReader(filepath)

-- Background: Refresh file manager after book opens
UIManager:scheduleIn(1, function()
    local FileManager = require("apps/filemanager/filemanager")
    if FileManager.instance then
        FileManager.instance:onRefresh()
        logger.info("OPDS: Background file manager refresh complete")
    end
end)

This will:

  1. Immediately open the downloaded book in the reader
  2. Schedule a background refresh of the file manager so the library view updates
  3. Provide immediate user feedback (book opens right away)

Expected Behavior After Fix

  1. User opens placeholder
  2. Download message appears
  3. Placeholder closes
  4. Downloaded book immediately opens ← This is what's missing
  5. User can start reading the real book
  6. If user exits and reloads, they see the real book (not placeholder)

Testing

After this fix:

  • Opening a placeholder should immediately show the downloaded book
  • The placeholder file should be gone from disk
  • Reloading should always show the real book
  • No blank screens or re-opening of placeholders

This is a simple fix - just need to add the missing ReaderUI:showReader(filepath) call at the end of the function.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix issue with opening downloaded book after placeholder replacement Verify downloaded book opening fix is implemented Dec 7, 2025
Copilot AI requested a review from shiggsy365 December 7, 2025 23:49
@shiggsy365 shiggsy365 closed this Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants