diff --git a/plugin/subminer/process.lua b/plugin/subminer/process.lua index b76ba5a..1db2ebd 100644 --- a/plugin/subminer/process.lua +++ b/plugin/subminer/process.lua @@ -2,8 +2,6 @@ local M = {} local OVERLAY_START_RETRY_DELAY_SECONDS = 0.2 local OVERLAY_START_MAX_ATTEMPTS = 6 -local STARTUP_OVERLAY_ACTION_RETRY_DELAY_SECONDS = 0.2 -local STARTUP_OVERLAY_ACTION_MAX_ATTEMPTS = 6 function M.create(ctx) local mp = ctx.mp @@ -16,6 +14,14 @@ function M.create(ctx) local show_osd = ctx.log.show_osd local normalize_log_level = ctx.log.normalize_log_level + local function resolve_visible_overlay_startup() + local raw_visible_overlay = opts.auto_start_visible_overlay + if raw_visible_overlay == nil then + raw_visible_overlay = opts["auto-start-visible-overlay"] + end + return options_helper.coerce_bool(raw_visible_overlay, false) + end + local function resolve_backend(override_backend) local selected = override_backend if selected == nil or selected == "" then @@ -48,6 +54,13 @@ function M.create(ctx) local socket_path = overrides.socket_path or opts.socket_path table.insert(args, "--socket") table.insert(args, socket_path) + + local should_show_visible = resolve_visible_overlay_startup() + if should_show_visible then + table.insert(args, "--show-visible-overlay") + else + table.insert(args, "--hide-visible-overlay") + end end return args @@ -99,43 +112,6 @@ function M.create(ctx) return overrides end - local function resolve_visible_overlay_startup() - local raw_visible_overlay = opts.auto_start_visible_overlay - if raw_visible_overlay == nil then - raw_visible_overlay = opts["auto-start-visible-overlay"] - end - return options_helper.coerce_bool(raw_visible_overlay, false) - end - - local function apply_startup_overlay_preferences() - local should_show_visible = resolve_visible_overlay_startup() - local visible_action = should_show_visible and "show-visible-overlay" or "hide-visible-overlay" - - local function try_apply(attempt) - run_control_command_async(visible_action, nil, function(ok) - if ok then - subminer_log( - "debug", - "process", - "Applied visible startup action: " .. visible_action .. " (attempt " .. tostring(attempt) .. ")" - ) - return - end - - if attempt >= STARTUP_OVERLAY_ACTION_MAX_ATTEMPTS then - subminer_log("warn", "process", "Failed to apply visible startup action: " .. visible_action) - return - end - - mp.add_timeout(STARTUP_OVERLAY_ACTION_RETRY_DELAY_SECONDS, function() - try_apply(attempt + 1) - end) - end) - end - - try_apply(1) - end - local function build_texthooker_args() local args = { state.binary_path, "--texthooker", "--port", tostring(opts.texthooker_port) } local log_level = normalize_log_level(opts.log_level) @@ -240,7 +216,6 @@ function M.create(ctx) return end - apply_startup_overlay_preferences() end) end @@ -376,7 +351,6 @@ function M.create(ctx) build_command_args = build_command_args, run_control_command_async = run_control_command_async, parse_start_script_message_overrides = parse_start_script_message_overrides, - apply_startup_overlay_preferences = apply_startup_overlay_preferences, ensure_texthooker_running = ensure_texthooker_running, start_overlay = start_overlay, start_overlay_from_script_message = start_overlay_from_script_message, diff --git a/scripts/test-plugin-start-gate.lua b/scripts/test-plugin-start-gate.lua index 1964b82..9fcce30 100644 --- a/scripts/test-plugin-start-gate.lua +++ b/scripts/test-plugin-start-gate.lua @@ -239,6 +239,16 @@ local function find_start_call(async_calls) return nil end +local function call_has_arg(call, target) + local args = (call and call.args) or {} + for _, value in ipairs(args) do + if value == target then + return true + end + end + return false +end + local function has_sync_command(sync_calls, executable) for _, call in ipairs(sync_calls) do local args = call.args or {} @@ -353,4 +363,58 @@ do ) end +do + local recorded, err = run_plugin_scenario({ + process_list = "", + option_overrides = { + binary_path = binary_path, + auto_start = "yes", + auto_start_visible_overlay = "yes", + }, + media_title = "Random Movie", + files = { + [binary_path] = true, + }, + }) + assert_true(recorded ~= nil, "plugin failed to load for visible auto-start scenario: " .. tostring(err)) + fire_event(recorded, "file-loaded") + local start_call = find_start_call(recorded.async_calls) + assert_true(start_call ~= nil, "auto-start should issue --start command") + assert_true( + call_has_arg(start_call, "--show-visible-overlay"), + "auto-start with visible overlay enabled should pass --show-visible-overlay" + ) + assert_true( + not call_has_arg(start_call, "--hide-visible-overlay"), + "auto-start with visible overlay enabled should not pass --hide-visible-overlay" + ) +end + +do + local recorded, err = run_plugin_scenario({ + process_list = "", + option_overrides = { + binary_path = binary_path, + auto_start = "yes", + auto_start_visible_overlay = "no", + }, + media_title = "Random Movie", + files = { + [binary_path] = true, + }, + }) + assert_true(recorded ~= nil, "plugin failed to load for hidden auto-start scenario: " .. tostring(err)) + fire_event(recorded, "file-loaded") + local start_call = find_start_call(recorded.async_calls) + assert_true(start_call ~= nil, "auto-start should issue --start command") + assert_true( + call_has_arg(start_call, "--hide-visible-overlay"), + "auto-start with visible overlay disabled should pass --hide-visible-overlay" + ) + assert_true( + not call_has_arg(start_call, "--show-visible-overlay"), + "auto-start with visible overlay disabled should not pass --show-visible-overlay" + ) +end + print("plugin start gate regression tests: OK")