function createCountdown(label, endTime, ...)
countdown = {
menu = hs.menubar.new(),
endTime = endTime,
}
countdown.timer = hs.timer.doEvery(1, function()
timeUntilEnd = countdown.endTime - os.time()
sign = timeUntilEnd < 0 and '-' or ''
timeUntilEnd = math.abs(timeUntilEnd)
minutes = math.floor(timeUntilEnd / 60)
seconds = timeUntilEnd % 60
countdown.menu:setTitle(label .. ': ' .. sign .. string.format('%02d:%02d', minutes, seconds))
end)
onStop = ...
countdown.menu:setClickCallback(function()
countdown.timer:stop()
countdown.menu:delete()
if onStop then
onStop()
end
end)
return countdown
end