[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
reviewable/pr6282/r1
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") local home_dir = G_reader_settings:readSetting("home_dir")
if not home_dir or lfs.attributes(home_dir, "mode") ~= "directory" then if not home_dir or lfs.attributes(home_dir, "mode") ~= "directory" then
-- Try some sane defaults, depending on platform -- Try some sane defaults, depending on platform
if Device:isKindle() then home_dir = Device.home_dir
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
end end
if home_dir then if home_dir then
-- Jump to the first page if we're already home -- Jump to the first page if we're already home

@ -10,19 +10,7 @@ local _ = require("gettext")
local filemanagerutil = {} local filemanagerutil = {}
function filemanagerutil.getDefaultDir() function filemanagerutil.getDefaultDir()
if Device:isAndroid() then return Device.home_dir or "."
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
end end
function filemanagerutil.abbreviate(path) function filemanagerutil.abbreviate(path)

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

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

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

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

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

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

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

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

@ -55,19 +55,14 @@ common_info.report_bug = {
text = _("Report a bug"), text = _("Report a bug"),
keep_menu_open = true, keep_menu_open = true,
callback = function() callback = function()
local device = Device.model
if Device:isAndroid() then
device = Device:info()
end
UIManager:show(InfoMessage:new{ 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"), 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 end
} }
if Device:isCervantes() or Device:isKindle() or Device:isKobo() then if Device:canSuspend() then
common_info.sleep = { common_info.sleep = {
text = _("Sleep"), text = _("Sleep"),
callback = function() callback = function()

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

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

Loading…
Cancel
Save