fix(sync): report interactive push/pull failures when offline

An interactive pull could exit without any feedback while push showed
'Failed to push progress', from two silent exits on the pull path:

- pulling an unlinked book delegated to a non-interactive push whose
  failure produced no UI (and could be swallowed by the 25s debounce)
- when the device is connected at the IP level but has no internet,
  NetworkMgr:willRerunWhenOnline drops the callback with neither a
  rerun nor any UI (it only guarantees isConnected)

Now the connected-but-offline state is detected up front and reported
('No internet connection. Progress was not pulled/pushed.'), resolve
failures notify interactively, pulling with progress sync disabled
explains itself instead of silently returning, and the generic pull
failure message mentions the network connection like push does.
This commit is contained in:
2026-08-22 09:57:26 -04:00
parent 9467bdb2bd
commit 656505eda7
+54 -13
View File
@@ -990,7 +990,15 @@ function Bookhoard:updateProgress(ensure_networking, interactive)
return return
end end
if not self.settings.sync_progress then return end if not self.settings.sync_progress then
if interactive then
UIManager:show(InfoMessage:new{
text = _("Reading progress sync is disabled (see What to sync)."),
timeout = 3,
})
end
return
end
if not self.ui.document then if not self.ui.document then
if interactive then if interactive then
@@ -1007,9 +1015,19 @@ function Bookhoard:updateProgress(ensure_networking, interactive)
return return
end end
if ensure_networking if ensure_networking then
and NetworkMgr:willRerunWhenOnline(function() self:updateProgress(ensure_networking, interactive) end) then -- Same silent-drop case as getProgress: connected but no internet
return -- means willRerunWhenOnline neither reruns nor shows any UI.
if interactive and NetworkMgr:isConnected() and not NetworkMgr:isOnline() then
UIManager:show(InfoMessage:new{
text = _("No internet connection. Progress was not pushed."),
timeout = 3,
})
return
end
if NetworkMgr:willRerunWhenOnline(function() self:updateProgress(ensure_networking, interactive) end) then
return
end
end end
UIManager:scheduleIn(0.5, function() UIManager:scheduleIn(0.5, function()
@@ -1078,30 +1096,53 @@ function Bookhoard:getProgress(ensure_networking, interactive)
return return
end end
if not self.settings.sync_progress then return end if not self.settings.sync_progress then
if interactive then
UIManager:show(InfoMessage:new{
text = _("Reading progress sync is disabled (see What to sync)."),
timeout = 3,
})
end
return
end
local now = UIManager:getElapsedTimeSinceBoot() local now = UIManager:getElapsedTimeSinceBoot()
if not interactive and now - self.pull_timestamp <= API_CALL_DEBOUNCE_DELAY then if not interactive and now - self.pull_timestamp <= API_CALL_DEBOUNCE_DELAY then
return return
end end
if ensure_networking if ensure_networking then
and NetworkMgr:willRerunWhenOnline(function() self:getProgress(ensure_networking, interactive) end) then -- willRerunWhenOnline silently drops the action (no rerun, no UI)
return -- when the device is connected at the IP level but has no internet
-- access: it only guarantees isConnected, and in that state the
-- framework re-connects without ever invoking the callback. Catch
-- that state up front so an interactive pull never no-ops silently.
if interactive and NetworkMgr:isConnected() and not NetworkMgr:isOnline() then
UIManager:show(InfoMessage:new{
text = _("No internet connection. Progress was not pulled."),
timeout = 3,
})
return
end
if NetworkMgr:willRerunWhenOnline(function() self:getProgress(ensure_networking, interactive) end) then
return
end
end end
local book_uuid = self:getBookhoardUUID() local book_uuid = self:getBookhoardUUID()
if not book_uuid then if not book_uuid then
-- No cached UUID yet (first open of a freshly downloaded book). Bootstrap -- No cached UUID yet (first open of a freshly downloaded book). Link
-- it by pushing once: the server resolves the book by SHA-256 and returns -- the book with a read-only SHA-256 lookup, then pull. Progress is
-- the UUID, which the push handler caches. Then retry the pull. -- never pushed here: the device sits on the first page of a book the
-- server may hold mid-read, and pushing that would overwrite/server-
-- conflict the real progress before the pull could deliver it.
if interactive then if interactive then
UIManager:show(InfoMessage:new{ UIManager:show(InfoMessage:new{
text = _("Linking this book to Bookhoard first…"), text = _("Linking this book to Bookhoard first…"),
timeout = 3, timeout = 3,
}) })
end end
self:_bootstrapUUIDThenPull(interactive) self:_linkBookThenPull(interactive)
return return
end end
@@ -1201,7 +1242,7 @@ function Bookhoard:_doGetProgress(interactive)
if not ok or not result then if not ok or not result then
if interactive then if interactive then
UIManager:show(InfoMessage:new{ UIManager:show(InfoMessage:new{
text = _("Failed to pull progress."), text = _("Failed to pull progress. Check your network connection."),
timeout = 3, timeout = 3,
}) })
end end