Created
April 16, 2025 05:33
-
-
Save hius07/c53bc1ed00e0490cb1a0709c5ed6e735 to your computer and use it in GitHub Desktop.
KOReader userpatch to show info in the file browser title
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- KOReader userpatch to show info in the file browser title | |
local config = { | |
-- indicators, comment out unneeded and set the order | |
"wifi", | |
"memory", -- RAM used, MiB | |
"storage", -- free storage, requires SystemStat plugin | |
"text", | |
"battery", | |
"ctime", | |
-- settings, comment out or set a value | |
text = "KOReader", | |
separator = " | ", -- | • · | |
wifi_show_disabled = true, | |
bold = false, | |
} | |
local BD = require("ui/bidi") | |
local Device = require("device") | |
local FileManager = require("apps/filemanager/filemanager") | |
local NetworkMgr = require("ui/network/manager") | |
local datetime = require("datetime") | |
local Screen = Device.screen | |
local string_func = { | |
text = function() | |
return config.text | |
end, | |
ctime = function() | |
return datetime.secondsToHour(os.time(), G_reader_settings:isTrue("twelve_hour_clock")) | |
end, | |
wifi = function() | |
return NetworkMgr:isWifiOn() and "" or (config.wifi_show_disabled and "") | |
end, | |
battery = function() | |
if Device:hasBattery() then | |
local powerd = Device:getPowerDevice() | |
local batt_lvl = powerd:getCapacity() | |
local batt_symbol = powerd:getBatterySymbol(powerd:isCharged(), powerd:isCharging(), batt_lvl) | |
local text = BD.wrap(batt_symbol) .. BD.wrap(batt_lvl .. "%") | |
if Device:hasAuxBattery() and powerd:isAuxBatteryConnected() then | |
local aux_batt_lvl = powerd:getAuxCapacity() | |
local aux_batt_symbol = powerd:getBatterySymbol(powerd:isAuxCharged(), powerd:isAuxCharging(), aux_batt_lvl) | |
text = text .. " " .. BD.wrap("+") .. BD.wrap(aux_batt_symbol) .. BD.wrap(aux_batt_lvl .. "%") | |
end | |
return text | |
end | |
end, | |
storage = function(self) | |
if self.systemstat then | |
local userpatch = require("userpatch") | |
local SystemStat = userpatch.getUpValue(self.systemstat.addToMainMenu, "SystemStat") | |
if SystemStat then | |
SystemStat.kv_pairs = {} | |
SystemStat:appendStorageInfo() | |
return SystemStat.kv_pairs[3][2] | |
end | |
end | |
end, | |
memory = function() | |
local statm = io.open("/proc/self/statm", "r") | |
if statm then | |
local _, rss = statm:read("*number", "*number") | |
statm:close() | |
return rss and ("%d"):format(math.floor(rss / 256)) | |
end | |
end, | |
} | |
function FileManager:updateTitleBarTitle() | |
local strings = {} | |
for _, item in ipairs(config) do | |
local text = string_func[item](self) | |
if text then | |
table.insert(strings, text) | |
end | |
end | |
self.title_bar:setTitle(table.concat(strings, config.separator or " ")) | |
end | |
FileManager.onNetworkConnected = FileManager.updateTitleBarTitle | |
FileManager.onNetworkDisconnected = FileManager.updateTitleBarTitle | |
FileManager.onCharging = FileManager.updateTitleBarTitle | |
FileManager.onNotCharging = FileManager.updateTitleBarTitle | |
FileManager.onResume = FileManager.updateTitleBarTitle | |
FileManager.onTimeFormatChanged = FileManager.updateTitleBarTitle | |
function FileManager:onPathChanged(path) | |
if not self.title_info_update_time_s then -- first run | |
self.title_info_update_time_s = 0 | |
if config.bold == false then | |
self.title_bar.title_face = self.title_bar.info_text_face | |
self.title_bar.bottom_v_padding = self.title_bar.bottom_v_padding + Screen:scaleBySize(5) | |
self.title_bar:clear() | |
self.title_bar:init() | |
end | |
end | |
local now = os.time() | |
if now > self.title_info_update_time_s + 60 then | |
self.title_info_update_time_s = now | |
self:updateTitleBarTitle() | |
end | |
self:updateTitleBarPath(path) -- subtitle | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a new version with the relevant menu to configure all the settings, choose which items to show, and rearrange the items.