-
Notifications
You must be signed in to change notification settings - Fork 3k
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
osdep/file_dialog: add file dialog for macOS, Windows and Linux #15845
base: master
Are you sure you want to change the base?
Conversation
kasper93
commented
Feb 10, 2025
•
edited
Loading
edited
- - figure out multi file selection or disable it
- - working macOS impl
- - connect more commands (?)
- - add Linux impl
@Akemi: Could you help me with macOS implementation? I tried to put something together to make sure the api will work nicely, but it is missing filters and probably doesn't work at all currently. Also I made objc, but I don't mind replacing it completely with swift impl or anything. |
Currently connected only to |
9f42128
to
38844b3
Compare
sure, i will have a look. give me a few days to think about the implementation details for macOS. from the top of my head, i would probably move the (open) dialog functionality (https://github.com/mpv-player/mpv/blob/master/osdep/mac/menu_bar.swift#L325-L361) out of the menu bar into its own class and make it reusable. also extending its functionality to be usable with your changes. if you don't mind, i would prepare something you can then just (re-)use here. |
I think it's better to add a separate command instead of making loadfile accepting empty url, because the semantics of the A separate command which opens the file dialog in a separate thread, and signals the core after the file is selected would be a better idea. This can reuse the the |
Could you explain the issue, I don't understand. It works perfectly fine.
Why? It already spawns a thread, unlocks core and wait for user selection. Also you can use asynchronous command if you don't want to wait for loadfile selection on calling thread. |
38844b3
to
e1fc1ae
Compare
Added |
84e3947
to
589654d
Compare
Download the artifacts for this pull request: |
Is there a plan to add the url box? rossy/mpv-open-file-dialog#2 https://github.com/v-ji/mpv-open-url-dialog/commit/afff96d785c9a95acdf87041f021c367c099c470 |
I think the support for file dialogs should be added to the |
This will be useful for third-party scripts and greatly increases scalability |
Sorry, I didn't notice So to make this viable, |
Not having synchronized access to mpctx doesn't mean that we cannot use parts of it that are thread-safe, like for example
The behavior of |
2a9bbc3
to
a4c405e
Compare
a4c405e
to
aa64876
Compare
Added |
0438edd
to
64b6db0
Compare
Nah, it doesn't work like this. Put your money where your mouth is. You don't get to talk and back out when you are asked for actual specifics. You are conveniently omitting details in your nicely worded "make it simpler with the script". So I want to see what you really mean. |
I don't think you understand what this is about. Clearly we are not executing or running any files in external programs. But hey, you do you. |
Specifically about this point: I don't think mpv was ever a "commandline" player, despite using this description, and neither did mplayer. mpv and mplayer are interactive media players, and always have been. They're also graphical, at least when playing a video (and ignoring TCT etc). They also have very extensive interactive UI, mpv more so than mplayer, and even while ignoring the OSC - using key bindings, typically with visual feedback of some kind (seek, pause, etc). So in that sense mpv is a "commandline" media player the same way that vim is a "commandline" editor (ignoring its "ed" origins). Both are not. Both are very interactive and not limited to command line options. Now that we've put that out of the way, let's see what we do have in terms of GUI:
And now this PR adds file-selection dialog, which I think no one would disagree that it's typically an essential functionality in media players. The main difference here is that it diverges from the internal-GUI-toolkit paradigm into external kits, which is indeed a very meaningful departure, mainly in the sense of dependencies, but IMO not in the sense of it being a commandline player or not, and it's definitely worth the discussions in this PR. So please don't use "commandline player" as an argument, because mpv never was that, and the file selection dialog is not a meaningful departure from any existing usage paradigm which have been used forever with mpv (OSC). The only real topics at hand IMO are the external dependencies (which to use, how to use, how far are we willing to go, if at all, etc), and the integration of the dialog with commands - mainly whether we should modify commands (and the technical or maintenance hurdles it may have), or only supply a dialog building block while allowing scripts to do the rest, possibly with also a builtin script which could streamline the common use cases while using the dialog as a building block. |
This patchset does fallback to zenity or kdialog if portal is unavailable, which, without reading that CVE or PR code in details, I think does fall into the realm of executing external apps (without user consent?), and therefore potentially with similar vulnerabilities, but I admit to not reading it very carefully, so hopefully I'm wrong. That being said, it would not be the first external executable which mpv uses without asking the user, and I'm thinking mainly yt-dl, but this allows the user to disable it via config or command line (commandline player to the rescue!). But ytdl is enabled by default, and it's likely susceptible to the same class of vulnerabilities. Regardless, adding more external executables increases the risk, and maybe it could be useful to allow disabling the fallback part via some option, if it doesn't already exist (I hope it does exist). |
This consideration makes sense. mpv has many commands that can pass file parameters. In addition to these already implemented, there are various protocols commands (such as |
As far as using a builtin script instead of modifying each command which takes a filename (in addition to allowing any 3rd party script to use it as well), here's an outline of what I had in mind:
And this should allow basically everything which the PR does by modifying commands, but instead by adding one command and one script, e.g. in input.conf:
Additionally, we can consider adding even more functionality than the builtin commands modifications allow, for instance maybe %f or %a is "auto", %s is single item, and %m is multiple items. We could specify a form of adding options to this % thing, e.g. maybe I don't think it would be too bad for the user, and I think both this script and the new |
e50ef06
to
d164a1b
Compare
avih has outlined a script solution, and I think that can be used for zenity/kdialog by implementing them in the script. The difficulty comes if you want zenity/kdialog have 100% feature parity as the
Executing external programs is already a risk factor, especially when it can't be disabled and the user has not specifically requested it, just like that CVE. The impact is also larger than a file manager since it affects all libmpv users.
Sure, mpv is interactive, just like ffplay, which also reacts to key bindings and provides feedbacks in terminal outputs. But it does not work in the same way as what is expected from a "normal" GUI program:
Putting OSC aside, mpv isn't really much different from ffplay, which I don't think is a GUI program as normally defined.
Well, the mpv documentation says:
It points out that mpv has no official GUI, that OSC is not a full GUI and is not meant to be one, that mpv has a lack of expected GUI behavior. At best this can be passed as a GUI on mobile platforms due to the lack of concept of windows, but it's not a GUI in a desktop platform sense. Desktop GUI media players like mpc-hc, vlc, and many mpv frontends typically have popup dialogs for file selection (which is what this PR does), adjusting settings, viewing media info, etc., in the GUI toolkit of the desktop platform. It's a fundamentally different paradigm from having everything as overlays over the video, like video game HUDs.
Agreed. I think this is especially true for libmpv-based GUI frontends, since they would want to use their own dialogs instead.
Thanks for posting this. These are all good ideas to make the script solution as concise as possible. The |
Sure. It's easy to imagine interface that looks nice. The difficult part is to implement it in a way that is maintainable. Because mind I remind you, your main concern is that adding it in C is "a lot" of code. So I want to see how you manage to port it to script with the same feature parity with less code and duplication. I will say it again, I don't see how duplicating and reimplenenting "dialog version" of each command is easier, simpler and less loc than C version.
The mentioned CVE is problematic, because it can exploit external applications, by opening the file based on mime type. The most prominent example would be if a script or bytecode is opened by some interpreter Y. Which is unexpected by the user who run application X. It has nothing to do with our case. We are not passing any user provided payloads/files to the external application. Moreover we are not trying to lookup any application based on mime type. We have hardcoded certain application with all arguments, provided by us and validated. The only variable arg is filter list, but this is passed only to trusted applications. I would appreciate if you stay on topic and not try to side track discussion with some bullshit. Also mind I remind you that kdialog and zenity are literally designed to be called by external applications/scripts. We are not doing anything strange here.
So, you propose to remove subprocess command from mpv? Or ytdl? Or whole scripting support? Because mpv allows to execute arbitrary code in form of lua and js payloads.
Stop it, just stop. It's not relevant to this PR. If you don't like having file dialog in mpv, just say it. Don't dance around it and find some excuses.
You know it is not true. mpv is fully fledged GUI application on Windows. I'm sure you know that... On linux there is no real distinction between GUI and console applications, but you also must know that console applications doesn't generally use Wayland or X11. Adding external file selection dialog will not change that.
And they can. Nothing will prevent them from doing so. |
d164a1b
to
725a50a
Compare
Those are not commands. |
d164a1b
to
322f76e
Compare
If URL is not provided file dialog will be open on supported platforms with selection for files (loadfile) or directories (loaddir).
322f76e
to
c686419
Compare