awesome/awesome-wm-widgets/email-widget/email.lua

58 lines
1.6 KiB
Lua

local os = require("os")
local wibox = require("wibox")
local awful = require("awful")
local naughty = require("naughty")
local watch = require("awful.widget.watch")
local path_to_icons = "/usr/share/icons/Arc/actions/22/"
local home = os.getenv('HOME')
local email_widget = wibox.widget.textbox()
email_widget:set_font('Play 9')
local email_icon = wibox.widget.imagebox()
email_icon:set_image(path_to_icons .. "/mail-mark-new.png")
local previous_value = 0
watch(
"bash -c " .. home .. "/.config/awesome/awesome-wm-widgets/email-widget/count_unread_emails.py", 60,
function(widget, stdout, stderr, exitreason, exitcode)
local unread_emails_num = tonumber(stdout) or 0
if previous_value < unread_emails_num then
previous_value = unread_emails_num
show_emails(10)
end
email_widget:set_text(stdout)
if (unread_emails_num > 0) then
email_icon:set_image(path_to_icons .. "/mail-mark-unread.png")
elseif (unread_emails_num == 0) then
email_icon:set_image(path_to_icons .. "/mail-message-new.png")
end
end
)
function show_emails(timeout)
awful.spawn.easy_async_with_shell(home .. "/.config/awesome/awesome-wm-widgets/email-widget/read_unread_emails.py",
function(stdout, stderr, reason, exit_code)
naughty.notify{
text = stdout,
title = "Unread Emails",
timeout = timeout,
width = 400,
}
end
)
end
email_icon:connect_signal("button::press", function() show_emails(5) end)
return {
icon = email_icon,
widget = email_widget
}