Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Prevent statistics for a folder with documents #10308

Closed
sndwichm4n opened this issue Apr 9, 2023 · 14 comments
Closed

FR: Prevent statistics for a folder with documents #10308

sndwichm4n opened this issue Apr 9, 2023 · 14 comments
Labels
enhancement Plugin User patch available Request is odd, specific, or complicated to do properly - but a user patch is provided

Comments

@sndwichm4n
Copy link

thread at Mobilereads for the backgroundinfos:

https://www.mobileread.com/forums/showthread.php?t=353241

I have a folder structure on my Kindle:

/documents
/documnts/books
/documnts/books/done
/documnts/music

in "/documnts/books" and "/documnts/books/done" are epub books.

In "/dokumnts/music" are (PDF) sheet music to sing. I would like to exclude all data in the folder "/dokumnts/music" from the statistics plugin.

Is there a way to do this?

@jonnyl2
Copy link

jonnyl2 commented Apr 9, 2023

I like this idea; it's also very useful when previewing books from the Downloads directory.

Another thing to consider is to also not record them in the History. However, user preferences may vary on this one.

@sndwichm4n
Copy link
Author

Another thing to consider is to also not record them in the History. However, user preferences may vary on this one.

+1

@poire-z
Copy link
Contributor

poire-z commented Apr 13, 2023

A bit too niche for us to spend time thinking about a UI to allow flagging/managing/displaying such directories - and as you both agree, users may want some things or some others disabled/changed, so again hard to propose via the UI.
So, another good candidate for user patches.

I haven't yet tried user-patching plugins, so I don't know how one could hack the statistics plugin. But one thing is that statistics are disabled for PicDocument (that is: images viewed as a document), and the only check is for document.is_pic being true, which looks like it is not used for anything else.

Something like this may work: 2-fake-is-pic.lua:

local DocumentRegistry = require("document/documentregistry")
local util = require("util")

local orig_openDocument =  DocumentRegistry.openDocument
DocumentRegistry.openDocument = function(self, file, provider)
    local doc = orig_openDocument(self, file, provider)
    if doc and util.stringStartsWith(file, "/koreader_stuff/test/Wikipedia/") then
        doc.is_pic = true
    end
    return doc
end

@poire-z poire-z added the User patch available Request is odd, specific, or complicated to do properly - but a user patch is provided label Apr 13, 2023
@jonnyl2
Copy link

jonnyl2 commented Apr 17, 2023

This seems to work fine, thank you! For my purposes, I just replaced line 7 with

if doc and util.stringStartsWith(file, "/storage/emulated/0/Download/") then

Question: is it also possible to prevent KOReader from creating a Docsettings file when opening a file from a certain folder with a user patch like this? So that it will just use standard settings and not save any changes?

@sndwichm4n
Copy link
Author

I have a look next days. Thank you.

@poire-z
Copy link
Contributor

poire-z commented Apr 17, 2023

is it also possible to prevent KOReader from creating a Docsettings file when opening a file from a certain folder with a user patch like this?

By overridding the function at the bottom of this snippet, knowing what the end of the :open() function at its top does:

new.data.doc_path = doc_path
return new
end
--- Serializes settings and writes them to `metadata.lua`.
function DocSettings:flush(data)

Not tested, but this may work:

local DocSettings = require("docsettings")
local util = require("util")

local orig_flush =  DocSettings.flush
function DocSettings:flush(data)
    if self and self.data and self.data.doc_path and util.stringStartsWith(self.data.doc_path, "/storage/emulated/0/Download/") then
        return
    end
    orig_flush(self, data)
end

@jonnyl2
Copy link

jonnyl2 commented Apr 17, 2023

Thank you, but unfortunately it didn't work. KOReader opens fine but crashes upon exit. It doesn't create a docsettings file (no matter from which directory a file was opened).

This is the crash.log:

--------- beginning of main 04-17 22:18:02.356 E/reader.launche(24731): LoadAppImageStartupCache enabled : 1 04-17 22:18:02.358 E/reader.launche(24731): Not starting debugger since process cannot load the jdwp agent. 04-17 22:18:02.381 E/BehaviorCollectManager(24731): Fail to acquire dataAnalyzerService... 04-17 22:18:02.400 E/AwareLog(24731): AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@b1e5ab0 04-17 22:18:02.411 E/iGraphics(24731): can not load local debug xml 04-17 22:23:23.796 E/reader.launche(26346): LoadAppImageStartupCache enabled : 1 04-17 22:23:23.798 E/reader.launche(26346): Not starting debugger since process cannot load the jdwp agent. 04-17 22:23:23.864 E/BehaviorCollectManager(26346): Fail to acquire dataAnalyzerService... 04-17 22:23:23.916 E/AwareLog(26346): AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@b1e5ab0 04-17 22:23:23.949 E/iGraphics(26346): can not load local debug xml

If you feel like diagnosing the problem then I would welcome that of course. But if not, don't worry about it since this is technically beyond the scope of this ticket.

@poire-z
Copy link
Contributor

poire-z commented Apr 17, 2023

Forgot to add local util = require("util"). Fixed in the snipped above.
(Easier to see real logs on a Kobo, and not that Android useless stuff :)

@jonnyl2
Copy link

jonnyl2 commented Apr 17, 2023

Amazing, it worked! Thank you!

Now if there's also a way to suppress a History record for files in that folder that would be even greater :) :)

@poire-z
Copy link
Contributor

poire-z commented Apr 17, 2023

You may be able to catch that third fish by yourself?:

--- Adds new item (last opened document) to the top of the history list.
-- If item time (ts) is passed, add item to the history list at this time position.
function ReadHistory:addItem(file, ts, no_flush)
if file ~= nil and lfs.attributes(file, "mode") == "file" then

@poire-z
Copy link
Contributor

poire-z commented Apr 18, 2023

No ? :/
Not tested:

local ReadHistory = require("readhistory")
local util = require("util")

local orig_addItem =  ReadHistory.addItem
function ReadHistory:addItem(file, ts, no_flush)
    if file ~= nil and util.stringStartsWith(file, "/storage/emulated/0/Download/") then
        return
    end
    orig_addItem(self, file, ts, no_flush)
end

@jonnyl2
Copy link

jonnyl2 commented Apr 18, 2023

Thank you! I was going to try and figure it out myself, but I needed some more time. I definitely appreciate the education! 👍

Edit: Tested and it works! Thanks again.

@sndwichm4n
Copy link
Author

A bit too niche for us to spend time thinking about a UI to allow flagging/managing/displaying such directories - and as you both agree, users may want some things or some others disabled/changed, so again hard to propose via the UI. So, another good candidate for user patches.

I haven't yet tried user-patching plugins, so I don't know how one could hack the statistics plugin. But one thing is that statistics are disabled for PicDocument (that is: images viewed as a document), and the only check is for document.is_pic being true, which looks like it is not used for anything else.

Something like this may work: 2-fake-is-pic.lua:

local DocumentRegistry = require("document/documentregistry")
local util = require("util")

local orig_openDocument =  DocumentRegistry.openDocument
DocumentRegistry.openDocument = function(self, file, provider)
    local doc = orig_openDocument(self, file, provider)
    if doc and util.stringStartsWith(file, "/koreader_stuff/test/Wikipedia/") then
        doc.is_pic = true
    end
    return doc
end

Thanks it works!!

@frozencircle
Copy link

In newer version (android 2024.01.63), I used these patches, when open a document, it still created new entry at statistics.sqlite3 although didn't update stats of this file (read time, etc...). Could I somehow prevent unused entry be created?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Plugin User patch available Request is odd, specific, or complicated to do properly - but a user patch is provided
Projects
None yet
Development

No branches or pull requests

5 participants