2018-11-29 11:39:53 +01:00
|
|
|
local os = require("os")
|
2018-11-28 15:31:35 +01:00
|
|
|
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/"
|
|
|
|
|
2018-11-29 11:39:53 +01:00
|
|
|
local home = os.getenv('HOME')
|
|
|
|
|
|
|
|
local email_widget = wibox.widget.textbox()
|
2018-11-28 15:31:35 +01:00
|
|
|
email_widget:set_font('Play 9')
|
|
|
|
|
2018-11-29 11:39:53 +01:00
|
|
|
local email_icon = wibox.widget.imagebox()
|
2018-11-28 15:31:35 +01:00
|
|
|
email_icon:set_image(path_to_icons .. "/mail-mark-new.png")
|
|
|
|
|
2018-11-29 11:39:53 +01:00
|
|
|
local previous_value = 0
|
|
|
|
|
2018-11-28 15:31:35 +01:00
|
|
|
watch(
|
2018-11-29 11:39:53 +01:00
|
|
|
"bash -c " .. home .. "/.config/awesome/awesome-wm-widgets/email-widget/count_unread_emails.py", 60,
|
2018-11-28 15:31:35 +01:00
|
|
|
function(widget, stdout, stderr, exitreason, exitcode)
|
|
|
|
local unread_emails_num = tonumber(stdout) or 0
|
2018-11-29 11:39:53 +01:00
|
|
|
|
|
|
|
if previous_value < unread_emails_num then
|
|
|
|
previous_value = unread_emails_num
|
|
|
|
show_emails(10)
|
|
|
|
end
|
|
|
|
|
|
|
|
email_widget:set_text(stdout)
|
2018-11-28 15:31:35 +01:00
|
|
|
if (unread_emails_num > 0) then
|
2018-11-29 11:39:53 +01:00
|
|
|
email_icon:set_image(path_to_icons .. "/mail-mark-unread.png")
|
2018-11-28 15:31:35 +01:00
|
|
|
elseif (unread_emails_num == 0) then
|
2018-11-29 11:39:53 +01:00
|
|
|
email_icon:set_image(path_to_icons .. "/mail-message-new.png")
|
|
|
|
end
|
2018-11-28 15:31:35 +01:00
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-11-29 11:39:53 +01:00
|
|
|
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)
|
2018-11-28 15:31:35 +01:00
|
|
|
naughty.notify{
|
|
|
|
text = stdout,
|
|
|
|
title = "Unread Emails",
|
2018-11-29 11:39:53 +01:00
|
|
|
timeout = timeout,
|
2018-11-28 15:31:35 +01:00
|
|
|
width = 400,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-11-29 11:39:53 +01:00
|
|
|
email_icon:connect_signal("button::press", function() show_emails(5) end)
|
|
|
|
|
|
|
|
return {
|
|
|
|
icon = email_icon,
|
|
|
|
widget = email_widget
|
|
|
|
}
|