bleakgrey / tootle

GTK-based Mastodon client for Linux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Opening images fails silently

wjt opened this issue · comments

What should happen:

I believe that the intended behaviour is: clicking on an image should open it in my system image viewer.

What happened instead:

Nothing visible.

Looking with Bustle I can see that Tootle calls the following portal method:

org.freedesktop.portal.OpenURI.OpenURI('', 'file://25145593432a38bebdd4c16c95.png', @a{sv} {})

Notice the malformed URI which appears to be file:// concatenated to a relative filepath.

If I enter the running Tootle's sandbox I can see that the file (and some others I tried) have been saved to (what Tootle believes to be) my homedir:

bash-5.1$ pwd
/sysroot/home/wjt
bash-5.1$ ls -la
total 176
drwxr-xr-x 4 wjt wjt   160 Apr 22 13:43 .
drwxr-xr-x 3 wjt wjt    60 Apr 22 13:38 ..
-rw------- 1 wjt wjt   148 Apr 22 13:44 .bash_history
drwxr-xr-x 3 wjt wjt    60 Apr 22 13:38 .local
drwxr-xr-x 3 wjt wjt    60 Apr 22 13:38 .var
-rw------- 1 wjt wjt 74723 Apr 22 13:39 10895068861c5a3f8a29cde002.png
-rw------- 1 wjt wjt  5456 Apr 22 13:40 25145593432a38bebdd4c16c95.png
-rw------- 1 wjt wjt 88071 Apr 22 13:39 988507221e4f1676aae6cb9fb.jpg

How to reproduce:

  1. Find a toot with an image
  2. Click the image

Build context:

  • Distro: Endless OS 4.0 (development branch)
  • App version: 1.0.0
  • Build type: Flatpak

Logs:

** Message: 13:46:12.272: Desktop.vala:48: Downloading file: https://files.mastodon.social/cache/media_attachments/files/106/108/691/314/125/982/original/2a38bebdd4c16c95.png...
** Message: 13:46:12.310: Desktop.vala:78: OK: File written to: 25145593432a38bebdd4c16c95.png
** Message: 13:46:12.310: Desktop.vala:11: Opening URI: file://25145593432a38bebdd4c16c95.png

Glancing at the code:

  • open_uri assumes that if a supposed "URI" does not contain a :, then it can be turned into one by prepending file://. This is not true in the case of relative paths. (The precondition is also not true: : is a perfectly valid character in a filename, but /home/wjt/foo:bar.txt is not a URI.) https://github.com/bleakgrey/tootle/blob/master/src/Desktop.vala#L8-L9
  • download attempts to download to the xdg downloads dir. But the Flatpak of Tootle doesn't have access to that. xdg-user-dir DOWNLOADS returns the path to my homedir. I agree with #279 that Tootle should download to cache. It's desirable to me that Tootle can't access all my other downloaded files.

Having similar issue, but instead of failing silently, I get "Error: Operation not supported", despite having sxiv as my default image viewer

You can work around this by granting Tootle access to your home directory.

The path where the file is downloaded becomes truncated to just the file name when the environment variable used isn't available in the sandbox, then the file:// prefix is added and the resulting string is passed to a program outside the sandbox.

As an aside, here's a funny thing you can do once you can open images: Click on an attached image twice, fast enough that your second click is registered before the file has been downloaded. You'll get an error saying that the file couldn't be opened because it exists.

commented

You can work around this by granting Tootle access to your home directory.

In case it helps somebody, (and in case this is not the right way to do it..), I share here the command that helped me do it and did the trick for me :

sudo flatpak override com.github.bleakgrey.tootle --filesystem=home