Fix crash on progress pull: gotoPercent is not a document method
Pulling progress crashed KOReader in syncToProgress when the target wasn't a page number or xpointer (e.g. an epubcfi string from the server on a rolling document, falling to the percentage branch): 'attempt to call method gotoPercent (a nil value)'. Documents have no such method — navigation goes through events, exactly as the other branches in this function already do. The percentage fallback now dispatches Event GotoPercent (0-100), handled by ReaderRolling:onGotoPercent and ReaderPaging:onGotoPercent (the built-in Go-to-% handlers, which also refresh the view). The redundant UpdatePos follow-up is gone; handlers do it. Verified all four paths in the stub harness: rolling+percentage → Event:GotoPercent, rolling+xpointer → Event:GotoXPointer, paging+ page → Event:GotoPage, paging+unresolvable → no-op. No crashes.
This commit is contained in:
@@ -909,8 +909,11 @@ function Bookhoard:syncToProgress(progress, percentage)
|
|||||||
elseif progress and progress:match("^/body/") then
|
elseif progress and progress:match("^/body/") then
|
||||||
self.ui:handleEvent(Event:new("GotoXPointer", progress))
|
self.ui:handleEvent(Event:new("GotoXPointer", progress))
|
||||||
elseif percentage then
|
elseif percentage then
|
||||||
self.ui.document:gotoPercent(percentage * 100)
|
-- Navigation goes through events (ReaderRolling/ReaderPaging both
|
||||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
-- implement onGotoPercent and refresh the view themselves). Calling
|
||||||
|
-- document:gotoPercent directly crashed KOReader — no such method
|
||||||
|
-- exists on documents.
|
||||||
|
self.ui:handleEvent(Event:new("GotoPercent", percentage * 100))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user