2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00
koreader/frontend/pluginloader.lua
Hzj_jie 0b29e73e2e BatteryStat plugin and instruction of KoboLight plugin (#2643)
* Start battery stat plugin

* BatteryStat & kobolight

* Several minor improvements

* Remove a useless function

* flush settings

* Some review feedbacks

* Resolve review comments

* Remaining Minutes -> Remaining Hours

* Add dump_file

* typo

* realpath

* realpath on folder

* Remove useless os.time()

* Resolve review comments

* warning

* Add BatteryStat.debugging flag

* treat log as txt

* Minor improvement

* Charging hour should be positive

* Use warn instead of info

* onSuspend in Kobo

* Charging events for kobo and kindle

* More events

* dumpOrLog

* Warnings

* Typo

* More space

* Singleton

* slightly format change

* BatteryStat singleton

* Init

* Remove debugging flag

* sleeping percentage is still negative

* Read settings

* Do not need to change was_suspending and was_charging

* Typo

* Remove debugging flag

* Not charging should happen before suspend

* Resolve review comments

* was_suspend and was_charging should be updated each time in onCallback()
2017-03-23 23:36:15 -07:00

48 lines
1.7 KiB
Lua

local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local PluginLoader = {
plugin_path = "plugins"
}
function PluginLoader:loadPlugins()
if self.plugins then return self.plugins end
self.plugins = {}
for f in lfs.dir(self.plugin_path) do
local path = self.plugin_path.."/"..f
local mode = lfs.attributes(path, "mode")
-- valid koreader plugin directory
if mode == "directory" and f:find(".+%.koplugin$") then
local mainfile = path.."/".."main.lua"
local package_path = package.path
local package_cpath = package.cpath
package.path = path.."/?.lua;"..package.path
package.cpath = path.."/lib/?.so;"..package.cpath
local ok, plugin_module = pcall(dofile, mainfile)
if not ok or not plugin_module then
logger.warn("Error when loading", mainfile, plugin_module)
elseif type(plugin_module.disabled) ~= "boolean" or not plugin_module.disabled then
package.path = package_path
package.cpath = package_cpath
plugin_module.path = path
plugin_module.name = plugin_module.name or path:match("/(.-)%.koplugin")
table.insert(self.plugins, plugin_module)
else
logger.info("Plugin ", mainfile, " has been disabled.")
end
end
end
for _,plugin in ipairs(self.plugins) do
package.path = package.path..";"..plugin.path.."/?.lua"
package.cpath = package.cpath..";"..plugin.path.."/lib/?.so"
end
table.sort(self.plugins, function(v1,v2) return v1.path < v2.path end)
return self.plugins
end
return PluginLoader