PocketBook: Simplify openLink impl - use inkview.OpenBook instead

Somewhat unintuitively, OpenBook does exactly what we want if we pass
the browser binary as the book and the URL as parameters.

It does a couple extra things we don't need, like checking if the
browser binary is being viewed by the built-in epub reading software,
and possibly some more stuff I don't quite understand, but at the end it
does almost exactly what OpenTask from the new PocketBook SDK does.

Actually, OpenBook2 is closer to OpenTask, as it takes `const char **argv`
rather than a single argument, but: we don't need multiple arguments,
and the single-argument version might work better on older PocketBook
firmwares (like the PB624 which is stuck with InkView 4.4).
pull/11787/head
Tomas Janousek 4 weeks ago
parent 18581965de
commit 916050dea4

@ -442,40 +442,9 @@ function PocketBook:canOpenLink()
end
function PocketBook:openLink(link)
if not link or type(link) ~= "string" then return end
-- SendRequestToNoWait only available in PocketBook SDK since 5.17
local inkview_SendRequestTo
if pcall(function() local _ = inkview.SendRequestToNoWait end) then
inkview_SendRequestTo = function(t, r, d, l) inkview.SendRequestToNoWait(t, r, d, l, 0) end
else
inkview_SendRequestTo = function(t, r, d, l) inkview.SendRequestTo(t, r, d, l, 0, 2000) end
end
local appname = "browser.app"
local task = inkview.FindTaskByAppName(appname)
if task > 0 then
local data = ffi.new("void *[1]")
local len = ffi.new("int[1]")
inkview.PackParameters(1, ffi.new("const char *[1]", {link}), data, len)
inkview_SendRequestTo(task, C.REQ_OPENBOOK2, data[0], len[0])
C.free(data[0])
inkview.SetActiveTask(task, 0)
else
local _, bin = getBrowser()
local args = ffi.new("const char *[3]", {bin, link, nil})
inkview.NewTask(bin, ffi.cast("char **", args), appname, appname, nil, C.TASK_MAKEACTIVE)
end
-- the above logic is available in newer PocketBook SDKs [1] as OpenTask:
--
-- ffi.cdef[[ int OpenTask(const char *, int, const char **, int); ]]
--
-- local argv = ffi.new("const char *[1]", {link})
-- inkview.OpenTask("/usr/bin/browser.app", 1, argv, C.TASK_MAKEACTIVE)
--
-- we're using an older SDK for compatibility, so we need to handle this manually
--
-- [1]: https://github.com/pocketbook/SDK_6.3.0/blob/6.5/SDK-B288/usr/arm-obreey-linux-gnueabi/sysroot/usr/local/include/inkview.h
local found, bin = getBrowser()
if not found or not link or type(link) ~= "string" then return end
inkview.OpenBook(bin, link, 0)
end
-- Pocketbook HW rotation modes start from landsape, CCW

Loading…
Cancel
Save