mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
refatoring: lazy loading of packages
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||
local ButtonDialog = require("ui/widget/buttondialog")
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local DocSettings = require("docsettings")
|
||||
@@ -79,6 +78,7 @@ function FileManagerHistory:addToMainMenu(tab_item_table)
|
||||
end
|
||||
|
||||
function FileManagerHistory:updateItemTable()
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
self.hist = {}
|
||||
|
||||
for f in lfs.dir(history_dir) do
|
||||
|
||||
@@ -3,7 +3,6 @@ local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Menu = require("ui/widget/menu")
|
||||
@@ -498,6 +497,7 @@ function Search:onMenuHold(item)
|
||||
end
|
||||
|
||||
function Search:showresults()
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local menu_container = CenterContainer:new{
|
||||
dimen = Screen:getSize(),
|
||||
}
|
||||
@@ -544,6 +544,7 @@ function Search:showresults()
|
||||
end
|
||||
|
||||
function Search:browse(option,run,chosen)
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local restart_me = false
|
||||
local menu_container = CenterContainer:new{
|
||||
dimen = Screen:getSize(),
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
local AndroidPowerd = require("ui/device/androidpowerd")
|
||||
local KindlePowerD = require("ui/device/kindlepowerd")
|
||||
local isAndroid, android = pcall(require, "android")
|
||||
local KoboPowerD = require("ui/device/kobopowerd")
|
||||
local BasePowerD = require("ui/device/basepowerd")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local Screen = require("ui/device/screen")
|
||||
local util = require("ffi/util")
|
||||
@@ -288,12 +284,16 @@ function Device:getPowerDevice()
|
||||
else
|
||||
local model = self:getModel()
|
||||
if model == "KindleTouch" or model == "KindlePaperWhite" or model == "KindlePaperWhite2" then
|
||||
local KindlePowerD = require("ui/device/kindlepowerd")
|
||||
self.powerd = KindlePowerD:new{model = model}
|
||||
elseif self:isKobo() then
|
||||
local KoboPowerD = require("ui/device/kobopowerd")
|
||||
self.powerd = KoboPowerD:new()
|
||||
elseif self.isAndroid then
|
||||
local AndroidPowerd = require("ui/device/androidpowerd")
|
||||
self.powerd = AndroidPowerd:new()
|
||||
else -- emulated FrontLight
|
||||
local BasePowerD = require("ui/device/basepowerd")
|
||||
self.powerd = BasePowerD:new()
|
||||
end
|
||||
end
|
||||
@@ -322,4 +322,13 @@ function Device:isSpecialOffers()
|
||||
return self.is_special_offers
|
||||
end
|
||||
|
||||
-- FIXME: this is a dirty hack, normally we don't need to get power device this early,
|
||||
-- but Kobo devices somehow may need to init the frontlight module at startup?
|
||||
-- because `kobolight = require("ffi/kobolight")` used to be in the `koreader-base` script
|
||||
-- and run as the first line of koreader script no matter which device you are running on,
|
||||
-- which is utterly ugly. So I refactored it into the `init` method of `kobopowerd` and
|
||||
-- `kobolight` will be init here. It's pretty safe to comment this line for non-kobo devices
|
||||
-- so if kobo users find this line is useless, please don't hesitate to get rid of it.
|
||||
local dummy_powerd = Device:getPowerDevice()
|
||||
|
||||
return Device
|
||||
|
||||
@@ -5,7 +5,7 @@ local KoboPowerD = BasePowerD:new{
|
||||
flIntensity = 20,
|
||||
restore_settings = true,
|
||||
fl = nil,
|
||||
|
||||
|
||||
batt_capacity_file = "/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity",
|
||||
is_charging_file = "/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/charge_now",
|
||||
battCapacity = nil,
|
||||
@@ -13,6 +13,7 @@ local KoboPowerD = BasePowerD:new{
|
||||
}
|
||||
|
||||
function KoboPowerD:init()
|
||||
local kobolight = require("ffi/kobolight")
|
||||
local ok, light = pcall(kobolight.open)
|
||||
if ok then self.fl = light end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!./koreader-base
|
||||
#!./luajit
|
||||
|
||||
require "defaults"
|
||||
pcall(dofile, "defaults.persistent.lua")
|
||||
@@ -100,6 +100,7 @@ local function showusage()
|
||||
return
|
||||
end
|
||||
|
||||
local ARGV = arg
|
||||
local argidx = 1
|
||||
while argidx <= #ARGV do
|
||||
local arg = ARGV[argidx]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!./koreader-base
|
||||
-- widget test utility
|
||||
-- usage: ./luajit util/wtest.lua
|
||||
|
||||
require "defaults"
|
||||
print(package.path)
|
||||
Reference in New Issue
Block a user