Code Monkey home page Code Monkey logo

Comments (10)

poire-z avatar poire-z commented on June 2, 2024 1

In that user patch #11469 (comment), I just quickly used the typography language to get something to toggle it.
There may be other more proper ways to toggle the patch than having to change typography language and having that need leak into profile/gestures - so let's not implement this feature request until it feels it is needed for other better reasons :)

The right way to help you is to tweak/improve the user patch, ie. by having it depend on another existing useless setting, or by having it properly add a menu item and a setting.

Quick try, that gets you a menu item in the first top level menu, add to the top of the patch (after the bunch of local = ... require(...):

ReaderRolling_orig_addToMainMenu = ReaderRolling.addToMainMenu
ReaderRolling.addToMainMenu = function(self, menu_items)
    ReaderRolling_orig_addToMainMenu(self, menu_items)
    menu_items.toggle_vertical_hack =  {
        text = "Toggle verting reading hack",
        checked_func = function()
            return self.ui.doc_settings:isTrue("vertical_reading_hack")
        end,
        callback = function()
            self.ui.doc_settings:flipNilOrFalse("vertical_reading_hack")
            self.ui:reloadDocument()
        end,
    }
end

and in the existing ReaderRolling.onPreRenderDocument, replace the first condition check:

ReaderRolling.onPreRenderDocument = function(self)
    -- Only enable these hacks when the typography language has been set to Japanese.
    -- if self.ui.typography.text_lang_tag ~= "ja" then
    -- Let's do it with a setting toggable via the menu item defined above
    if not self.ui.doc_settings:isTrue("vertical_reading_hack") then
        return
    end

Pinging @plateaukao if you want to include/improve that , as after #11469 (comment), you are now the official maintainer of this user patch :)

from koreader.

hius07 avatar hius07 commented on June 2, 2024 1

For example

menu_items.autostandby = {
sorting_hint = "device",
text = _("Auto-standby settings"),

All menu item ids you can see in
https://github.com/koreader/koreader/blob/master/frontend/ui/elements/reader_menu_order.lua

from koreader.

poire-z avatar poire-z commented on June 2, 2024 1

Not sure what you have on line 949 of readertoc.lua (dunno which version of KOReader you are running, but I see nothing of interest in current nightly or last stable).
Didn't crash for me... because I had the NEW: menu item on the 2nd menu page. It crashes too when I use another document with less menu items so it gets on the first page.

Should fix that:

-- Add this to the top:
local UIManager = require("ui/uimanager")

-- And use this instead:
ReaderRolling_orig_addToMainMenu = ReaderRolling.addToMainMenu
ReaderRolling.addToMainMenu = function(self, menu_items)
    ReaderRolling_orig_addToMainMenu(self, menu_items)
    menu_items.toggle_vertical_hack =  {
        text = "Toggle verting reading hack",
        checked_func = function()
            return self.ui.doc_settings:isTrue("vertical_reading_hack")
        end,
        callback = function(touchmenu_instance)
            self.ui.doc_settings:flipNilOrFalse("vertical_reading_hack")
            UIManager:nextTick(function()
                self.ui:reloadDocument()
            end)
        end,
    }
end

Also, May I know further how I can debug more effeciently than just keep copying the modified script onto my device? If there's a developer doc that I missed, please let me know.

Dunno about how to speed things up on Android.
We have an emulator for linux desktops.
Otherwise, it's what you do: edit the file and push it on the device, and restart KOReader to test.
There is the Text Editor plugin to edit files, but it's not usable for developping, just for quick testing like changeing a value and restart.

As for developper docs, nothing more than this https://koreader.rocks/doc/ - and it's just best to read the existing code, related/similar parts to what you are doing and copy & pasting & experimenting...

from koreader.

plateaukao avatar plateaukao commented on June 2, 2024

That's what I am thinking too, to have an independent setting to toggle it. Thanks for providing the code snippet. I'll look into how to integrate it.

from koreader.

hius07 avatar hius07 commented on June 2, 2024

a menu item in the first top level menu

sorting_hint may help to place it to the desired submenu.

from koreader.

plateaukao avatar plateaukao commented on June 2, 2024

@poire-z
I tried to integrate your code snippet, it crashes when clicking on the created menu item, with following error log:
ps. although it crashes, after I restart KOReader, the book is correctly enabled with the vertical_read feature. seems something wrong when calling self.ui:reloadDocument()? Also, May I know further how I can debug more effeciently than just keep copying the modified script onto my device? If there's a developer doc that I missed, please let me know. Thanks!

image

my commit is here: plateaukao/koreader_patch_vertical_read@024e383

Hi, @hius07
What do you mean by sorting_hint may help to place it to the desired submenu. ?
is it a variable of some object, or any document I should look into?

from koreader.

plateaukao avatar plateaukao commented on June 2, 2024

Thanks @poire-z and @hius07
Now the script could work.

Hi, @smarliecy
I've modified the patch, so that it does not depend on epub file language. You can toggle the effect under second menu list with a new menu item "Toggle vertical reading". As for supporting gesture, I checked a bit, but couldn't figure out how to add it. So, I think it should be good enough for now. :)
image

file: https://github.com/plateaukao/koreader_plugin_vertical_read/blob/main/2-cre-rotate-japanese-book.lua

from koreader.

plateaukao avatar plateaukao commented on June 2, 2024

Hi, @poire-z
I tried to add Vertical-Reading-Toggle feature to action list, and it did appear in Gesture settings. However, when enabling it, and click on designated area, it seems failed to get document (or the self object) and crashed. Usually, there's no crash logs on screen.

pr: https://github.com/plateaukao/koreader_plugin_vertical_read/pull/1/files

Could you give me some hint how I can fix it? Or it's better to move the implementations to a normal plugin, so that self object is available?

Thanks in advance.

from koreader.

poire-z avatar poire-z commented on June 2, 2024

Your code doesn't crash for me, when I associate it to tap top left corner or a multiswipe.
So, I really dunno what to tell you :)
Try to look into the crash.log - on Android the issue template says:

Android logs are kept in memory. Please go to [Menu] → Help → Bug Report to save these logs to a file.

I do get a crash though (in my original code) when I invoke Book information:

./luajit: ./patches/2-cre-rotate-japanese-book.lua:100: attempt to call method 'copy' (a nil value)
stack traceback:
        ./patches/2-cre-rotate-japanese-book.lua:100: in function 'getTextFromPositions'
        frontend/apps/reader/modules/readerview.lua:1304: in function 'getCurrentPageLineWordCounts'
        frontend/apps/filemanager/filemanagerbookinfo.lua:156: in function 'show'
        frontend/apps/filemanager/filemanagerbookinfo.lua:298: in function 'handleEvent'

The getCurrentPageLineWordCounts doesn't provide real Geom objects to that getTextFromPositions, so :copy() does not exist.
Fix that case around line 100 with:

    document.getTextFromPositions = function(self, pos0, pos1, do_not_draw_selection)
        if not pos0.copy then -- not a real Geom object
            return orig_getTextFromPositions(self, pos0, pos1, do_not_draw_selection)
        end
        pos0 = pos0:copy()

(Yes, we are adding hacks to a hack :/)

Or it's better to move the implementations to a normal plugin, so that self object is available?

No, and this is really not a "koreader plugin", and can't be: a plugin is some other independant module that do its own stuff, and usually don't hack into the core code.
Here, we just hack into the core code: we don't add any independant functionality - so it's quite non-convertible to a plugin. The only common things you could have in a plugin is the addToMainMenu and the onToggleVerticalReading event, which is only 20% of the work - but you can just as easily plug them into ReaderRolling, no need to have a plugin just to expose them.

On your project page, and to avoid confusion remove any notion of "plugin", and use "user-patch", and link to https://github.com/koreader/koreader/wiki/User-patches for how to install it.

from koreader.

plateaukao avatar plateaukao commented on June 2, 2024

@poire-z
Thanks for the reply and the clear explanation between user-patch and plugin! 😄

I found that my testing android device was using an old version of KOReader (way back to last year). After updating it to latest one, the action menu and normal menu works great!
Now the feature is almost perfect~ 🙇

from koreader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.