ScreenSaver: allow battery % in screensaver message (#9810)

reviewable/pr9822/r1
melyux 2 years ago committed by GitHub
parent 90f6dd178e
commit 38797498da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -145,6 +145,7 @@ function Screensaver:expandSpecial(message, fallback)
-- %S document series -- %S document series
-- %h time left in chapter -- %h time left in chapter
-- %H time left in document -- %H time left in document
-- %b battery level
if G_reader_settings:hasNot("lastfile") then if G_reader_settings:hasNot("lastfile") then
return fallback return fallback
@ -161,6 +162,7 @@ function Screensaver:expandSpecial(message, fallback)
local series = _("N/A") local series = _("N/A")
local time_left_chapter = _("N/A") local time_left_chapter = _("N/A")
local time_left_document = _("N/A") local time_left_document = _("N/A")
local batt_lvl = _("N/A")
local ReaderUI = require("apps/reader/readerui") local ReaderUI = require("apps/reader/readerui")
local ui = ReaderUI:_getRunningInstance() local ui = ReaderUI:_getRunningInstance()
@ -192,6 +194,14 @@ function Screensaver:expandSpecial(message, fallback)
end end
-- Unable to set time_left_chapter and time_left_document without ReaderUI, so leave N/A -- Unable to set time_left_chapter and time_left_document without ReaderUI, so leave N/A
end end
if Device:hasBattery() then
local powerd = Device:getPowerDevice()
if Device:hasAuxBattery() and powerd:isAuxBatteryConnected() then
batt_lvl = powerd:getCapacity() + powerd:getAuxCapacity()
else
batt_lvl = powerd:getCapacity()
end
end
local replace = { local replace = {
["%c"] = currentpage, ["%c"] = currentpage,
@ -202,6 +212,7 @@ function Screensaver:expandSpecial(message, fallback)
["%S"] = series, ["%S"] = series,
["%h"] = time_left_chapter, ["%h"] = time_left_chapter,
["%H"] = time_left_document, ["%H"] = time_left_document,
["%b"] = batt_lvl,
} }
ret = ret:gsub("(%%%a)", replace) ret = ret:gsub("(%%%a)", replace)
@ -392,7 +403,7 @@ function Screensaver:setMessage()
local input_dialog local input_dialog
input_dialog = InputDialog:new{ input_dialog = InputDialog:new{
title = "Screensaver message", title = "Screensaver message",
description = _("Enter the message to be displayed by the screensaver. The following escape sequences can be used:\n %p percentage read\n %c current page number\n %t total number of pages\n %T title\n %A authors\n %S series\n %h time left in chapter\n %H time left in document"), description = _("Enter the message to be displayed by the screensaver. The following escape sequences can be used:\n %p percentage read\n %c current page number\n %t total number of pages\n %T title\n %A authors\n %S series\n %h time left in chapter\n %H time left in document\n %b battery level"),
input = screensaver_message, input = screensaver_message,
buttons = { buttons = {
{ {

Loading…
Cancel
Save