From d09145a932c083b7ea32edda0e65dd0357ac9b9a Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sat, 2 Nov 2024 21:37:08 +0100 Subject: [PATCH] auto_profiles.lua: don't log warnings on exit If a script registers hooks before exiting mpv logs "Sending hook command failed. Removing hook.". (Also there is no function to unregister hooks.) Don't register hooks in auto_profiles.lua before it exits to not log these warnings. Fixes 5dc4047415. Fixes #15244. --- player/lua/auto_profiles.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/player/lua/auto_profiles.lua b/player/lua/auto_profiles.lua index bf1c79721c809..de449fc894d4f 100644 --- a/player/lua/auto_profiles.lua +++ b/player/lua/auto_profiles.lua @@ -19,6 +19,8 @@ for _, property in pairs(mp.get_property_native("property-list")) do property_set[property] = true end +local first_run = true + local function evaluate(profile) msg.verbose("Re-evaluating auto profile " .. profile.name) @@ -198,10 +200,14 @@ mp.observe_property("profile-list", "native", function (_, profiles_property) return end + if first_run then + mp.register_idle(on_idle) + for _, name in ipairs({"on_load", "on_preloaded", "on_before_start_file"}) do + mp.add_hook(name, 50, on_hook) + end + + first_run = false + end + on_idle() -- re-evaluate all profiles immediately end) - -mp.register_idle(on_idle) -for _, name in ipairs({"on_load", "on_preloaded", "on_before_start_file"}) do - mp.add_hook(name, 50, on_hook) -end