summaryrefslogtreecommitdiffstats
path: root/player/javascript
Commit message (Collapse)AuthorAgeFilesLines
* js: complex key-binding: send also key_textAvi Halachmi (:avih)2024-02-091-4/+5
| | | | | | | This is doumented and has been part of the table in lua, but until now not in the JS object. Fixes #13448
* console.lua: style log lines in the terminalGuido Cella2024-01-141-3/+6
| | | | | | | | | | When running the console in the terminal, style log lines with the same escape sequences as msg.c. mp.input can also specify terminal escape sequences, e.g. a script to select a playlist entry can invert the color of the selection. Also add a missing newline to help's error message.
* scripting: add mp.inputGuido Cella2024-01-131-0/+47
| | | | This lets scripts get textual input from the user using console.lua.
* player: remove shared-script-properties propertyDudemanguy2023-11-221-22/+0
| | | | | | | | | | | | This property was never encouraged. The manual even stated that "You should avoid using it, unless you absolutely have to." Since we now have user-data which is superior in every single way and replaces this, delete this property. The manual also has threatened people for years with the line "It's a makeshift solution which could go away any time (for example, when a better solution becomes available)." We were nice and deprecated it in 1d00aee8e191c9689a20e67e3d6dfd2af6ad2588 for a while to give script authors some time to update. Let's remove it for good now.
* build: remove outdated generated directoryDudemanguy2023-07-311-0/+6
| | | | | | | | | | | | | | | | This only existed as essentially a workaround for meson's behavior and to maintain compatibility with the waf build. Since waf put everything in a generated subdirectory, we had to put make a subdirectory called "generated" in the source for meson so stuff could go to the right place. Well now we don't need to do that anymore. Move the meson.build files around so they go in the appropriate place in the subdirectory of the source tree and change the paths of the headers accordingly. A couple of important things to note. 1. mpv.com now gets made in build/player/mpv.com (necessary because of a meson limitation) 2. The macos icon generation path is shortened to TOOLS/osxbundle/icon.icns.inc.
* lua/js: remove user-data helpersAvi Halachmi (:avih)2023-01-291-24/+0
| | | | | | | | | | | | | | | This reverts: 3fb4140c lua/defaults: add user_data helpers 68a20e7a javascript/defaults: add user_data helpers 00510379 lua/js: fix user_data_del util function As well as the lua/js parts of: 3ec2a098 docs: document new user-data property user-data and its sub-properties can be set/get/observed/deleted via the standard properties interface, so there's no need for additional helpers specific to user-data, which only added maintenance burden.
* lua/js: fix user_data_del util functionrcombs2023-01-281-1/+1
|
* javascript/defaults: add user_data helpersrcombs2023-01-281-0/+24
|
* js: key bindings: ensure priorities for same-key - againAvi Halachmi (:avih)2022-06-231-1/+1
| | | | | | | | | | | | Commit 7f4841ff sorted the bindings so that if the same key was bound more than once, then the newest binding takes priority (sorted last). However, it got the comparison function wrong, which means the result of the sort depended on the algorithm and not on the actual data, so the priority for keys with more than one binding was still arbitraty. Fix the sort function, and finally ensure that later binding acutally override earlier bindings of the same key.
* js: utils.get_user_path: make wrapper of expand-pathAvi Halachmi (:avih)2022-02-041-0/+2
| | | | | | | | When utils.get_user_path was added, the expand-path command didn't exist. Now it does, so remove the C code, make it a trivial wrapper. Keep this function for backward compat to not break scripts, but technically it's not required anymore.
* js: ~~/init.js: use mp.find_config_fileAvi Halachmi (:avih)2021-11-011-9/+5
| | | | | | | | | | | | The problem with the previous code - which used mp.get_user_path, is that it returns a path even with --no-config, and even if the file doesn't exist. This is why we tested the "config" property, and also used mp.utils.file_info to check that the file exists. mp.find_config_file doesn't return a path with no-cofig and doesn't return a path if the file doesn't exists. It's simpler and better.
* js: custom-init: use ~~/init.js instead of ~~/.init.js (dot)Avi Halachmi (:avih)2021-10-191-6/+10
| | | | | | | | | | | | | | | | | | | | mpv doesn't have other dot files in its config dir, and it also shouldn't be "invisible". The new name ~~/init.js now replaces ~~/.init.js While mpv usually deprecates things before outright removing them, in this case the old (dot) name is replaced without deprecation: - It's a bad idea to execute hidden scripts, even if at a config dir, and we don't want to do that for the next release cycle too. - We warn if the old (dot) name exists and the new name doesn't, which should be reasonably visible for affected users. - It's likely niche enough to not cause too much pain. If for some reason both names are needed, e.g. when using also an old mpv versions, then the old name could be symlinked to the new one, or simply have one line: `require("~~/init")` to load the new name, while a new mpv version will load (only) the new name without warning.
* js: custom init: ignore ~~/.init.js with --no-configAvi Halachmi (:avih)2021-10-121-1/+4
| | | | | | The custom init script should be considered a configuration file, and as such it should be ignored when the user wants vanilla mpv - and now it is ignored with --no-config.
* js: custom init (~~/.init.js): fail loudly on errorsAvi Halachmi (:avih)2021-09-301-3/+3
| | | | | | | | | | | | Previously, loading ~~/.init.js was inside a try block, in order to quietly ignore errors if the file doesn't exist. However, that also prevented any real errors from showing up even when the file does exist, and the script continued as if everything is OK, while in fact the custom init script didn't complete correctly. Now we first check if the file exists, and then load it without try/catch, so that any error shows up normally (and abort the script).
* js: key bindings: ensure priorities for same-key bindingsAvi Halachmi (:avih)2021-07-211-4/+14
| | | | | | | | | | | | | | | | | | Previously, if a script bound the same key more than once to different functions (without removing the older bindings first), then pressing the key triggered any of the bound functions arbitrarily[1]. Now the newest binding for the same key is always the active one. If the newest binding is then removed - the second-newest will become active, etc. (same mechanism as before, except that the active key was not always the newest). [1] The order was implementation-defined, however `for (name in obj)' happens to iterate. With mujs that's currently alhabetic order, and name is from mp.add_[forced_]key_binding(key, name...) or generated internally if name is not provided. So a binding with higher alphabetic `name' value had priority over lower name value.
* js: idle-observers: minor performance improvementAvi Halachmi (:avih)2021-06-221-1/+1
| | | | | | The idle-observers block has at least 3 function calls, and it was entered every time the script went into idle, however, we can save these calls by checking first that there are indeed such observers.
* js: add mp.utils.append_fileAvi Halachmi (:avih)2021-06-131-0/+2
| | | | | Also, for consistency with other APIs, mp.utils.{write,append}_file now return true on success (and still throw on any error).
* scripting (lua/js): utils.getpid: make wrapper of pid propertyAvi Halachmi (:avih)2021-05-011-0/+1
| | | | | | | | | We now have at least 3 scripting APIs which are trivial wrappers around properties: mp.get_mouse_pos, utils.getcwd, utils.getpid. After some discussion on IRC it was decided that it's easier for us to maintain them as trivial wrappers than to deprecate them and inflict pain on users and script authors, so currently no plan to deprecate.
* lua/js: mp.get_mouse_pos: use the mouse-pos propertyAvi Halachmi (:avih)2020-11-161-0/+1
| | | | | | | mp.get_mouse_pos() is undocumented and is no longer required - the property can be used officially by any client now, however, osc.lua uses it, and also some user scripts learnt to rely on it, so we keep it - as a trivial wrapper around the new mouse-pos property.
* js: hooks: allow deferred continuation (match d0ab562b)Avi Halachmi (:avih)2020-08-071-2/+9
| | | | | | | | | | The callback now gets an object argument with defer/cont functions. Like the lua code, the behavior is that each hook event allows at most one continue, but nothing enforces the order of continuations if more hook events arrive before prior ones were continued - which is possible now with the defer option, but wasn't possible before (continuation was synchronous from the hook event handler).
* js: mp.set_osd_ass: ignore identical inputs (match ccbb8b1c)Avi Halachmi (:avih)2020-05-101-0/+5
|
* js: osd-overlay update: return the command result (match 7a76b577)Avi Halachmi (:avih)2020-03-071-2/+1
| | | | Currently only useful for the new 'compute_bounds' command key.
* js: osd-overlay update: support arbitrary key namesAvi Halachmi (:avih)2020-03-071-9/+11
| | | | | | | | | | | | | | | | | | | | Until now the 'update' method used mp.command_native with a hardcoded list of key names. Change it to use whatever keys the user set to this object, so that we can remain oblivious to new keys which 'osd-overlay' may support. This is how the lua code did it from the begining. We didn't, and now we pay the price. Note: could be implemented either as we have now (clone `this` excluding the methods) or by moving the methods up the prototype chain (i.e. class methods) so they don't get enumerated and use `this` as the command object itself. However, in the latter approach we'll have to save the values which we change (name, res_x, res_y) and restore them after the command, so it's simpler to just clone `this`.
* js: require: directory-scripts: first look at <dir>/modules/Avi Halachmi (:avih)2020-02-071-0/+3
| | | | | Also, add the function mp.get_script_directory() to let scripts know if they're loaded as a directory and where.
* js: require: don't use ~~/scripts/modules.js/Avi Halachmi (:avih)2020-02-071-1/+6
| | | | | | | | | Directories inside ~~/scripts/ are now loaded as scripts, so don't use it also for modules. Now there are no default module paths. To compensate, we now try to run ~~/.init.js right after defaults.js, so the user may extend the js init procedure via this script, e.g. for adding default paths to mp.module_paths .
* js: use osd-dimentions for mp.get_osd_{size,margins}Avi Halachmi (:avih)2020-01-081-4/+7
| | | | | | | | | | | This matches lua's 11b9315b but with the lagacy field names which the js code used previously. Currently the property always returns an object (with dummy/last/null field values if there are no dimensions), but the code is ready for a future case where it might return null if there are no dimensions - at which case it will forward the null, breaking backward compatibility for a better API.
* js: support mp.create_osd_overlay (match 07287262)Avi Halachmi (:avih)2019-12-231-0/+53
| | | | | The legacy mp.set_osd_ass(...) is still supported (but also still undocumented) as a wrapper for the new mp.create_osd_overlay(...).
* js: batch key bindings updates (match 96932fe7)Avi Halachmi (:avih)2019-12-231-3/+12
| | | | | | | Implemented using one-time idle observer (i.e. setTimeout), to avoid additional function call(back) every time the event loop enters idle. The lua mp.flush_key_bindings() is also available, also undocumented.
* js: read_options: on_update: don't re-read the config fileAvi Halachmi (:avih)2019-12-221-3/+3
| | | | | | | | | | | | | Now that 00af718a made the lua read_options behavior much more similar to the js behavior, the main difference was that lua does not re-read the config file at on_update (but it does re-apply its stored content) while js did re-read it. Now the js on_update also does not re-read the config file and instead applies its stored original content. This is slightly hacky by adding an undocumented optional 4th argument to read_options which allows overriding the config file content.
* js: read_options: support on_update (match 478a321d)Avi Halachmi (:avih)2019-12-211-2/+16
| | | | | | | | | | | | | This is a bit different than the lua code: on script-opts change it simply re-applies the conf-file and script-opts to the options object, and if this results in any changed value at options then on_update is called with the changelist as argument. This allows a value to revert back to the conf-file value if the matching script-opts key had a different value and then got deleted. It also guarantees to call back whenever the options object is modified, which the lua code doesn't do (e.g. if the caller changed a value and the observer changed it back - it won't detect a change).
* js: support shared script properties (match 7e4819e7)Avi Halachmi (:avih)2019-12-191-0/+22
|
* js: require: allow custom module search paths via mp.module_pathsAvi Halachmi (:avih)2019-12-191-4/+10
|
* js: mp.add_key_binding: allow false-y name (match 311cc5b)Avi Halachmi (:avih)2019-11-301-1/+3
| | | | | This is in addition to the allowed omission of name and/or flags (as documented).
* js: complex key binding: use key_name like the docs sayAvi Halachmi (:avih)2019-11-201-1/+1
|
* js: report key name for "complex" key bindings - match b08c8f50Avi Halachmi (:avih)2019-11-201-4/+5
|
* js: expose mpv_abort_async_command() (match dbe831bd)Avi Halachmi (:avih)2019-09-111-1/+14
| | | | With minor difference from lua, as documented.
* js: reimplement subprocess_detached using the run command (match 7f91e268)Avi Halachmi (:avih)2019-09-111-0/+5
|
* js: reimplement subprocess using the subprocess command (match 548ef078)Avi Halachmi (:avih)2019-09-111-0/+14
| | | | | | | | | Semantics changes are the same as at 548ef078 . Also, the previous C implementation returnd a string for the `stdout` value, but stdout of the subprocess command is MPV_FORMAT_BYTE_ARRAY which js previously didn't support, so support it too (at pushnode) by returning it as a string - the same as the lua code does.
* js: expose async commands (match 159379980e)Avi Halachmi (:avih)2019-09-111-1/+21
|
* js: use new hooks API (match f60826c3)Avi Halachmi (:avih)2018-04-071-10/+8
|
* js: dump(..): fix incorrect <VISITED> with array argumentAvi Halachmi (:avih)2018-04-071-1/+1
| | | | | | | | | | | | | | | | | | | | | When dump's argument is an array, it was displaying <VISITED> for all the array's object elements (objects, arrays, etc), regardless if they're actually visited or not. The reason is that we try to stringify twice: once normally which may throw (on cycles), and a second time while excluding visited items which is indicated by binding the replacer to an empty array - in which we hold the visited items, where the replacer tests if its 'this' is an array or not and acts accordingly. However, its "this" may also be an array even if we don't bind it to one, because its "normal" this is the main stringified object, so the test of Array.isArray(this) is true when the top object is an array, and the object items are indeed are in it - so the replacer considers them visited. Fix by binding to null on the first attempt such that "this" is an array only when we want it to test for visited items and not when the argument itself is an array.
* js: implement mp.register_idleAvi Halachmi (:avih)2018-04-071-2/+37
| | | | | | | | | | Due to earlier misinterpretation of the Lua docs as if mp.register_idle registers a one-shot callback, the JS docs suggested to use setTimeout. But the behavior and Lua docs are such that it's a repeating callback which fires just before the script thread goes to sleep. Implement it for JS too.
* js: implement mp.options.read_optionsAvi Halachmi (:avih)2018-04-071-0/+52
|
* js: implement mp.msg.trace()TheAMM2017-12-161-1/+1
| | | | | | | To match the new Lua helper introduced in 1afdeee1ad8bca1c703e741002fa3b882d162968 Add documentation for both.
* js: add javascript scripting support using MuJSAvi Halachmi (:avih)2017-06-141-0/+495
Implements JS with almost identical API to the Lua support. Key differences from Lua: - The global mp, mp.msg and mp.utils are always available. - Instead of returning x, error, return x and expose mp.last_error(). - Timers are JS standard set/clear Timeout/Interval. - Supports CommonJS modules/require. - Added at mp.utils: getenv, read_file, write_file and few more. - Global print and dump (expand objects) functions. - mp.options currently not supported. See DOCS/man/javascript.rst for more details.