mirror of
https://github.com/koreader/koreader
synced 2024-11-18 03:25:46 +00:00
SDL: use platform as model for desktop computers, report battery if available
This commit is contained in:
parent
94c0d7854f
commit
ca21d1401a
@ -311,7 +311,7 @@ function ReaderFooter:init()
|
||||
all_at_once = false,
|
||||
reclaim_height = false,
|
||||
toc_markers = true,
|
||||
battery = not Device:isDesktop(),
|
||||
battery = Device:hasBattery(),
|
||||
time = true,
|
||||
page_progress = true,
|
||||
pages_left = true,
|
||||
@ -338,7 +338,7 @@ function ReaderFooter:init()
|
||||
if not Device:hasFrontlight() then
|
||||
MODE.frontlight = nil
|
||||
end
|
||||
if Device:isDesktop() then
|
||||
if not Device:hasBattery() then
|
||||
MODE.battery = nil
|
||||
end
|
||||
|
||||
@ -1609,7 +1609,7 @@ function ReaderFooter:addToMainMenu(menu_items)
|
||||
table.insert(sub_items, getMinibarOption("page_progress"))
|
||||
table.insert(sub_items, getMinibarOption("time"))
|
||||
table.insert(sub_items, getMinibarOption("pages_left"))
|
||||
if not Device:isDesktop() then
|
||||
if Device:hasBattery() then
|
||||
table.insert(sub_items, getMinibarOption("battery"))
|
||||
end
|
||||
table.insert(sub_items, getMinibarOption("percentage"))
|
||||
|
@ -28,6 +28,7 @@ local Device = {
|
||||
suspend_wait_timeout = 15,
|
||||
|
||||
-- hardware feature tests: (these are functions!)
|
||||
hasBattery = yes,
|
||||
hasKeyboard = no,
|
||||
hasKeys = no,
|
||||
hasDPad = no,
|
||||
|
@ -1,5 +1,6 @@
|
||||
local Event = require("ui/event")
|
||||
local Generic = require("device/generic/device")
|
||||
local SDL = require("ffi/SDL2_0")
|
||||
local logger = require("logger")
|
||||
|
||||
local function yes() return true end
|
||||
@ -51,6 +52,7 @@ local Device = Generic:new{
|
||||
model = "SDL",
|
||||
isSDL = yes,
|
||||
home_dir = os.getenv("HOME"),
|
||||
hasBattery = SDL.getPowerInfo(),
|
||||
hasKeyboard = yes,
|
||||
hasKeys = yes,
|
||||
hasDPad = yes,
|
||||
@ -96,9 +98,15 @@ local AppImage = Device:new{
|
||||
isDesktop = yes,
|
||||
}
|
||||
|
||||
local Desktop = Device:new{
|
||||
model = SDL.getPlatform(),
|
||||
isDesktop = yes,
|
||||
}
|
||||
|
||||
local Emulator = Device:new{
|
||||
model = "Emulator",
|
||||
isEmulator = yes,
|
||||
hasBattery = yes,
|
||||
hasEinkScreen = yes,
|
||||
hasFrontlight = yes,
|
||||
hasWifiToggle = yes,
|
||||
@ -108,16 +116,6 @@ local Emulator = Device:new{
|
||||
canSuspend = yes,
|
||||
}
|
||||
|
||||
local Linux = Device:new{
|
||||
model = "Linux",
|
||||
isDesktop = yes,
|
||||
}
|
||||
|
||||
local Mac = Device:new{
|
||||
model = "Mac",
|
||||
isDesktop = yes,
|
||||
}
|
||||
|
||||
local UbuntuTouch = Device:new{
|
||||
model = "UbuntuTouch",
|
||||
hasFrontlight = yes,
|
||||
@ -144,6 +142,7 @@ function Device:init()
|
||||
|
||||
self.hasClipboard = yes
|
||||
self.screen = require("ffi/framebuffer_SDL2_0"):new{device = self, debug = logger.dbg}
|
||||
self.powerd = require("device/sdl/powerd"):new{device = self}
|
||||
|
||||
local ok, re = pcall(self.screen.setWindowIcon, self.screen, "resources/koreader.png")
|
||||
if not ok then logger.warn(re) end
|
||||
@ -334,15 +333,13 @@ function Emulator:initNetworkManager(NetworkMgr)
|
||||
end
|
||||
end
|
||||
|
||||
io.write("Starting SDL in " .. SDL.getBasePath() .. "\n")
|
||||
|
||||
-------------- device probe ------------
|
||||
if os.getenv("APPIMAGE") then
|
||||
return AppImage
|
||||
elseif os.getenv("KO_MULTIUSER") then
|
||||
if jit.os == "OSX" then
|
||||
return Mac
|
||||
else
|
||||
return Linux
|
||||
end
|
||||
return Desktop
|
||||
elseif os.getenv("UBUNTU_APPLICATION_ISOLATION") then
|
||||
return UbuntuTouch
|
||||
else
|
||||
|
19
frontend/device/sdl/powerd.lua
Normal file
19
frontend/device/sdl/powerd.lua
Normal file
@ -0,0 +1,19 @@
|
||||
local BasePowerD = require("device/generic/powerd")
|
||||
local SDL = require("ffi/SDL2_0")
|
||||
|
||||
local SDLPowerD = BasePowerD:new{}
|
||||
|
||||
function SDLPowerD:getCapacityHW()
|
||||
local _, _, _, percent = SDL.getPowerInfo()
|
||||
-- never return negative values, since tests rely on battery being 0%
|
||||
if percent == -1 then return 0 end
|
||||
return percent
|
||||
end
|
||||
|
||||
function SDLPowerD:isChargingHW()
|
||||
local ok, charging = SDL.getPowerInfo()
|
||||
if ok then return charging end
|
||||
return false
|
||||
end
|
||||
|
||||
return SDLPowerD
|
@ -663,7 +663,7 @@ function TouchMenu:updateItems()
|
||||
batt_symbol = ""
|
||||
end
|
||||
end
|
||||
if not Device:isDesktop() then
|
||||
if Device:hasBattery() then
|
||||
time_info_txt = BD.wrap(time_info_txt) .. " " .. BD.wrap("⌁") .. BD.wrap(batt_symbol) .. BD.wrap(batt_lvl .. "%")
|
||||
end
|
||||
self.time_info:setText(time_info_txt)
|
||||
|
Loading…
Reference in New Issue
Block a user