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-12-02 12:36:50 +01:00
|
|
|
function split(str, delimiter)
|
|
|
|
if str == nil then
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
local ret = {''}
|
|
|
|
count = 1
|
|
|
|
for i = 1, string.len(str) do
|
|
|
|
local c = str:sub(i,i)
|
|
|
|
if c == delimiter then
|
|
|
|
count = count + 1
|
|
|
|
ret[count] = ''
|
|
|
|
else
|
|
|
|
ret[count] = ret[count] .. c
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
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-12-02 12:36:50 +01:00
|
|
|
|
|
|
|
s = split(stderr, '\n')
|
|
|
|
local actions = {}
|
|
|
|
|
|
|
|
if stderr ~= '' then
|
|
|
|
for index, line in pairs(s) do
|
|
|
|
if index > 1 then
|
|
|
|
actions["Check email from account " .. tostring(index - 1)] = function ()
|
2018-12-05 20:32:37 +01:00
|
|
|
awful.spawn.easy_async("firefox " .. s[index - 1], function() end)
|
2018-12-02 12:36:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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,
|
2018-12-02 12:36:50 +01:00
|
|
|
actions = actions,
|
2018-11-28 15:31:35 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|