History

js: read_options: on_update: don't re-read the config file

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.

Avi Halachmi (:avih) committed 6 years ago

Commit b6708381 parent 3267bcd2 files · +4 −4Browse files

Showing the changes to player/javascript (1 of 2 files). Show all

Unified · Split

player/javascript/defaults.js+3−3
@@ -511,13 +511,13 @@ g.require = new_require(SCRIPTDIR_META + "/" + main_script[1]); · 510 unmodified lines
511/**********************************************************************511/**********************************************************************
512 * mp.options512 * mp.options
513 *********************************************************************/513 *********************************************************************/
514function read_options(opts, id, on_update) {514function read_options(opts, id, on_update, conf_override) {
515 id = String(id ? id : mp.get_script_name());515 id = String(id ? id : mp.get_script_name());
516 mp.msg.debug("reading options for " + id);516 mp.msg.debug("reading options for " + id);
517 517
518 var conf, fname = "~~/script-opts/" + id + ".conf";518 var conf, fname = "~~/script-opts/" + id + ".conf";
519 try {519 try {
520 conf = mp.utils.read_file(fname);520 conf = arguments.length > 3 ? conf_override : mp.utils.read_file(fname);
521 } catch (e) {521 } catch (e) {
522 mp.msg.verbose(fname + " not found.");522 mp.msg.verbose(fname + " not found.");
523 }523 }
@@ -561,7 +561,7 @@ function read_options(opts, id, on_update) { · 37 unmodified lines
561 mp.observe_property("options/script-opts", "native", function(_n, _v) {561 mp.observe_property("options/script-opts", "native", function(_n, _v) {
562 var saved = JSON.parse(JSON.stringify(opts)); // clone562 var saved = JSON.parse(JSON.stringify(opts)); // clone
563 var changelist = {}, changed = false;563 var changelist = {}, changed = false;
564 read_options(opts, id); // re-apply conf-file + script-opts564 read_options(opts, id, 0, conf); // re-apply orig-file + script-opts
565 for (var key in opts) {565 for (var key in opts) {
566 if (opts[key] != saved[key]) // type always stays the same566 if (opts[key] != saved[key]) // type always stays the same
567 changelist[key] = changed = true;567 changelist[key] = changed = true;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t