soupslurpr / BeauTyXT

A beautiful, private, secure, and minimalistic Text, Markdown, and Typst editor.
https://beautyxt.app
ISC License
103 stars 7 forks source link

Use an isolatedProcess service for calling Rust functions from TypstProjectViewModel #128

Closed soupslurpr closed 10 months ago

soupslurpr commented 11 months ago

This will enhance security.

https://developer.android.com/guide/topics/manifest/service-element#:~:text=element%27s%20icon%20attribute.-,android%3AisolatedProcess,-If%20set%20to

Last time I tried, Typst seemed to need access to /tmp but couldn't (due to being in isolatedProcess I presume) and it failed with a JNA error.

soupslurpr commented 10 months ago

Did some tests, passing file descriptors (and temp_dir which isn't used anywhere just relevant) only works without isolatedProcess.

So I don't think doing this would be practical as it would require rewriting most of the Typst integration to not use file descriptors and instead accept/return Strings and Vec (which is what the Rust library bits for plain text and markdown do). Also handle writing to the files from the Kotlin side instead since the Rust side only accepts and returns stuff and can't write it itself as passing file descriptors doesn't work.

If anyone knows of some other way or thing I am missing, please comment here.

I'm looking into the solution I proposed...

soupslurpr commented 10 months ago

Never mind, it is possible but that doesn't mean it should be implemented. It would mean that all the files in a folder would have to be loaded into memory twice instead of the current way of loading files as it needs them.

Would be cool if isolated process services could be granted permissions so I could just do that but oh well...

soupslurpr commented 10 months ago

Wait never mind (again lol), it seems it can access file descriptors if I pass a ParcelFileDescriptor and detatch it in the isolatedProcess service before passing the file descriptor to Rust.

soupslurpr commented 10 months ago

Completed in https://github.com/soupslurpr/BeauTyXT/commit/e9cee7814225c89b09c6258a79912419a1c28493

:D