mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-06-10 03:13:32 -07:00
9d77907877
- Show mpv OSD spinner from start-file until subminer-overlay-loading-ready; force-shown for visible-overlay startup regardless of osd_messages setting - Gate non-macOS overlay visibility on content-ready so first subtitle line is immediately hoverable and clickable - Queue startup notifications in main process until overlay window finishes loading; upsert progress cards by id to avoid cold-start floods - Defer background warmups until after overlay runtime init so queued notifications can deliver promptly - Preserve character dictionary checking/building/importing/ready phases as distinct history entries; route building and importing to system notifications when notificationType is both
68 lines
1.5 KiB
Lua
68 lines
1.5 KiB
Lua
local M = {}
|
|
|
|
local LOG_LEVEL_PRIORITY = {
|
|
debug = 10,
|
|
info = 20,
|
|
warn = 30,
|
|
error = 40,
|
|
}
|
|
|
|
function M.create(ctx)
|
|
local mp = ctx.mp
|
|
local msg = ctx.msg
|
|
local opts = ctx.opts
|
|
|
|
local function normalize_log_level(level)
|
|
local normalized = (level or "info"):lower()
|
|
if LOG_LEVEL_PRIORITY[normalized] then
|
|
return normalized
|
|
end
|
|
return "info"
|
|
end
|
|
|
|
local function should_log(level)
|
|
local current = normalize_log_level(os.getenv("SUBMINER_LOG_LEVEL"))
|
|
local target = normalize_log_level(level)
|
|
return LOG_LEVEL_PRIORITY[target] >= LOG_LEVEL_PRIORITY[current]
|
|
end
|
|
|
|
local function subminer_log(level, scope, message)
|
|
if not should_log(level) then
|
|
return
|
|
end
|
|
local timestamp = os.date("%Y-%m-%d %H:%M:%S")
|
|
local line = string.format("[subminer] - %s - %s - [%s] %s", timestamp, string.upper(level), scope, message)
|
|
if level == "error" then
|
|
msg.error(line)
|
|
elseif level == "warn" then
|
|
msg.warn(line)
|
|
elseif level == "debug" then
|
|
msg.debug(line)
|
|
else
|
|
msg.info(line)
|
|
end
|
|
end
|
|
|
|
local function show_osd(message, options)
|
|
if opts.osd_messages or (options and options.force == true) then
|
|
local payload = "SubMiner: " .. message
|
|
local sent = false
|
|
if type(mp.osd_message) == "function" then
|
|
sent = pcall(mp.osd_message, payload, 3)
|
|
end
|
|
if not sent and type(mp.commandv) == "function" then
|
|
pcall(mp.commandv, "show-text", payload, "3000")
|
|
end
|
|
end
|
|
end
|
|
|
|
return {
|
|
normalize_log_level = normalize_log_level,
|
|
should_log = should_log,
|
|
subminer_log = subminer_log,
|
|
show_osd = show_osd,
|
|
}
|
|
end
|
|
|
|
return M
|