-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Mediatypes support #134
Mediatypes support #134
Conversation
Thanks for making this PR. This was actually something I wanted to work on personally, which I indicated by assigning myself in #121. Next time feel free to ask and I'll let you know. But I still appreciate the work here, and thanks for your interest in Amfora! I'll outline some issues I see with the way you've added this below, you're welcome to either make the changes if you agree, or close the PR and I will work on it at some point later. Config
It's important to me that those commands are the default, built-in to the application. So by default when accessing a file the user gets three options (Open, Download, Cancel), and clicking "Open" will use one of these default handlers. On Windows you can use Note that opening in the portal was not one of the options, I'd like to remove that dependency. Limitations
This is something I need to have before releasing and before closing #121, but it's fine if it's not in this PR, happy to add it myself.
That's fine with me, I believe it's what Firefox does as well.
Also fine.
I was thinking about this as well. Unfortunately there doesn't seem to be a good way around this, I'm not interested in nesting a terminal inside Amfora as all the implementations of that I've see don't work very well (slow, no truecolor support, etc). CodeThere are some things in the code I could go over and do a full review, but I'd rather hear your response to this and what you think, as well as see the above changes made, before doing that. Thanks again for your work! |
Thanks for the reply. I completely understand wanting to work on this yourself. I initially was just going to kludge something together for myself since I was really wanting to get around using the portal, but I figured it couldn't hurt to clean it a bit and post what I had. Bad form not introducing myself. Your reply on the config makes sense to me. I'll make changes to this PR. But I'll not be offended in the least if you want to do your own implementation, or rework things. With regards to the terminal apps, a solution I am using myself is: #!/bin/sh
if [ -n "$TMUX" ]; then
tmux new-window sh -c 'viu "$@"; read -p "[Press Enter]"' sh "$@"
else
display "$@"
fi Setting this script as the handler will allow you to stay in the terminal if you are using tmux otherwise it falls back to opening a new window. Cheers 🍻 |
This is how open source is built. Thank you!
Happy to hear it, thanks for understanding. Once you make the changes let me know here, and I'll decide what I want to do. Since you're open to my ideas I suspect I'll probably just end up merging your work.
What is that EDIT: Something I forgot mention in my original reply -- please use "mediatype" everywhere instead of "mimetype", it's the newer and more accurate term. |
I've pushed an update which uses the configuration you specified. I looked into viper and found its unmarshalling ability made things cleaner.
The display command is what you have on Linux (I'm on Linux too). That script is for opening an image. viu is a program to render an image using utf-8 characters.
Noted and done. Thanks! There are a few code smell issues: Location of MediaHandler structI wasn't sure where the MediaHandler struct should go. Currently it is (Ab)using the webbrowser packageInstead of copying from the If it were me, I would be tempted to make the webbrowser package into a general "system open" utility, but I don't want to run off and do my own thing drastically changing stuff (again 😉). And I may have an overdeveloped aversion to code duplication... Old commits left in place.The commits should be squashed. I'm leaving things as-is for the PR review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes! Please see my comments below, in this message and the specific code comments.
Location of MediaHandler struct
I'm fine with it being in config/config.go
, it seems directly related.
(Ab)using the webbrowser package
I'm not really okay with this. I think this (mis)usage can result in strange errors, as well as incorrect logic. I'm not in favour of the accidental $BROWSER
fallback you mention, or that files won't open on *nix systems if there's no Xorg or Wayland display server.
I would be tempted to make the webbrowser package into a general "system open" utility
I would prefer something like this. But leave the existing webbrowser package in place, as it already has some specific code that I'd rather not shift elsewhere. It should be simple enough to copy webbrowser/
into a new folder and just remove the stuff that doesn't apply, and change the package name.
The commits should be squashed. I'm leaving things as-is for the PR review.
Thank you, it's helpful to have to the full history. I will squash the commits for merging.
Co-authored-by: makeworld <25111343+makeworld-the-better-one@users.noreply.github.com>
Makes sense.
I think that if a user does not have a display server running, then there is not going to be a way to determine the system default viewer. The xdg-open man page says:
I think the best course of action for when there is no display server is to display an error dialog instructing the user to add their own default |
Aha you're totally right, lol. I still think this should be a separate package because of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some small changes, I think this is almost ready to go! Thanks for this.
I don't want this in the upcoming v1.7.0 release though, so I might leave this PR open, or merge it into a different branch. It should be in v1.8.0.
Co-authored-by: makeworld <25111343+makeworld-the-better-one@users.noreply.github.com>
OK. The CI checks have passed, and I think I got all of your requests in. 🍻 |
Alright this looks done, thank you! I'll merge it into the new |
This is a partial solution to #121. It uses a slightly different configuration syntax than the one proposed. It looks like this:
It leaves the mozz.us portal as the default, but it is trivial for a Linux user to add a
*/*
handler forxdg-open
. On mac I think plainopen
works. I don't know about Windows though.Limitations
There are a handful of limitations with this implementation that I want to point out: