fix: wake sink preserved on pw-play fallback, logging and cb guards
This commit is contained in:
1 parent
d8b334eb0b
commit
3547a319d9
1 file changed
+24
-10
+24
-10
@@ -166,6 +166,7 @@ function M.wake(cb)
|
||||
end
|
||||
local dir = noctalia.pluginDir()
|
||||
if dir == nil or dir == "" then
|
||||
noctalia.log("wake tone: plugin dir unavailable")
|
||||
if cb then cb(false) end
|
||||
return
|
||||
end
|
||||
@@ -175,22 +176,35 @@ function M.wake(cb)
|
||||
if cb then cb(false) end
|
||||
return
|
||||
end
|
||||
local argv = { "paplay" }
|
||||
if config.wake_sink ~= "" then
|
||||
table.insert(argv, "--device=" .. config.wake_sink)
|
||||
end
|
||||
table.insert(argv, path)
|
||||
if not noctalia.commandExists("paplay") then
|
||||
argv = { "pw-play", path }
|
||||
local argv
|
||||
if noctalia.commandExists("paplay") then
|
||||
argv = { "paplay" }
|
||||
if config.wake_sink ~= "" then
|
||||
table.insert(argv, "--device=" .. config.wake_sink)
|
||||
end
|
||||
table.insert(argv, path)
|
||||
else
|
||||
argv = { "pw-play" }
|
||||
if config.wake_sink ~= "" then
|
||||
table.insert(argv, "-d")
|
||||
table.insert(argv, config.wake_sink)
|
||||
end
|
||||
table.insert(argv, path)
|
||||
if config.wake_sink == "" then
|
||||
noctalia.log("paplay not found, falling back to pw-play")
|
||||
end
|
||||
end
|
||||
noctalia.runAsync(argv, function(res)
|
||||
if res.exitCode ~= 0 then
|
||||
noctalia.log("wake tone playback failed, exit " .. tostring(res.exitCode) .. ": " .. string.sub(res.stderr or "", 1, 200))
|
||||
end
|
||||
if cb then cb(res.exitCode == 0) end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Checks whether the headset is connected. cb(connected:boolean).
|
||||
-- `headsetcontrol --connected` prints `true` or `false` (verified live).
|
||||
-- In mock mode, reports true when the mock battery level is above 30, else false.
|
||||
-- In mock mode, reports true when the mock battery level is above 30, else false (mock connected follows the mock battery walk: true while level > 30).
|
||||
function M.fetchConnected(cb)
|
||||
if config.mock then
|
||||
if cb then cb(mockBattery > 30) end
|
||||
@@ -201,10 +215,10 @@ function M.fetchConnected(cb)
|
||||
table.insert(argv, "--connected")
|
||||
noctalia.runAsync(argv, function(res)
|
||||
if res.exitCode ~= 0 then
|
||||
cb(false)
|
||||
if cb then cb(false) end
|
||||
return
|
||||
end
|
||||
cb(noctalia.string.trim(res.stdout or "") == "true")
|
||||
if cb then cb(noctalia.string.trim(res.stdout or "") == "true") end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user