Skip to content

Couple of minor fixes#13185

Merged
hius07 merged 10 commits into
koreader:masterfrom
hius07:fixes
Feb 1, 2025
Merged

Couple of minor fixes#13185
hius07 merged 10 commits into
koreader:masterfrom
hius07:fixes

Conversation

@hius07

@hius07 hius07 commented Feb 1, 2025

Copy link
Copy Markdown
Member

(1) Annotations: don't create annotation datetime_modified if it is equal to datetime.
(2) ReaderUI: set correct book status when opening old books


This change is Reviewable

Comment on lines +432 to +435
if self.ui.pagemap and self.ui.pagemap:wantsPageLabels() then
if self.ui.rolling and self.ui.pagemap:wantsPageLabels() then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ?
Currently, pagemap is only loaded when rolling, so your change assumes that - but if one day we have pagemap working with pdf or handmade, we may forget about this one. And logically, the test means check for self.ui.pagemap existence before calling its wantsPageLabels() method - so this reads strange. If you ever want to restrict this to rolling, if self.ui.rolling and self.ui.pagemap and self.ui.pagemap:wantsPageLabels() then would feel more logical.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency. We never check for existence of registered submodules, but always have the main fork paging/rolling. This is the only exception.

When (if) the pagemap is added to paging, we will have to grep pagemap and remove if self.ui.pagemap (or, after the above changes, if self.ui.rolling) from everywhere.

@hius07 hius07 Feb 1, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading if self.ui.pagemap, one may think that the pagemap module appears depending on some conditions (when a user creates custom pagemap, for example).
But the condition is rolling only.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the condition is rolling only.

You're used to that because of the numerous checks you did for highlights/annotations and the different formats and expected stuff.

Reading if self.ui.pagemap, one may think that the pagemap module appears depending on some conditions

When reading this here, I wouldn't think that. I would just consider it a logical "exists before accessing the method". Not reading it would have me check if it can happen rolling but not pagemap, or why do the pagemap stuff only when rolling, and have me check that indeed, pagemap is there because rolling is there.
I don't need to know here that pagemap depends on rollling.

So, I disagree :) but if you really want it, I would read it better if it were on 2 lines:

if self.ui.rolling then
    if self.ui.pagemap:wantsPageLabels() then

It would still not answer my above comments, but at least, it would not look like an error in "exists before accessing the method".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I erroneously removed if self.ui.pagemap because I remembered that it was a registered module but didn't remember that it was registered by rollling only. CircleCI tests have failed.
I wouldn't have done the mistake if I saw if self.ui.rolling instead.
Anyway, restoring.

function ReaderAnnotation:onAnnotationsModified(items)
items[1].datetime_updated = os.date("%Y-%m-%d %H:%M:%S")
local now = os.date("%Y-%m-%d %H:%M:%S")
if items[1].datetime ~= now then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a condition that based on the diff looks like it'd nearly always be true? They're likely to be equal in practice?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation datetime property is filled on creation. Then, when modifying the annotation - adding a note, changing the boundaries etc, the AnnotationsModified event is sent and the datetime_updated property is set.

@hius07 hius07 Feb 1, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, when the annotation is created, the event is sent too, so the check is false and datetime_updated isn't created.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naively I'd expect created and updated to be the same at the time of creation (or put another way, queryable), but I haven't followed the annotation developments in-depth.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, when the annotation is created, the event is sent too

Feels a bit clumsy to check the datetime against now to guess, in a :onAnnotationsModified(), that it is not modifed but created.
Isn't there a cleaner way to handle that ? Not calling onAnnotationsModified if it is... not modified ? :) or passing another arg created=true ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Frenzie Frenzie added this to the 2025.02 milestone Feb 1, 2025
Comment thread frontend/ui/widget/booklist.lua Outdated
Comment on lines +107 to +114
local status_string = ({
new = _("New"), -- no sidecar file
reading = _("Reading"), -- doc_settings.summary.status
abandoned = _("On hold"), -- doc_settings.summary.status
complete = _("Finished"), -- doc_settings.summary.status
deleted = _("Deleted"),
all = _("All"),
})[status]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(You're just moving it around, so I should have asked that ealier :)
Not worth having it as a module local ?
(Dunno how luajit works with that, but creating that small table everytime, with newly created strings then removed, may uses more cpu than if it was long-living - moreover if this function BookList.getBookStatusString() can be caller tons of time when we browse files or collections.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@hius07 hius07 merged commit 8606b13 into koreader:master Feb 1, 2025
@hius07 hius07 deleted the fixes branch February 1, 2025 19:25
})[status]
return with_prefix and T(_("Status: %1"), status_string:lower()) or status_string
local status_string = status and status_strings[status]
return status_string and (with_prefix and T(_("Status: %1"), status_string:lower()) or status_string)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably too clever btw; I'd overlooked it previously (wrt #13277)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have 2 dialogs with plural and 2 with singular usages of these strings, if differentiate.

@Frenzie Frenzie Feb 17, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the string:lower(). Hopefully it doesn't matter too much, let's wait and see if anyone complains. :-)

@hius07 hius07 mentioned this pull request Feb 18, 2025
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants