Skip to content

[screensaver] Ignore sleep screen cover conditionally#13068

Merged
Frenzie merged 23 commits into
koreader:masterfrom
Commodore64user:exclude-read-books
Jan 17, 2025
Merged

[screensaver] Ignore sleep screen cover conditionally#13068
Frenzie merged 23 commits into
koreader:masterfrom
Commodore64user:exclude-read-books

Conversation

@Commodore64user

@Commodore64user Commodore64user commented Jan 14, 2025

Copy link
Copy Markdown
Member

what's new

This pull request introduces a new feature to allow users to hide sleep screen covers conditionally

  • frontend/ui/elements/screensaver_menu.lua: Added a new menu item "Ignore book cover" with sub-options to exclude book covers from the screensaver under specific conditions, such as for books on hold, finished books, and when in the file browser.
  • frontend/ui/screensaver.lua: Modified the Screensaver:setup function to check new settings for excluding book covers from the screensaver based on the book's status (finished or on hold) and the current UI context (file browser).

screenshots

hide cover off / hide cover on


This change is Reviewable

@Commodore64user Commodore64user changed the title Hide sleep screen covers for finished books Hide sleep screen covers conditionally Jan 14, 2025
genMenuItem(_("Show book status on sleep screen"), "screensaver_type", "bookstatus", hasLastFile),
genMenuItem(_("Leave screen as-is"), "screensaver_type", "disable", nil, true),
{
text = _("Book cover visibility rules"),

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.

May be stay simple like every where else - and consistent with "Do not show this book cover...":

Do not show book cover >
  Do not show book cover on finished books
  Do not show book cover in file browser

(Or "Ignore" instead of "Do not show" which was my first idea when reading "Hide..." - we're not really hiding it.)

(Feels a bit excessive options, we rarely stay on a finished book or in File browser - except may be as a way to explicitely not wanting to let the device with a cover, just switching to FM before suspend.)

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.

the part about closing from FM is something I have wanted for a bit, since I read in different devices and usually use a different one for every new book. the other bit is taken from #11080. I'm not sure about the Ignore book cover rules though

@Frenzie Frenzie left a comment

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.

Looks fine, I left some comments relating to the strings because I think they could be a lot shorter.

Comment thread frontend/ui/screensaver.lua
genMenuItem(_("Show book status on sleep screen"), "screensaver_type", "bookstatus", hasLastFile),
genMenuItem(_("Leave screen as-is"), "screensaver_type", "disable", nil, true),
{
text = _("Ignore book cover rules"),

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.

Maybe something like


Show book cover:

  • always
  • not when finished
  • not in file browser

Show book cover

  • always
  • only when reading
  • only when in document

Comment thread frontend/ui/elements/screensaver_menu.lua
@Frenzie Frenzie added this to the 2025.01 milestone Jan 15, 2025
genMenuItem(_("Leave screen as-is"), "screensaver_type", "disable", nil, true),
{
text = _("Ignore book cover"),
help_text = _("Choose to programatically not show book covers when locking the device from the file browser or after finishing a book."),

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.

Choose to programatically not show feels a bit too verbose, we have "programmatically" nowhere else, which is not surprising for a program which does it all programmatically :)
Decide to show or not book covers ... or something more straigthfoward.

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.

Maybe something like

Choose when to show book covers on the lock screen.

@Commodore64user Commodore64user Jan 15, 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.

How about this: ;)

Forsooth, by digital alchemy’s might,

Cloak book facades from prying sight;

When device locked or tale complete,

Let covers vanish, discreet and neat.

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.

A distinct lack of spacing. But yes, "choose to programmatically not show" must go, I was just too distracted by the regular text. :-)

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.

fixed, the spacing ;)

Comment thread frontend/ui/screensaver.lua Outdated
Comment on lines +459 to +464
doc_settings:makeTrue("exclude_screensaver_finished_or_on_hold")
if self.show_message then
self.show_message = false
end
else
doc_settings:makeFalse("exclude_screensaver_finished_or_on_hold")

@poire-z poire-z Jan 15, 2025

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.

What is this stored in doc_settings ?
doc_settings:isTrue("exclude_screensaver") is in it because it's a per-book decision.
Your check can just be dynamic in here, it does not need to store anything anywhere, doesn't it?

@Commodore64user Commodore64user Jan 15, 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.

I suppose not. but finished is also a per book decision.

text = _("Ignore book cover"),
help_text = _("Choose when to ignore showing book covers on the sleep screen."),
enabled_func = function()
return G_reader_settings:readSetting("screensaver_type") == "cover"

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.

Not familiar with all the screensaver modes, but you wrote "both the cover and sleep screen message": does the message in question only shows when screensaver_type=="cover" ? or are there some other modes which display some info about the book as a message over a black screen or random image - and does this setting apply then?

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.

does the message in question only shows when screensaver_type=="cover" ?

nope, but with all due respect to those who don't use the book cover. They are all, wrong ;). This PR exclusively acts on book covers, everyone else stay the same. the sleep screen message can be plastered on top of anything.

return G_reader_settings:readSetting("screensaver_type") == "cover"
end,
checked_func = function()
return G_reader_settings:isTrue("screensaver_exclude_finished_books") or G_reader_settings:isTrue("screensaver_hide_cover_in_filemanager")

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.

Missing screensaver_exclude_on_hold_books ?

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.

yeah, apparently in rushing to do the on hold before leaving, standards were lowered.

Comment thread frontend/ui/elements/screensaver_menu.lua Outdated
Comment thread frontend/ui/elements/screensaver_menu.lua Outdated
Comment thread frontend/ui/screensaver.lua Outdated
Comment on lines +453 to +471
local exclude_finished_books = G_reader_settings:isTrue("screensaver_exclude_finished_books")
local exclude_on_hold_books = G_reader_settings:isTrue("screensaver_exclude_on_hold_books")
local exclude_screensaver_fm = G_reader_settings:isTrue("screensaver_hide_cover_in_filemanager")
local book_summary = doc_settings:readSetting("summary")
local book_finished_or_on_hold = book_summary and (book_summary.status == "complete" or book_summary.status == "abandoned")
local exclude_screensaver_finished_or_on_hold = false
if (exclude_finished_books or exclude_on_hold_books) and book_finished_or_on_hold then
exclude_screensaver_finished_or_on_hold = true
if self.show_message then
self.show_message = false
end
end
if ui then -- ReaderUI instance
excluded = doc_settings:isTrue("exclude_screensaver") or exclude_screensaver_finished_or_on_hold
else -- FileManager instance
excluded = doc_settings:isTrue("exclude_screensaver") or exclude_screensaver_finished_or_on_hold or exclude_screensaver_fm
if self.show_message and exclude_screensaver_fm then
self.show_message = false
end

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.

All this logic is tedious to read - and because of that I think there is a bug (see other comment).
You should write it simpler and more logical

excluded = doc_settings:isTrue("exclude_screensaver")
if not excluded then
    if not ui and G_reader_settings:isTrue("screensaver_hide_cover_in_filemanager") then
        excluded = true
    else if ui then
        if  G_reader_settings:isTrue("screensaver_exclude_finished_books") or G_reader_settings:isTrue("screensaver_exclude_on_hold_books") then
            -- do your summary cuisine and checks and set exclude = true
        end
    end
end
if excluded then
    self.show_message = false
end

Comment thread frontend/ui/screensaver.lua Outdated
Comment on lines +457 to +460
local book_finished_or_on_hold = book_summary and (book_summary.status == "complete" or book_summary.status == "abandoned")
local exclude_screensaver_finished_or_on_hold = false
if (exclude_finished_books or exclude_on_hold_books) and book_finished_or_on_hold then
exclude_screensaver_finished_or_on_hold = true

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.

Looks like if I have G_reader_settings:isTrue("screensaver_exclude_on_hold_books") and the book is finished
or G_reader_settings:isTrue("screensaver_exclude_finished_books") and the book is on hold,
you will exclude that book cover.

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.

good eye.

@Commodore64user Commodore64user changed the title Hide sleep screen covers conditionally [screensaver] Ignore sleep screen cover conditionally Jan 16, 2025
Comment on lines +48 to +50
return G_reader_settings:isTrue("screensaver_exclude_finished_books")
or G_reader_settings:isTrue("screensaver_hide_cover_in_filemanager")
or G_reader_settings:isTrue("screensaver_exclude_on_hold_books")

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.

Please re-order them so hide_cover_in_filemanager doesn't end in the middle of the other more-related 2 (put fm first, so the exclude_ ones are visually aligned).

Comment thread frontend/ui/screensaver.lua Outdated
Comment on lines +457 to +479
if not excluded then
if not ui and G_reader_settings:isTrue("screensaver_hide_cover_in_filemanager") then
excluded = true
elseif G_reader_settings:isTrue("screensaver_exclude_finished_books") and book_finished then
excluded = true
elseif G_reader_settings:isTrue("screensaver_exclude_on_hold_books") and book_on_hold then
excluded = true
end
if excluded then
self.show_message = false
end
else
-- doc_settings:isTrue("exclude_screensaver") does not get rid of the message, so honor it, when not in any of the other cases
if self.show_message then
if not ui and G_reader_settings:isTrue("screensaver_hide_cover_in_filemanager") then
self.show_message = false
elseif G_reader_settings:isTrue("screensaver_exclude_finished_books") and book_finished then
self.show_message = false
elseif G_reader_settings:isTrue("screensaver_exclude_on_hold_books") and book_on_hold then
self.show_message = false
end
end
end -- if not excluded

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.

Looks like these 2 big similar branches can be merged ? (more checks even if already excluded, but it avoids duplicating the whole thing):

            local book_on_hold = book_summary and book_summary.status == "abandoned"
            if not ui and G_reader_settings:isTrue("screensaver_hide_cover_in_filemanager") then
                excluded = true
            elseif G_reader_settings:isTrue("screensaver_exclude_finished_books") and book_finished then
                excluded = true
            elseif G_reader_settings:isTrue("screensaver_exclude_on_hold_books") and book_on_hold then
                excluded = true
            end
            if excluded then
                self.show_message = false
            end

Comment thread frontend/ui/screensaver.lua Outdated
Comment on lines +457 to +461
local exclude_finished_books = G_reader_settings:isTrue("screensaver_exclude_finished_books") and book_finished
local exclude_on_hold_books = G_reader_settings:isTrue("screensaver_exclude_on_hold_books") and book_on_hold
local exclude_books_in_fm = not ui and G_reader_settings:isTrue("screensaver_hide_cover_in_filemanager")

if not excluded 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.

These local variables are badly named:
exclude_finished_books = G_reader_settings:isTrue("screensaver_exclude_finished_books") and book_finished
The G_reader_setting things is plural, but and book_finished have it apply on the current book, so the local var can't be plural.

The blank line is not needed, as the whole section is about the same thing.

And I'm sure you can do shorter than adding 20 lines and you don't need that many branches.

Comment thread frontend/ui/screensaver.lua Outdated
Comment on lines +461 to +466
if not excluded and should_exclude_book then
excluded = true
self.show_message = false
elseif self.show_message and excluded and should_exclude_book then
-- doc_settings:isTrue("exclude_screensaver") does not get rid of the message, check if we should hide it, otherwise we honor it
self.show_message = false

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.

Good for what's above that.
For these 2 branches, it looks to me they are just logically equivalent to one and clearer:

if should_exclude_book then
    excluded = true
    self.show_message = false -- get rid of the message
end

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 hate you ;)

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.

I know - but it warms the heart to hear it. I hate you too :)

@Commodore64user

Commodore64user commented Jan 17, 2025

Copy link
Copy Markdown
Member Author

Instead of having a cover from a book i read three weeks ago, show me these instead...

Edit: slap that 2025.01 on it ;)

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.

FR: Add an option to change screensaver setting depending on last book's status

3 participants