summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2021-10-31 01:08:08 +0300
committersfan5 <sfan5@live.de>2021-11-01 14:31:18 +0100
commitf6b834a2fcd9a00ca6ed150aede436b42a3107e7 (patch)
treeac3fae5f2df40669a79d0a67b313730d2f03124f
parent3ea1f8e80a33edff8d944ea2e82b0dfe4ff25215 (diff)
downloadmpv-f6b834a2fcd9a00ca6ed150aede436b42a3107e7.tar.bz2
mpv-f6b834a2fcd9a00ca6ed150aede436b42a3107e7.tar.xz
js: ~~/init.js: use mp.find_config_file
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.
-rw-r--r--player/javascript/defaults.js14
1 files changed, 5 insertions, 9 deletions
diff --git a/player/javascript/defaults.js b/player/javascript/defaults.js
index d489bed256..bf83f42204 100644
--- a/player/javascript/defaults.js
+++ b/player/javascript/defaults.js
@@ -771,14 +771,10 @@ g.mp_event_loop = function mp_event_loop() {
// let the user extend us, e.g. by adding items to mp.module_paths
-if (mp.get_property_bool("config")) { // --no-config disables custom init
- // file_info doesn't expand meta-paths (other file functions do)
- var file_info = mp.utils.file_info, user_path = mp.utils.get_user_path;
-
- if (file_info(user_path("~~/init.js")))
- require("~~/init");
- else if (file_info(user_path("~~/.init.js")))
- mp.msg.warn("Config file ~~/.init.js is ignored. Use ~~/init.js");
-}
+var initjs = mp.find_config_file("init.js"); // ~~/init.js
+if (initjs)
+ require(initjs.slice(0, -3)); // remove ".js"
+else if ((initjs = mp.find_config_file(".init.js")))
+ mp.msg.warn("Use init.js instead of .init.js (ignoring " + initjs + ")");
})(this)