[chore] Device abstraction (#6280)

* generic Device:info() function which returns the model

* add Device:canSuspend() and make it true in all devices that have suspend routines and the emulator

* also enable fake poweroff/reboot on the emulator

* add Device.home_dir

* add Device:hasExitOptions() and update menus & comments
pull/6282/head
Martín Fernández 4 years ago committed by GitHub
parent f3489cdd24
commit 2e731dd4dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -681,17 +681,7 @@ function FileManager:goHome()
local home_dir = G_reader_settings:readSetting("home_dir")
if not home_dir or lfs.attributes(home_dir, "mode") ~= "directory" then
-- Try some sane defaults, depending on platform
if Device:isKindle() then
home_dir = "/mnt/us"
elseif Device:isKobo() then
home_dir = "/mnt/onboard"
elseif Device:isPocketBook() then
home_dir = "/mnt/ext1"
elseif Device:isCervantes() then
home_dir = "/mnt/public"
elseif Device:isAndroid() then
home_dir = Device.external_storage()
end
home_dir = Device.home_dir
end
if home_dir then
-- Jump to the first page if we're already home

@ -10,19 +10,7 @@ local _ = require("gettext")
local filemanagerutil = {}
function filemanagerutil.getDefaultDir()
if Device:isAndroid() then
return Device.external_storage()
elseif Device:isCervantes() then
return "/mnt/public"
elseif Device:isKindle() then
return "/mnt/us/documents"
elseif Device:isKobo() then
return "/mnt/onboard"
elseif Device:isRemarkable() then
return "/home/root"
else
return "."
end
return Device.home_dir or "."
end
function filemanagerutil.abbreviate(path)

@ -67,13 +67,15 @@ local Device = Generic:new{
model = android.prop.product,
hasKeys = yes,
hasDPad = no,
hasExitOptions = no,
hasEinkScreen = function() return android.isEink() end,
hasColorScreen = function() return not android.isEink() end,
hasFrontlight = yes,
hasLightLevelFallback = yes,
canRestart = no,
canSuspend = no,
firmware_rev = android.app.activity.sdkVersion,
external_storage = android.getExternalStoragePath,
home_dir = android.getExternalStoragePath(),
display_dpi = android.lib.AConfiguration_getDensity(android.app.config),
isHapticFeedbackEnabled = yes,
hasClipboard = yes,

@ -62,6 +62,7 @@ local Cervantes = Generic:new{
hasWifiManager = yes,
canReboot = yes,
canPowerOff = yes,
home_dir = "/mnt/public",
-- do we support usb mass storage?
canToggleMassStorage = function() return isMassStorageSupported() end,

@ -21,6 +21,7 @@ local Device = {
screen = nil,
screen_dpi_override = nil,
input = nil,
home_dir = nil,
-- For Kobo, wait at least 15 seconds before calling suspend script. Otherwise, suspend might
-- fail and the battery will be drained while we are in screensaver mode
suspend_wait_timeout = 15,
@ -29,6 +30,7 @@ local Device = {
hasKeyboard = no,
hasKeys = no,
hasDPad = no,
hasExitOptions = yes,
hasFewKeys = no,
hasWifiToggle = yes,
hasWifiManager = no,
@ -52,6 +54,7 @@ local Device = {
canToggleMassStorage = no,
canUseWAL = yes, -- requires mmap'ed I/O on the target FS
canRestart = yes,
canSuspend = yes,
canReboot = no,
canPowerOff = no,
@ -279,6 +282,10 @@ function Device:onPowerEvent(ev)
end
end
function Device:info()
return self.model
end
-- Hardware specific method to handle usb plug in event
function Device:usbPlugIn() end

@ -96,6 +96,7 @@ local Kindle = Generic:new{
canHWInvert = yes,
-- NOTE: Newer devices will turn the frontlight off at 0
canTurnFrontlightOff = yes,
home_dir = "/mnt/us/documents",
}
function Kindle:initNetworkManager(NetworkMgr)

@ -47,6 +47,7 @@ local Kobo = Generic:new{
hasNaturalLightMixer = no,
-- HW inversion is generally safe on Kobo, except on a few boards/kernels
canHWInvert = yes,
home_dir = "/mnt/onboard",
}
--- @todo hasKeys for some devices?

@ -63,7 +63,9 @@ local PocketBook = Generic:new{
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = yes,
canSuspend = no,
emu_events_dev = "/dev/shm/emu_events",
home_dir = "/mnt/ext1",
}
-- Make sure the C BB cannot be used on devices with a 24bpp fb

@ -14,6 +14,7 @@ local Remarkable = Generic:new{
isTouchDevice = yes,
hasFrontlight = no,
display_dpi = 226,
home_dir = "/mnt/root",
}
local EV_ABS = 3

@ -80,6 +80,7 @@ local Device = Generic:new{
needsScreenRefreshAfterResume = no,
hasColorScreen = yes,
hasEinkScreen = no,
canSuspend = no,
canOpenLink = getLinkOpener,
openLink = function(self, link)
local enabled, tool = getLinkOpener()
@ -114,6 +115,7 @@ local AppImage = Device:new{
hasMultitouch = no,
hasOTAUpdates = yes,
isDesktop = yes,
home_dir = os.getenv("HOME"),
}
local Emulator = Device:new{
@ -123,11 +125,15 @@ local Emulator = Device:new{
hasFrontlight = yes,
hasWifiToggle = yes,
hasWifiManager = yes,
canPowerOff = yes,
canReboot = yes,
canSuspend = yes,
}
local Linux = Device:new{
model = "Linux",
isDesktop = yes,
home_dir = os.getenv("HOME"),
}
local UbuntuTouch = Device:new{

@ -55,19 +55,14 @@ common_info.report_bug = {
text = _("Report a bug"),
keep_menu_open = true,
callback = function()
local device = Device.model
if Device:isAndroid() then
device = Device:info()
end
UIManager:show(InfoMessage:new{
text = T(_("Please report bugs to \nhttps://github.com/koreader/koreader/issues\n\nVersion:\n%1\n\nDetected device:\n%2"),
version, device),
version, Device:info()),
})
end
}
if Device:isCervantes() or Device:isKindle() or Device:isKobo() then
if Device:canSuspend() then
common_info.sleep = {
text = _("Sleep"),
callback = function()

@ -154,19 +154,18 @@ local order = {
},
plus_menu = {},
exit_menu = {
"restart_koreader",
"restart_koreader", -- if Device:canRestart()
"----------------------------",
"sleep", -- if Device:isKindle() or Device:isKobo()
"poweroff", -- if Device:isKobo()
"reboot", -- if Device:isKobo()
"sleep", -- if Device:canSuspend()
"poweroff", -- if Device:canPowerOff()
"reboot", -- if Device:canReboot()
"----------------------------",
"start_bq",
"start_bq", -- if Device:isCervantes()
"exit",
}
}
if Device:isAndroid() then
if not Device:hasExitOptions() then
order.exit_menu = nil
end
return order

@ -178,18 +178,18 @@ local order = {
"about",
},
exit_menu = {
"restart_koreader",
"restart_koreader", -- if Device:canRestart()
"----------------------------",
"sleep", -- if Device:isKindle() or Device:isKobo()
"poweroff", -- if Device:isKobo()
"reboot", -- if Device:isKobo()
"sleep", -- if Device:canSuspend()
"poweroff", -- if Device:canPowerOff()
"reboot", -- if Device:canReboot()
"----------------------------",
"start_bq",
"start_bq", -- if Device:isCervantes()
"exit",
}
}
if Device:isAndroid() then
if not Device:hasExitOptions() then
order.exit_menu = nil
end

Loading…
Cancel
Save