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

Open with... improvement #11056

Merged
merged 29 commits into from
Nov 5, 2023
Merged

Open with... improvement #11056

merged 29 commits into from
Nov 5, 2023

Conversation

hius07
Copy link
Member

@hius07 hius07 commented Oct 31, 2023

The purpose is to open non-document files by a tap in file browser and file search results.
Currently we have 4 auxiliary (non-document) providers: Image viewer, Text viewer, Text editor plugin, Archive viewer plugin.

Changes:
(1) DocumentRegistry
-a plugin can register itself as an auxiliary provider
-deduplicated code and run

(2) Open with... dialog
-associate a file type with an auxiliary provider
-view the list of providers associated with a file type
-reset the provider associated with a single file

Unchanged:
A single file cannot be associated with an auxiliary provider.
Document providers' standard behaviour.

(3) Archive viewer
-view images in an archive as a multi-page image (useful to view cbz content)

1

2

3


This change is Reviewable

@@ -161,7 +161,7 @@ function FileManagerCollection:showCollDialog()
path = G_reader_settings:readSetting("home_dir"),
select_directory = false,
file_filter = function(file)
return DocumentRegistry:getProviders(file) ~= nil
return DocumentRegistry:hasProvider(file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the behavior the same for normally hidden files with a custom assigned engine and similar edge cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give an example what do you mean.
We add to favorites only documents (ie they have a provider).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mainly meant I assumed it was a line I wrote a few years back, but I see now that it's in something you wrote. ;-)

Copy link
Member

@Frenzie Frenzie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm in principle, not able to test atm though

@hius07
Copy link
Member Author

hius07 commented Oct 31, 2023

Aligned infomessage with type associates.

5

@NiLuJe
Copy link
Member

NiLuJe commented Oct 31, 2023

You can't cache the providers registered from plugins; they reinstantiate on view changes, so you'd be pinning stale objects ;).

(IIRC, that's less of a problem for real Doc* providers, as we either feed it the class, or they're singletons, can't recall and a bit short on time right now).

@hius07
Copy link
Member Author

hius07 commented Oct 31, 2023

Thank you, I understand. I'll change the architecture.

Copy link
Contributor

@poire-z poire-z left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a thorough review (this provider business is a bit too much for me :)), but nothing jumps out. Trusting you.
Just a nitpick.

local util = require("util")

local DocumentRegistry = {
registry = {},
providers = {},
providers_hash = {}, -- hash table of registered providers { provider_key = provider }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providers_hash sounds like it would be a hash value (a string or a number).
It is a Lua hash (not an array) table, ok, but we don't advertize that fact in most of our names :)
So, may be known_providers or provider_names ?

@hius07
Copy link
Member Author

hius07 commented Nov 1, 2023

@pazos, regarding your #9615 and #11001, I do not follow your way:
-because such handlers as Text viewer or Text editor can be used for any file types,
-and to avoid far route via "showReader, then detect non-document, close Reader, reopen FM and finally handle the file".

I think your non-document handlers (plugins?) can be registered as auxiliary provider (see Text editor and Archive viewer here). Then any packet/non-document extension can be associated (manually in Open with... dialog or automatically by the plugin itself) with your aux provider. It will be opened just by a tap in the file browser and in the file search results.
No changes to the core would be required (except your icons in the coverbrowser, but that's another story).

@pazos
Copy link
Member

pazos commented Nov 1, 2023

@pazos, regarding your #9615 and #11001, I do not follow your way: -because such handlers as Text viewer or Text editor can be used for any file types, -and to avoid far route via "showReader, then detect non-document, close Reader, reopen FM and finally handle the file".

I think your non-document handlers (plugins?) can be registered as auxiliary provider (see Text editor and Archive viewer here). Then any packet/non-document extension can be associated (manually in Open with... dialog or automatically by the plugin itself) with your aux provider. It will be opened just by a tap in the file browser and in the file search results. No changes to the core would be required (except your icons in the coverbrowser, but that's another story).

Thanks for the hints. Feel free to do it your way. Mine was a quick attempt. Anyhow, I won't probably have time for that stuff until I'm retired :/

Will close those, while I'm at it :)

Copy link
Member

@NiLuJe NiLuJe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 9 of 14 files at r1, 1 of 2 files at r2, 4 of 4 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @hius07)


frontend/apps/filemanager/filemanagerfilesearcher.lua line 322 at r4 (raw file):

                close_dialog_callback()
                local FileManager = require("apps/filemanager/filemanager")
                FileManager.openFile(self.ui, file, nil, self.close_callback)

Unfamiliar with all this, but I don't follow why close_callback is now limited to running when opening via auxiliary providers?

Code quote:

                close_dialog_callback()
                local FileManager = require("apps/filemanager/filemanager")
                FileManager.openFile(self.ui, file, nil, self.close_callback)

frontend/document/documentregistry.lua line 285 at r4 (raw file):

require("document/djvudocument"):register(DocumentRegistry)
require("document/picdocument"):register(DocumentRegistry)
-- auxuliary built-in

nit: auxiliary ;)


frontend/ui/widget/imageviewer.lua line 863 at r4 (raw file):

            return registry:isImageFile(file)
        end,
        callback = function(file)

You should be able to use a direct assignment here, e.g., callback = ImageViewer.openFile,, the signatures are identical, and the closure doesn't do anything fancy at all ;).


frontend/ui/widget/textviewer.lua line 544 at r4 (raw file):

        callback = function(file)
            TextViewer.openFile(file)
        end,

Ditto ;).

Code quote:

        callback = function(file)
            TextViewer.openFile(file)
        end,

@NiLuJe
Copy link
Member

NiLuJe commented Nov 1, 2023

I also wouldn't mind clearer comments about the fact that none of these aux stuff actually implement the Document* API, and we're just shoe-horning those in DocumentRegistry, which requires more careful consideration in how you actually deal with them to do something useful (e.g., in FileManager.openFile)

@hius07
Copy link
Member Author

hius07 commented Nov 1, 2023

why close_callback is now limited to running when opening via auxiliary providers?

We are in the search results list.
I want to view a file (say, in the Text viewer), keep the list opened and then view the next found file, so on.
When I open a file in Reader, the list should be closed.

function FileManager:openFile(file, provider, doc_caller_callback, aux_caller_callback)

Actually, aux_caller_callback is not yet used anywhere, for the future.

@hius07
Copy link
Member Author

hius07 commented Nov 1, 2023

-- Register an auxiliary (non-document) provider.
-- Aux providers are modules (eg TextViewer) or plugins (eg TextEditor).
-- It does not implement the Document API.
-- For plugins the hash table value does not contain file handler,
-- but only a provider_key (provider.provider) to call the corresponding
-- plugin in FileManager:openFile().
function DocumentRegistry:addAuxProvider(provider)

Copy link
Member

@NiLuJe NiLuJe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r6, 2 of 2 files at r7, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @hius07)

Comment on lines 80 to 82
function InfoMessage:init()
if not self.font_adjusted then
self.face = Font:getFace(self.monospace_font and "infont" or "infofont")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just if not self.face then self.face = ... ?
(Will allow passing a face= when we want something other of infont/infofont?)

@hius07 hius07 merged commit 68aa209 into koreader:master Nov 5, 2023
2 of 4 checks passed
@hius07 hius07 deleted the open-with branch November 5, 2023 05:24
@hius07 hius07 added this to the 2023.11 milestone Nov 5, 2023
NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Jan 19, 2024
NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Jan 19, 2024
The previous check was inlined in the dir walk, so it always saw a
relative path.
Here, it gets an absolute one instead, so act accordingly ;).

Fix koreader#11390
Regression since koreader#11056
NiLuJe added a commit that referenced this pull request Jan 19, 2024
The previous check was inlined in the dir walk, so it always saw a
relative path.
Here, it gets an absolute one instead, so act accordingly ;).

Fix #11390
Regression since #11056
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants