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
Adds time left for chapter and document to the screensaver message options #7897
Conversation
document for screensaver message
As a side note, it's not checked in or part of my change, but I was able to test this on the desktop by changing generic/device.lua to support screensaver, and added onPowerEvent calls to ui/uimanager.lua in the isSDL check within UIManager:Init. However, I wasn't really sure the full ramification of that change, so I left it out. It only displayed the screensaver once per launch so clearly some issues there, but it worked well enough for my local testing of the feature though! :) If there is another way I'm supposed to be able to test the screensaver functionality on PC, I'd love to know the trick! |
Yes, if you want to play around with it on PC you'd need to add supportsScreensaver (or whatever the exact name is) in device to test it. Since we now distinguish the emulator in the SDL device it can probably be added by default. Not quite sure what you mean with the powerevent stuff; that sounds neither desired nor necessary. ;-) |
@@ -1902,6 +1902,7 @@ end | |||
|
|||
function ReaderFooter:getDataFromStatistics(title, pages) | |||
local sec = _("N/A") | |||
-- This is implemented by the Statistics plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a comment along these lines is useful, it should be above over on line 1899. That being said, to me the function above strongly implies it's there in order to be overridden by an actual implementation. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will move it up to 1899. When I first started working through how to get the timing data, I got confused as to how this function was working. Having this comment might save someone else a bit of time finding where the override is, or at least, it would have saved me a bit of time.
text = _("Duration format"), | ||
sub_item_table = { | ||
{ | ||
text_func = function() | ||
local util = require("util") | ||
-- sample text to show 1h23m | ||
local return_text = util.secondsToHClock(4980, true) | ||
return T(_("Modern (%1)"), return_text) | ||
end, | ||
checked_func = function() | ||
return G_reader_settings:readSetting("screensaver_duration_format") == "modern" | ||
end, | ||
callback = function() | ||
G_reader_settings:saveSetting("screensaver_duration_format", "modern") | ||
end, | ||
}, | ||
{ | ||
text_func = function() | ||
local util = require("util") | ||
-- sample text to show 1:23 | ||
local return_text = util.secondsToClock(4980, true) | ||
return T(_("Classic (%1)"), return_text) | ||
end, | ||
checked_func = function() | ||
return G_reader_settings:readSetting("screensaver_duration_format") == "classic" | ||
end, | ||
callback = function() | ||
G_reader_settings:saveSetting("screensaver_duration_format", "classic") | ||
end, | ||
}, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vaguely wondering if it wouldn't be worth merging all of these into a single setting in Date/Time, like what was done for 24h clocks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thought when I originally put this in. It would be nice to have a single user setting to control this, and a new util function that returns the clock format based on that user preference so plug-ins wouldn't need to do this logic. To do it right, I would change the plug-in's that use util.secondsToClock or util.secondsToHClock to use this new function, and move the relevant user settings to a new one within Device -> "time and date". It would touch readerfooter, screensaver, bookstatuswidget, readerprogress and statistics. I would also add unit tests for the new util function.
Does this sound reasonable? If so, let me know if you'd prefer I close this PR while I do that work, since it's going to be a bit larger of a change than I originally planned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds perfect, yeah 👍.
I'd be inclined to prefer delaying the PR as a whole, but no strong feelings on that ;).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest iteration has this ready for review! Please check it out!
frontend/ui/screensaver.lua
Outdated
@@ -150,6 +182,8 @@ local function expandSpecial(message, fallback) | |||
ret = string.gsub(ret, "%%T", title) | |||
ret = string.gsub(ret, "%%A", authors) | |||
ret = string.gsub(ret, "%%S", series) | |||
ret = string.gsub(ret, "%%h", time_left_chapter) | |||
ret = string.gsub(ret, "%%H", time_left_document) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only tangentially related to the PR, but this whole block could be "simplified" with a replacement table.
e.g.,
local rep = { ["%c"] = currentpage, ["%t"] = totalpages, ... }
ret = ret:gsub("(%%%a)", rep)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Wasn't aware of this. Made this change in latest iteration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's kind of my bad for not implementing it this way the first time around, thanks ;).
- Added new utility function to pass to different clock formats - Added unit tests for new utility function - Updated any plugin that called util.secondsToClock to use the new util for different duration format - Add one time migration from footer's duration format - Removed duration format from footer settings Manual tests on desktop and Kobo. Verified all plugins look correct with both modern and classic formats.
frontend/ui/uimanager.lua
Outdated
@@ -377,10 +377,12 @@ function UIManager:init() | |||
elseif Device:isSDL() then | |||
self.event_handlers["Suspend"] = function() | |||
self:_beforeSuspend() | |||
Device:onPowerEvent("Suspend") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the onPowerEvent I referred to in an earlier comment. This function is what is needed to actually kick off the screensaver. Without this, it suspends, but no screensaver appears.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you change the above from Device:isSDL()
to Device:isEmulator()
[1] and it's probably good to go. Needs further testing though (mainly in the regular AppImage target).
[1] That's a fairly recent addition to distinguish the more recent regular desktop AppImage/Debian package from the emulator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I've traced this back to the event handler for Resume not firing when I'd expect on either isSDL or isEmulator (thus not resetting the screen_saver_mode variable, and not showing a screensaver after the first attempt).
What I can do to fix this is to add another event handler in uimanager for Device:isEmulator for the default input event, check if it's in screensaver mode, in which case do a device resume, and then send the input event along.
This seems to work:
elseif Device:isEmulator() then
self.event_handlers["Suspend"] = function()
self:_beforeSuspend()
Device:onPowerEvent("Suspend")
Device:simulateSuspend()
end
self.event_handlers["Resume"] = function()
Device:onPowerEvent("Resume")
Device:simulateResume()
self:_afterResume()
end
**self.event_handlers["__default__"] = function(input_event)
if Device.screen_saver_mode then
self:resume()
end
self:sendEvent(input_event)**
end
Would you prefer I put this in a separate PR at this point? I'm not as confident in my testing of this, though it seems to work fine in my limited tests. I'd also rip out the "Suspend" and "Resume" UI messages which seem pretty useless if the screensaver triggers when expected...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that definitely doesn't sound related and it'd just hold up this one. ;-)
Guess I'm really classic, because these modern durations looks really ugly to me in all these pannels. (But I personally don't mind, I'll stay classic all around :) |
I have to wonder if the modern and classic labels might not be reversed… :-P |
Hah! I'm also someone who will opt to use Classic. Much easier for me to understand. I have it defaulting to use Classic as well for new users, but for existing users the one time migration will use a user's footer's format as their starting default. |
frontend/device/generic/device.lua
Outdated
@@ -410,7 +410,7 @@ function Device:reboot() end | |||
-- Hardware specific method to initialize network manager module | |||
function Device:initNetworkManager() end | |||
|
|||
function Device:supportsScreensaver() return false end | |||
function Device:supportsScreensaver() return true end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unintended leftover from the Emu/SDL shenanigans?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pretty much do the same for the emulator with
function Emulator:supportsScreensaver() return true end
in https://github.com/koreader/koreader/blob/master/frontend/device/sdl/device.lua#L338
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I will remove this since it's not necessary for the PR.
if last_migration_date < 202100629 then | ||
logger.info("Performing one-time migration for 202100629") | ||
|
||
local footer = G_reader_settings:child("footer") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congratulations for being the first actual user of the child
method ^^.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno if it's just me, but on my 2 devices (Kobo, Android phone), where I don't remember having ever seen the modern (2"30') anywhere, I got to see it everywhere after some recent update that must have included this PR/migration. |
FWIW, I started from a fresh setup on the Elipsa (@ 2021.06-40), and it defaults to Classic. |
It seems the footer had it "modern" by default: koreader/frontend/apps/reader/modules/readerfooter.lua Lines 452 to 456 in 96c895d
I think you made some migration/cleanup of readerfooter not too long ago when you transfer the app defaults into the user footer settings - and then this picks that user prefered setting (while it was only a default being propagated, not a user preference :)). Dunno if this is what triggers what I get, and if on a fresh setup, the ordering of this makes it default to "classic" ? |
True, but the new code (post this PR) shouldn't honor that setting remnant anymore, it only checks the "new" consolidated setting: koreader/frontend/apps/reader/modules/readerfooter.lua Lines 1869 to 1877 in b31b772
(And, IIRC, that does indeed default to classic now). |
@poire-z @NiLuJe If modern was the default, and people never changed it or used the time in the footer to notice it, it might have been better to not have handled any migration and just start everyone on Classic to keep consistent throughout more of the UI. Sorry, that didn't occur to me before, but probably would have been a better trade off in migrating. Ideally we can just point people towards the new setting to flip it back, however if folks wanted, we could do a one-time migration and reset everyone back to classic, which anecdotally seems to be the far more popular option anyway. koreader/frontend/ui/data/onetime_migration.lua Lines 266 to 276 in b31b772
|
Oh, right, the upgrade path picked up the "modern" default from the footer, didn't quite think of that ^^. No strong feelings about it, but if we hear about it, why not? |
I also found this an unpleasant surprise. I thought it was my own fault somehow. |
Reset unwanted migration of this setting to "modern" done with #7897.
Adds options for time left for chapter and document to the screensaver message options.
Adds a Duration Format option to the screensaver message option, for Modern (1h23m) or Classic (1:23) styles to be consistent with the status bar options.
Tested on desktop emulator and Kobo Libra H2O device.
Modern:
Classic:
This change is