History

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.

Avi Halachmi (:avih) committed 5 years ago

Commit f6b834a1 parent 3ea1f8e1 file · +5 −9Browse files

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

Unified · Split

player/javascript/defaults.js+5−9
@@ -771,14 +771,10 @@ g.mp_event_loop = function mp_event_loop() { · 770 unmodified lines
771 771
772 772
773// let the user extend us, e.g. by adding items to mp.module_paths773// let the user extend us, e.g. by adding items to mp.module_paths
774if (mp.get_property_bool("config")) { // --no-config disables custom init774var initjs = mp.find_config_file("init.js"); // ~~/init.js
775 // file_info doesn't expand meta-paths (other file functions do)775if (initjs)
776 var file_info = mp.utils.file_info, user_path = mp.utils.get_user_path;776 require(initjs.slice(0, -3)); // remove ".js"
777 777else if ((initjs = mp.find_config_file(".init.js")))
778 if (file_info(user_path("~~/init.js")))778 mp.msg.warn("Use init.js instead of .init.js (ignoring " + initjs + ")");
779 require("~~/init");
780 else if (file_info(user_path("~~/.init.js")))
781 mp.msg.warn("Config file ~~/.init.js is ignored. Use ~~/init.js");
782}
783 779
784})(this)780})(this)

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