Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Open links in PocketBook web browser #11782

Closed
liskin opened this issue May 8, 2024 · 5 comments · Fixed by #11787
Closed

FR: Open links in PocketBook web browser #11782

liskin opened this issue May 8, 2024 · 5 comments · Fixed by #11787

Comments

@liskin
Copy link
Contributor

liskin commented May 8, 2024

Many PocketBook devices include a web browser, but when clicking a link in KOReader, there's no option to open the link in the browser, there's only an option to show a QR code (which can then be scanned by a smartphone). It would be useful if KOReader offered an option to open it directly on the device browser itself.

I was able to make this work on PB740 (InkPad 3) using the following userpatch (1-pocketbook-browser.lua):

local PocketBook = require("device/pocketbook/device")
local ffi = require("ffi")
local C = ffi.C
local inkview = ffi.load("inkview")

require("ffi/inkview_h")
ffi.cdef[[
/**
 * @brief OpenTask runs child process or make active existing process of specified exe if exist
 * @param path - path/to/exe
 * @param argc - args ptr
 * @param argv - args count
 * @param flags - TASK_* macros
 * @return 0 if created | 1 if already exist | -1 if fail
 */
int OpenTask(const char *path, int argc, const char * const* argv, int flags);
]]

function PocketBook:canOpenLink()
    return true
end

function PocketBook:openLink(link)
    if not link or type(link) ~= "string" then return end
    local argv = ffi.new("const char *[1]", {link})
    inkview.OpenTask("/usr/bin/browser.app", 1, argv, C.TASK_MAKEACTIVE)
end

I'm now seeking advice how to proceed if I wanted to submit this to KOReader as a PR. OpenTask is not available in the old SDK that's used for building KOReader for PocketBook, and I was unable to make this work using NewTask (it works once and then keeps segfaulting). So I can't just add OpenTask to base/ffi-cdecl/inkview_decl.c and use it.

Any ideas?

(I'll keep playing with NewTask and other inkview stuff a bit more but I'm not super hopeful.)

@liskin
Copy link
Contributor Author

liskin commented May 8, 2024

OpenTask itself seems to be implemented via NewTaskEx, but it also calls stuff like hw_task_findbyappname and sendParametersToTaskNoWait so I guess if I understood ARM assembly or used a decompiler I could theoretically piece a compat implementation of OpenTask together…

But then it's probably completely fine to just make this available on modern PocketBooks, if that's something that can be done.

@pazos
Copy link
Member

pazos commented May 8, 2024

But then it's probably completely fine to just make this available on modern PocketBooks, if that's something that can be done

That's totally ok. You can use PocketBook:getSoftwareVersion()

No real idea about the minimum supported version but I guess you could try from the major version your firmware is currently in and assume all devices work the same.

@liskin
Copy link
Contributor Author

liskin commented May 8, 2024

https://github.com/koreader/koreader/blob/master/frontend/device/pocketbook/device.lua#L400-L402

Well, that doesn't really solve anything. I can easily check for the existence of OpenTask this way:
https://github.com/koreader/koreader-base/blob/9a90ea881201ae64f188150b4e3c02daeb3901bc/ffi/input_pocketbook.lua#L17

But the issue is that it needs to be declared first, and I'm not meant to change base/ffi/inkview_h.lua manually, it's generated from base/ffi-cdecl/inkview_decl.c which uses the real inkview.h, but the one used is too old and doesn't have OpenTask.

I can obviously just ffi.cdef it manually but is that really something I'm meant to do?

@pazos
Copy link
Member

pazos commented May 9, 2024

Well, that doesn't really solve anything. I can easily check for the existence of OpenTask this way

cool :)

But the issue is that it needs to be declared first, and I'm not meant to change base/ffi/inkview_h.lua manually, it's generated from base/ffi-cdecl/inkview_decl.c which uses the real inkview.h, but the one used is too old and doesn't have OpenTask.

I can obviously just ffi.cdef it manually but is that really something I'm meant to do?

It is totally ok to define platform's behaviour manually. see android cdefs

Please keep base/ffi/inkview_h.lua as is and put your code somewhere else.

I'm not very fan of our current base/front split so maybe others can give you some suggestion.
I guess it belongs to base, I don't know if it worths the hussle to move it there.

@liskin
Copy link
Contributor Author

liskin commented May 9, 2024

Armed with https://ghidra-sre.org/, I've actually managed to make it work using NewTaskEx as well, so I might not need to declare OpenTask after all. I'll keep playing with it for a bit more as it's quite fun and then open a PR once I have something robust enough 🙂

liskin added a commit to liskin/koreader that referenced this issue May 9, 2024
Many PocketBook devices include a web browser, but when clicking a link
in KOReader, there was no option to open the link in the browser, there
was only an option to show a QR code (which can then be scanned by a
smartphone).

This commit implements `canOpenLink`/`openLink` on PocketBook using the
"browser.app", if available.

Tested on PB740 (InkPad 3).

Fixes: koreader#11782
Related: koreader#6597
liskin added a commit to liskin/koreader that referenced this issue May 9, 2024
Many PocketBook devices include a web browser, but when clicking a link
in KOReader, there was no option to open the link in the browser, there
was only an option to show a QR code (which can then be scanned by a
smartphone).

This commit implements `canOpenLink`/`openLink` on PocketBook using the
"browser.app", if available.

Tested on PB740 (InkPad 3).

Fixes: koreader#11782
Related: koreader#6597
@Frenzie Frenzie added this to the 2024.05 milestone May 9, 2024
liskin added a commit to liskin/koreader that referenced this issue May 15, 2024
Many PocketBook devices include a web browser, but when clicking a link
in KOReader, there was no option to open the link in the browser, there
was only an option to show a QR code (which can then be scanned by a
smartphone).

This commit implements `canOpenLink`/`openLink` on PocketBook using the
"browser.app", if available.

Tested on PB740 (InkPad 3).

Fixes: koreader#11782
Related: koreader#6597
liskin added a commit to liskin/koreader that referenced this issue May 15, 2024
Many PocketBook devices include a web browser, but when clicking a link
in KOReader, there was no option to open the link in the browser, there
was only an option to show a QR code (which can then be scanned by a
smartphone).

This commit implements `canOpenLink`/`openLink` on PocketBook using the
"browser.app", if available.

Tested on PB740 (InkPad 3).

Fixes: koreader#11782
Related: koreader#6597
liskin added a commit to liskin/koreader that referenced this issue May 16, 2024
Many PocketBook devices include a web browser, but when clicking a link
in KOReader, there was no option to open the link in the browser, there
was only an option to show a QR code (which can then be scanned by a
smartphone).

This commit implements `canOpenLink`/`openLink` on PocketBook using the
"browser.app", if available.

Tested on PB740 (InkPad 3) and PB624 (Basic Touch).
On the older device (PB624) it doesn't work quite as well—an already
running browser ignores the request to switch URL, but it doesn't work
with the built-in book reader software either.

Fixes: koreader#11782
Related: koreader#6597
Frenzie pushed a commit that referenced this issue May 18, 2024
Many PocketBook devices include a web browser, but when clicking a link in KOReader, there was no option to open the link in the browser, there was only an option to show a QR code (which can then be scanned by a smartphone).

This commit implements `canOpenLink`/`openLink` on PocketBook using the "browser.app", if available.

Tested on PB740 (InkPad 3).

Fixes: #11782
Related: #6597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants