Skip to content

Commit d58ed66

Browse files
committed
extra protection against division by zero
1 parent 0391d98 commit d58ed66

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mpris-widget/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function playerctl:watch(timeout, callback, widget)
3838

3939
local position, length, progress = tonumber(words[5]), tonumber(words[6])
4040

41-
if position ~= nil and length ~= nil then
41+
if position ~= nil and length ~= nil and length > 0 then
4242
progress = position / length
4343
end
4444

@@ -256,7 +256,7 @@ local function worker(user_args)
256256
s = s .. "\n" .. meta.current_song .. " (" .. duration(meta.position) .. "/" .. duration(meta.length) .. ")"
257257
metadata_widget:set_text(s)
258258

259-
progress_widget.values = {1.0 - meta.progress, meta.progress}
259+
progress_widget.values = {1.0 - (meta.progress or 0.0), meta.progress or 0.0}
260260

261261
-- poor man's urldecode
262262
local art_url = meta.art_url:gsub("file://", "/")

0 commit comments

Comments
 (0)