telescope-browser / telescope

browser for the small internet
https://telescope-browser.org
ISC License
43 stars 1 forks source link

Should open web (https) pages and images in configured application or xdg-open #12

Closed linuxcult closed 2 months ago

linuxcult commented 7 months ago

It would be a great feature if you could choose an application to open http(s) links or images in a specified application in the config file and default to xdg-open.

omar-polo commented 7 months ago

What a timing, I just got also an email about this! :)

I agree, it's a quite big omission.

Now the question becomes, should telescope just feed anything to xdg-open or provide more flexibility (or support mailcap files) ?

One annoying thing of having a terminal interface is that you (generally) have to suspend the UI before starting another application, as it can mess out the display. In some cases however, it may be safe to just run the other command in the background. For images at least, I think it would be preferably to run the viewer in the background.

I'm not sure if mailcap would be appropriate for telescope. Off the top of my head I could image something like this for our configuration file

# these don't take over the terminal
open "image/svg+xml" with "inkview" background
open "image/*" with "nsxiv" background

# no background means they take over the terminal
open "http:" with w3m
open "https:" with w3m

# an implicit open "*/*" with "xdg-open" is always loaded.

# maybe also
set default-opener = "my-xdg-open-like-script"

What do you think?

linuxcult commented 7 months ago

Hello Omar, the email you mentioned, was from me too, I'll react separately. :-)

As far as I can tell, the options you mentioned seem to be very good for the config file, but the http:/https: links should at least in my case also be able to get the background option (I use qutebrowser for web links).

I think to open */* with xdg-open seems a sensible default.

omar-polo commented 7 months ago

but the http:/https: links should at least in my case also be able to get the background option

Yes, of course. That was mostly an example of how it could work.

I think to open / with xdg-open seems a sensible default.

Yep, the idea is that the more it works out-of-the-box in a sensible way, the better. The rest of the config would just be for very specific use-cases.

omar-polo commented 3 months ago

Part of this has just been implemented thanks to @ThomasAdam who is working on this. Currently as soon as a download is finished, telescope will prompt the command to open (defaulting to xdg-open) and, upon confirmation, will run it.

This is still WIP and is subject to further changes to the behaviour, but it's already in the main branch.

There's nothing for opening external links yet.

ThomasAdam commented 3 months ago

This has now been implemented via the use of a mailcap file.

If one is not present, then telescope will fallback to using xdg-open.

This will be in the next release of telescope, but any testing you can do from git, @linuxcult would be appreciated.

linuxcult commented 3 months ago

After some tweaking my .mailcap file a little, the image downloads correctly and is opened in my configured qutebrowser.

But there seems to be a problem with my .mailcap file. I get some error when closing telescope:

mailcap: trailing: copiousoutput: skipping... Error with entry: <<text/html>>, line: 1

The problem is that I need this entry for my NeoMutt setup to use elinks to render HTML mails and it seems it insists on this "copiousoutput" option.

Not sure how to circumvent this issue.

EDIT: After commenting out the "image/*" entry in mailcap, telescope opens the file with xdg-open as intended, although the error message concerning the mailcap file persists.

linuxcult commented 3 months ago

Another thing is that there should maybe a config file option to select which filetypes to show automatically. Maybe somebody wants to download PDFs but don't show them.

Otherwise good work so far!

ThomasAdam commented 3 months ago

After some tweaking my .mailcap file a little, the image downloads correctly and is opened in my configured qutebrowser. But there seems to be a problem with my .mailcap file. I get some error when closing telescope: mailcap: trailing: copiousoutput: skipping... Error with entry: <<text/html>>, line:

Can you post your mailcap file, please?

linuxcult commented 3 months ago

Can you post your mailcap file, please?

I think it's pretty basic:

text/html;  elinks -dump %s; nametemplate=%s.html; copiousoutput
application/pdf; /usr/bin/zathura %s
image/*; /usr/bin/qutebrowser %s;
audio/*; /usr/bin/mpv %s;
video/*; /usr/bin/mpv %s;

But I can't do without the "copiousoutput" option in the first line, otherwise my NeoMutt setup breaks for rendering HTML mails.

ThomasAdam commented 3 months ago

Thanks. There's already an open PR on codeberg to fix this.

The it's failing is due to an incorrect assumption about the ordering of fields.

Once that fix is merged and synced here, I'll let you know so you can test it further.

linuxcult commented 3 months ago

I got another strange message but I'm not sure which one belongs to telescope and which one to zathura (pdf viewer):

mailcap: trailing:  copiousoutput: skipping...
Error with entry: <<text/html>>, line: 1

(zathura:4250): dbind-WARNING **: 16:57:44.321: Couldn't connect to accessibility bus: Failed to connect to socket /run/user/977/at-spi/bus_0: Keine Berechtigung
info: Opening plain database via sqlite backend.
warning: sqlite database already exists. Set your database backend to sqlite
telescope: execve failed: Datei oder Verzeichnis nicht gefunden

I'm especcially worried about the "telescope: execve failed" message (Although I don't know what it means)

ThomasAdam commented 3 months ago

Would you mind translating that for me?

linuxcult commented 3 months ago

Oh, yes sorry: telescope: execve failed: file or directory not found

linuxcult commented 3 months ago

For some reason the telescope: execve failed: file or directory not found just vanished when opening pdfs - although I didn't update the code. Maybe a problem on my end. I'm not sure what's changed.

Edit: I think it was a missing ; in my mailcap

linuxcult commented 3 months ago

After pulling down the latest commits and recompiling telescope the error messages concerning "copiousoutput" are gone!

Good job!

omar-polo commented 3 months ago

@linuxcult thanks for testing! I've improved the error message, now instead of "failed to execve" it shows what it tried to execute, so that it will be easier to know if it's a misparsed entry or a typo in the mailcap file.

I also agree we should at least prompt before launching a program to open the download.

linuxcult commented 2 months ago

There is a little bug in the telescope file opening functionality:

If I open for example an image for the first time, it gets displayed fine. But after choosing another image, the first one is displayed again. And once when I opened a pdf as the second file I got a segmentation fault.

ThomasAdam commented 2 months ago

There is a little bug in the telescope file opening functionality:

If I open for example an image for the first time, it gets displayed fine. But after choosing another image, the first one is displayed again. And once when I opened a pdf as the second file I got a segmentation fault.

Indeed there is.

Please may you take a look at the ta/mailcap-fix branch in this repo and let me know if that fixes the issue for you?

It seems to work just fine for me...

linuxcult commented 2 months ago

The ta/mailcap-fix branch seems to fix the issue. All images and pdfs are show in their applications as configured even if I use the 'show' function multiple times.

However, I'm not sure if I tested all usecases.

ThomasAdam commented 2 months ago

Hi @linuxcult

Thank you -- any and all testing is appreciated. The tests still pass, and my own strenuous testing showed it seemed OK.

It was certainly a lot easier to show how things were broken, and having replayed those tests against fix, things seems fine.

So I think this is fixed. This change is also in main now...

ThomasAdam commented 2 months ago

I'm going to close this issue now. Mailcap support is now in the 0.10.0 release.

If there's anything which crops up as a result of mailcap handling, please open a new issue.