-
Notifications
You must be signed in to change notification settings - Fork 3.1k
select.lua: add edit-config-file and edit-input-conf #16129
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
base: master
Are you sure you want to change the base?
Conversation
Download the artifacts for this pull request: Windows |
b465f69
to
3629e3c
Compare
options/options.c
Outdated
@@ -556,6 +556,7 @@ static const m_option_t mp_opts[] = { | |||
{"load-select", OPT_BOOL(lua_load_select), .flags = UPDATE_BUILTIN_SCRIPTS}, | |||
{"load-positioning", OPT_BOOL(lua_load_positioning), .flags = UPDATE_BUILTIN_SCRIPTS}, | |||
{"load-commands", OPT_BOOL(lua_load_commands), .flags = UPDATE_BUILTIN_SCRIPTS}, | |||
{"load-utils", OPT_BOOL(lua_load_utils), .flags = UPDATE_BUILTIN_SCRIPTS}, |
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.
Could we convert this to load option to string list? Not related to this PR, just an idea I got rn.
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.
I don't have a strong preference either way
player/lua/utils.lua
Outdated
return | ||
end | ||
|
||
file_handle:write(initial_contents .. "\n") |
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.
do you need \n
here, initial content seems to already have new line.
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.
Yeah it's not needed after I added newlines in the initial contents
cb6fe78
to
e148a55
Compare
misc.lua, instead of utils.lua? It's more like miscellaneous functions than utils to be used by other scripts. |
This might be a name to be easily misunderstood. I thought it was related to the |
options/options.c
Outdated
@@ -990,6 +991,7 @@ static const struct MPOpts mp_default_opts = { | |||
.lua_load_select = true, | |||
.lua_load_positioning = true, | |||
.lua_load_commands = true, | |||
.loa_load_misc = true, |
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.
typo
player/lua/misc.lua
Outdated
local platform = mp.get_property("platform") | ||
local args | ||
if platform == "windows" then | ||
args = {"rundll32", "url.dll,FileProtocolHandler", path} | ||
elseif platform == "darwin" then | ||
args = {"open", path} | ||
else | ||
args = {"xdg-open", path} | ||
end | ||
|
||
local result = mp.command_native({ | ||
name = "subprocess", | ||
playback_only = false, | ||
args = args, | ||
}) | ||
|
||
if result.status < 0 then | ||
show_error("Subprocess error: " .. result.error_string) | ||
elseif result.status > 0 then | ||
show_error(utils.to_string(args) .. " failed with code " .. | ||
result.status) | ||
end |
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.
I think the script is pretty much pointless except this part which can be extracted as a mp.utils
function to "open url with preferred app". The rest can be implemented in select.lua.
I don't think third party scripts have much use for the two script bindings here so this script would create a thread and use resources while doing nothing.
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.
The rest can be implemented in select.lua.
Something like this
Select a config file to edit:
/path/to/mpv.conf
/path/to/input.conf
script config files in ~~/script-opts directory can also be added to the list.
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.
Edit config file and Edit input.conf are going to be added to the context menu (which I implemented months ago and is blocked by this PR), and the idea is to use this for any future miscellaneous functions, e.g. I implemented "seek to timestamp" for the context menu, and we can set prefetch-playlist to true here when the next file is an image like you suggested.
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.
Well I guess it's not too much of a stretch to add Edit config file, input.conf and Seek to timestamp to select.lua (the context menu is still populated by select.lua) and a C option to set prefetch-playlist to avoid adding another script if preferred?
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.
Yes, I think these helper functions can live in the script that uses it unless it's being used by multiple scripts, then it can live in places like defaults.lua which are included instead of using a separate script thread.
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.
Sure I will update the PR. But for the record while I was also worried about many threads before avih challenged me to measure the difference and if you try running mpv with 100 copies of an empty script the CPU usage and performance are exactly the same and there's just an increase of 20MB of memory so it doesn't cause problems in practice.
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.
I didn't look at this closely, but please don't forget that JS and JSON-IPC clients exists too in mpv, and functionality which is available to lua should also be available to any other client too. select.lua covers this by using JSON-based RPC-like thing which is accessible for any client.
e384203
to
d39b909
Compare
Preferably this is implemented in one place, either the C code (as normal mpv command), or in some scripting language which makes it accessible to all clients. Such scripting interfaces already exist: either message-based fire-and-forget (like Also, running a process synchronously is generally highly discouraged, as it completely blocks the event queue of the script. And IMO none of those is worth cluttering defaults.lua/js, which should be kept minimal as the scripting interface of lua and js. |
I removed the Edit: we posted at the same time Edit 2: switched to use |
I think it's OK now at select.lua. And indeed Few notes:
|
It creates mpv.conf and input.conf in the current working directory. This may be expected since
So as discussed on IRC apparently I considered doing something like elseif os.getenv("XDG_CURRENT_DESKTOP") then
args = {"xdg-open", path}
else
-- If the default text editor is a terminal one, xdg-open without a
-- smart backend like gio open or gvfs-open will open the editor in the
-- terminal making it unusable if mpv is running. Open the parent
-- directory to be safe.
args = {"xdg-open", (select(1, utils.split_path(path)))} but this will no longer open the file directly for all window manager users who do have a graphical editor configured, and if you don't all graphical applications opening text files with
I'm not sure that is worth it when the main advantage of this feature is for now users who don't have to create the config files and have no idea what select.lua script-opts are. And it is more convenient if the editor you configured system wise is opened by default.
There's no standard way to specify which file to focus on startup with Linux file managers, and it is slower than opening the files directly.
If calling
It's reasonable to convert it to a command but I'm not willing to figure out how to make it work properly on Windows and macOS, but it seems out of place as a select.lua script message and it's just a few lines that you can copy paste and only useful if you need cross-platform support anyway, else you can |
The user doesn't know it uses
Right. Not great.
And, accorgint to you on IRC:
The main problem for these users is that they don't know where the config file is, together with the fact that it's not created automatically. And the solution to this problem, other than directing them to the docs, is to create the file and show them where it is. This can be done trivially in a menu items, by creating the file and printing its path to the OSD. Opening an editor is an extra, which I agree is convenient, but only if it can be safe, because it IS extra, after we're solved the main problem of creating it and showing where it is.
How do you even know that Don't underestimates how systems of clueless users are configured. This simply has too many boobytraps for an extra beyond the main problem which it solves, even if many users will not encounter them, and I don't think it's worth the hacks which might try to avoid them, and I don't think we can make it part of mpv while we know these boobytraps exist. Solve the main problem, and leave extras to https://github.com/mpv-player/mpv/wiki/User-Scripts . Unrelated, I'm pretty sure it doesn't create |
Just made it return early with
As I explained many times on IRC, configuring By the way, with "can't find" more than the path I'm referring to the fact that even after they find the mpv config directory they don't understand why the config files don't already exist. I see new users asking it often.
xdg-open uses MIME types, not extensions. I indeed don't use Windows and macOS so confirmations from who does are welcome.
There is no point to a user script when the the feature is meant to be discoverable to new users by adding it to mpv's menu.
mpv creates it automatically on startup. |
Yes. And the solution is to create it and show where it is. I said so explicitly. I'm not against these.
I'm not against the menu either, as I mentioned explicitly. By all means make a menu item which creates the file and shows where it is. I only dislike the opening of an unknown external application to edit it, with its associated potential issues. This is the extra which IMO belongs in user-scripts. |
And if you want to be even more useful, copy its path to the clipboard too. |
Not being available to JSON IPC clients is not a good reason to exclude it. They already do not have access to
I do not consider it something that is really needed in defaults.lua/js so I am OK with it being inside select.lua. I was just saying that it is better than a script-message based interface. |
The trend over the years, possibly pushed and implemented to some degree by me, but not only, has been to remove special things which were only available to scripts, and make them generally available to all clients. From what I recall, this includes at least adding the mouse-pos property and make mp.mouse_pos (iirc) a thin wrapper over it, same for utils.get_pid, expand property-string and path, and more. While it's true that any client can reimplement it, it's also true for any lua/js mpv scripts, but if we're making it available to scripts, then I think it would be nice of mpv to not limit it to scripts.
I think duplicating any non trivial logic is not great, and if a trivial message based interface is enough to implement it only in one place, then I don't think it's too bad, even if not ideal. As for where to implement it, you could also say that copy to clipboard is not a core part of player functionality, so the lines can be blurry, though I agree mpv itself is also not ideal for it. But as it stands, it appears that we don't strictly need this functionality to solve the core user problem here (which is mainly creating a config file and showing where it is), and also that it can have some issues specific to this scenario of launching an editor from mpv, so currently I don't see being vital, at least not here. |
player/lua/select.lua
Outdated
@@ -25,6 +25,15 @@ local options = { | |||
|
|||
require "mp.options".read_options(options, nil, function () end) | |||
|
|||
local default_config_file = [[# https://mpv.io/manual/master/#configuration-files | |||
# https://mpv.io/manual/master/#options |
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.
This should refer to current version of installed mpv, not the master
which ma be vastly different
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.
Switched to stable
but we don't seem to have web pages for old versions of the manual.
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.
Actually linking the current version's docs would be bad because the comments stay in the config files forever without getting updated along with mpv.
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.
I think there is no reason for these lines to exist. mpv can already build offiline docs which are accurate no matter what version or git revision is used. There can be another menu entry to open the doc in a browser instead.
Replaced |
Add script bindings to edit mpv.conf and input.conf, and add them to the menu. These are useful as shortcuts, but the main motivation is that new users often ask why they can't find mpv.conf and input.conf, so this creates them if they don't exist.
Add a script with script bindings to edit mpv.conf and input.conf, and add them to the menu. These are useful as shortcuts, but the main motivation is that new users often ask why they can't find mpv.conf and input.conf, so this creates them if they don't exist, also including links to the documentation.
Other future script bindings that don't fit anywhere else can also be added to utils.lua.