Pocketbook: File handling OS integration (#6617)

* Show opened file in task manager
* Remember file to open on power-off
* Perform file associations
reviewable/pr6620/r1
ezdiy 4 years ago committed by GitHub
parent 426f7b5ddc
commit c9a339ead0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -257,7 +257,6 @@ pbupdate: all
cp $(POCKETBOOK_DIR)/koreader.app $(INSTALL_DIR)/applications
cp $(POCKETBOOK_DIR)/koreader.app $(INSTALL_DIR)/system/bin
cp $(POCKETBOOK_DIR)/extensions.cfg $(INSTALL_DIR)/system/config
cp -rfL $(INSTALL_DIR)/koreader $(INSTALL_DIR)/applications
# create new package
cd $(INSTALL_DIR) && \

@ -583,6 +583,7 @@ function ReaderUI:doShowReader(file, provider)
local _, filename = util.splitFilePathName(file)
Screen:setWindowTitle(filename)
end
Device:notifyBookState(title, document)
UIManager:show(reader)
_running_instance = reader
@ -692,6 +693,7 @@ end
function ReaderUI:onClose(full_refresh)
logger.dbg("closing reader")
Device:notifyBookState(nil, nil)
if full_refresh == nil then
full_refresh = true
end

@ -307,6 +307,9 @@ function Device:info()
return self.model
end
-- Hardware specific method to track opened/closed books (nil on book close)
function Device:notifyBookState(title, document) end
-- Hardware specific method for UI to signal allowed/disallowed standby.
-- The device is allowed to enter standby only from within waitForEvents,
-- and only if allowed state is true at the time of waitForEvents() invocation.

@ -17,6 +17,8 @@ _G.POCKETBOOK_FFI = true
local function yes() return true end
local function no() return false end
local ext_path = "/mnt/ext1/system/config/extensions.cfg"
local app_name = "koreader.app"
local PocketBook = Generic:new{
model = "PocketBook",
@ -135,6 +137,18 @@ function PocketBook:init()
Generic.init(self)
end
function PocketBook:notifyBookState(title, document)
local fn = document and document.file or nil
logger.dbg("Notify book state", title or "[nil]", fn or "[nil]")
os.remove("/tmp/.current")
if fn then
local fo = io.open("/tmp/.current", "w+")
fo:write(fn)
fo:close()
end
inkview.SetSubtaskInfo(inkview.GetCurrentTask(), 0, title and (title .. " - koreader") or "koreader", fn)
end
function PocketBook:setDateTime(year, month, day, hour, min, sec)
if hour == nil or min == nil then return true end
-- If the device is rooted, we might actually have a fighting chance to change os clock.
@ -154,6 +168,44 @@ function PocketBook:setDateTime(year, month, day, hour, min, sec)
end
end
-- Predicate, so no self
function PocketBook.canAssociateFileExtensions()
local f = io.open(ext_path, "r")
if not f then return true end
local l = f:read("*line")
f:close()
if l and not l:match("^#koreader") then
return false
end
return true
end
function PocketBook:associateFileExtensions(assoc)
-- First load the system-wide table, from which we'll snoop file types and icons
local info = {}
for l in io.lines("/ebrmain/config/extensions.cfg") do
local m = { l:match("^([^:]*):([^:]*):([^:]*):([^:]*):(.*)") }
info[m[1]] = m
end
local res = {"#koreader"}
for k,v in pairs(assoc) do
local t = info[k]
if t then
-- A system entry exists, so just change app, and reuse the rest
t[4] = app_name
else
-- Doesn't exist, so hallucinate up something
-- TBD: We have document opener in 'v', maybe consult mime in there?
local bn = k:match("%a+"):upper()
t = { k, '@' .. bn .. '_file', "1", app_name, "ICON_" .. bn }
end
table.insert(res, table.concat(t, ":"))
end
local out = io.open(ext_path, "w+")
out:write(table.concat(res, "\n"))
out:close()
end
function PocketBook:setAutoStandby(isAllowed)
inkview.iv_sleepmode(isAllowed and 1 or 0)
end

@ -1,10 +0,0 @@
pdf:@PDF_file:1:koreader.app:ICON_PDF
djvu:@DJVU_file:1:koreader.app:ICON_DJVU
epub:@EPUB_file:1:koreader.app:ICON_EPUB
fb2:@FB2_file:1:koreader.app:ICON_FB2
mobi:@MOBI_file:1:koreader.app:ICON_MOBI
zip:@ZIP_file:1:koreader.app:ICON_ZIP
cbz:@ZIP_file:1:koreader.app:ICON_ZIP
Loading…
Cancel
Save