mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 18:22:42 -08:00
fix(plugin): gate auto-start overlay by matching mpv IPC socket
This commit is contained in:
@@ -77,9 +77,11 @@ texthooker_port=5174
|
|||||||
backend=auto
|
backend=auto
|
||||||
|
|
||||||
# Start the overlay automatically when a file is loaded.
|
# Start the overlay automatically when a file is loaded.
|
||||||
|
# Runs only when mpv input-ipc-server matches socket_path.
|
||||||
auto_start=no
|
auto_start=no
|
||||||
|
|
||||||
# Show the visible overlay on auto-start.
|
# Show the visible overlay on auto-start.
|
||||||
|
# Runs only when mpv input-ipc-server matches socket_path.
|
||||||
auto_start_visible_overlay=no
|
auto_start_visible_overlay=no
|
||||||
|
|
||||||
# Show OSD messages for overlay status changes.
|
# Show OSD messages for overlay status changes.
|
||||||
@@ -121,8 +123,8 @@ aniskip_button_duration=3
|
|||||||
| `texthooker_enabled` | `yes` | `yes` / `no` | Enable texthooker server |
|
| `texthooker_enabled` | `yes` | `yes` / `no` | Enable texthooker server |
|
||||||
| `texthooker_port` | `5174` | 1–65535 | Texthooker server port |
|
| `texthooker_port` | `5174` | 1–65535 | Texthooker server port |
|
||||||
| `backend` | `auto` | `auto`, `hyprland`, `sway`, `x11`, `macos` | Window manager backend |
|
| `backend` | `auto` | `auto`, `hyprland`, `sway`, `x11`, `macos` | Window manager backend |
|
||||||
| `auto_start` | `no` | `yes` / `no` | Auto-start overlay on file load |
|
| `auto_start` | `no` | `yes` / `no` | Auto-start overlay on file load when mpv socket matches `socket_path` |
|
||||||
| `auto_start_visible_overlay` | `no` | `yes` / `no` | Show visible layer on auto-start |
|
| `auto_start_visible_overlay` | `no` | `yes` / `no` | Show visible layer on auto-start when mpv socket matches `socket_path` |
|
||||||
| `osd_messages` | `yes` | `yes` / `no` | Show OSD status messages |
|
| `osd_messages` | `yes` | `yes` / `no` | Show OSD status messages |
|
||||||
| `log_level` | `info` | `debug`, `info`, `warn`, `error` | Log verbosity |
|
| `log_level` | `info` | `debug`, `info`, `warn`, `error` | Log verbosity |
|
||||||
| `aniskip_enabled` | `yes` | `yes` / `no` | Enable AniSkip intro detection |
|
| `aniskip_enabled` | `yes` | `yes` / `no` | Enable AniSkip intro detection |
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ texthooker_port=5174
|
|||||||
backend=auto
|
backend=auto
|
||||||
|
|
||||||
# Automatically start overlay when a file is loaded
|
# Automatically start overlay when a file is loaded
|
||||||
|
# Runs only when mpv input-ipc-server matches socket_path.
|
||||||
auto_start=yes
|
auto_start=yes
|
||||||
|
|
||||||
# Automatically show visible overlay when overlay starts
|
# Automatically show visible overlay when overlay starts
|
||||||
|
# Runs only when mpv input-ipc-server matches socket_path.
|
||||||
auto_start_visible_overlay=yes
|
auto_start_visible_overlay=yes
|
||||||
|
|
||||||
# Show OSD messages for overlay status
|
# Show OSD messages for overlay status
|
||||||
|
|||||||
@@ -34,7 +34,20 @@ function M.create(ctx)
|
|||||||
|
|
||||||
local should_auto_start = resolve_auto_start_enabled()
|
local should_auto_start = resolve_auto_start_enabled()
|
||||||
if should_auto_start then
|
if should_auto_start then
|
||||||
process.start_overlay()
|
if not process.has_matching_mpv_ipc_socket(opts.socket_path) then
|
||||||
|
subminer_log(
|
||||||
|
"info",
|
||||||
|
"lifecycle",
|
||||||
|
"Skipping auto-start: input-ipc-server does not match configured socket_path"
|
||||||
|
)
|
||||||
|
schedule_aniskip_fetch("file-loaded", 0)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
process.start_overlay({
|
||||||
|
auto_start_trigger = true,
|
||||||
|
socket_path = opts.socket_path,
|
||||||
|
})
|
||||||
-- Give the overlay process a moment to initialize before querying AniSkip.
|
-- Give the overlay process a moment to initialize before querying AniSkip.
|
||||||
schedule_aniskip_fetch("overlay-start", 0.8)
|
schedule_aniskip_fetch("overlay-start", 0.8)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -22,6 +22,26 @@ function M.create(ctx)
|
|||||||
return options_helper.coerce_bool(raw_visible_overlay, false)
|
return options_helper.coerce_bool(raw_visible_overlay, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function normalize_socket_path(path)
|
||||||
|
if type(path) ~= "string" then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local trimmed = path:match("^%s*(.-)%s*$")
|
||||||
|
if trimmed == "" then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return trimmed
|
||||||
|
end
|
||||||
|
|
||||||
|
local function has_matching_mpv_ipc_socket(target_socket_path)
|
||||||
|
local expected_socket = normalize_socket_path(target_socket_path or opts.socket_path)
|
||||||
|
local active_socket = normalize_socket_path(mp.get_property("input-ipc-server"))
|
||||||
|
if expected_socket == nil or active_socket == nil then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return expected_socket == active_socket
|
||||||
|
end
|
||||||
|
|
||||||
local function resolve_backend(override_backend)
|
local function resolve_backend(override_backend)
|
||||||
local selected = override_backend
|
local selected = override_backend
|
||||||
if selected == nil or selected == "" then
|
if selected == nil or selected == "" then
|
||||||
@@ -56,6 +76,9 @@ function M.create(ctx)
|
|||||||
table.insert(args, socket_path)
|
table.insert(args, socket_path)
|
||||||
|
|
||||||
local should_show_visible = resolve_visible_overlay_startup()
|
local should_show_visible = resolve_visible_overlay_startup()
|
||||||
|
if should_show_visible and overrides.auto_start_trigger == true then
|
||||||
|
should_show_visible = has_matching_mpv_ipc_socket(socket_path)
|
||||||
|
end
|
||||||
if should_show_visible then
|
if should_show_visible then
|
||||||
table.insert(args, "--show-visible-overlay")
|
table.insert(args, "--show-visible-overlay")
|
||||||
else
|
else
|
||||||
@@ -349,6 +372,7 @@ function M.create(ctx)
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
build_command_args = build_command_args,
|
build_command_args = build_command_args,
|
||||||
|
has_matching_mpv_ipc_socket = has_matching_mpv_ipc_socket,
|
||||||
run_control_command_async = run_control_command_async,
|
run_control_command_async = run_control_command_async,
|
||||||
parse_start_script_message_overrides = parse_start_script_message_overrides,
|
parse_start_script_message_overrides = parse_start_script_message_overrides,
|
||||||
ensure_texthooker_running = ensure_texthooker_running,
|
ensure_texthooker_running = ensure_texthooker_running,
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ local function run_plugin_scenario(config)
|
|||||||
if name == "platform" then
|
if name == "platform" then
|
||||||
return config.platform or "linux"
|
return config.platform or "linux"
|
||||||
end
|
end
|
||||||
|
if name == "input-ipc-server" then
|
||||||
|
return config.input_ipc_server or ""
|
||||||
|
end
|
||||||
if name == "filename/no-ext" then
|
if name == "filename/no-ext" then
|
||||||
return config.filename_no_ext or ""
|
return config.filename_no_ext or ""
|
||||||
end
|
end
|
||||||
@@ -370,7 +373,9 @@ do
|
|||||||
binary_path = binary_path,
|
binary_path = binary_path,
|
||||||
auto_start = "yes",
|
auto_start = "yes",
|
||||||
auto_start_visible_overlay = "yes",
|
auto_start_visible_overlay = "yes",
|
||||||
|
socket_path = "/tmp/subminer-socket",
|
||||||
},
|
},
|
||||||
|
input_ipc_server = "/tmp/subminer-socket",
|
||||||
media_title = "Random Movie",
|
media_title = "Random Movie",
|
||||||
files = {
|
files = {
|
||||||
[binary_path] = true,
|
[binary_path] = true,
|
||||||
@@ -397,7 +402,9 @@ do
|
|||||||
binary_path = binary_path,
|
binary_path = binary_path,
|
||||||
auto_start = "yes",
|
auto_start = "yes",
|
||||||
auto_start_visible_overlay = "no",
|
auto_start_visible_overlay = "no",
|
||||||
|
socket_path = "/tmp/subminer-socket",
|
||||||
},
|
},
|
||||||
|
input_ipc_server = "/tmp/subminer-socket",
|
||||||
media_title = "Random Movie",
|
media_title = "Random Movie",
|
||||||
files = {
|
files = {
|
||||||
[binary_path] = true,
|
[binary_path] = true,
|
||||||
@@ -417,4 +424,28 @@ do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local recorded, err = run_plugin_scenario({
|
||||||
|
process_list = "",
|
||||||
|
option_overrides = {
|
||||||
|
binary_path = binary_path,
|
||||||
|
auto_start = "yes",
|
||||||
|
auto_start_visible_overlay = "yes",
|
||||||
|
socket_path = "/tmp/subminer-socket",
|
||||||
|
},
|
||||||
|
input_ipc_server = "/tmp/other.sock",
|
||||||
|
media_title = "Random Movie",
|
||||||
|
files = {
|
||||||
|
[binary_path] = true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert_true(recorded ~= nil, "plugin failed to load for mismatched socket 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 be skipped when mpv input-ipc-server does not match configured socket_path"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
print("plugin start gate regression tests: OK")
|
print("plugin start gate regression tests: OK")
|
||||||
|
|||||||
Reference in New Issue
Block a user