2017-01-31 03:38:50 +01:00
|
|
|
local wibox = require("wibox")
|
|
|
|
local awful = require("awful")
|
|
|
|
local naughty = require("naughty")
|
|
|
|
local watch = require("awful.widget.watch")
|
|
|
|
|
2023-11-26 13:16:29 +01:00
|
|
|
local currentPath = debug.getinfo(1, "S").source:sub(2):match("(.*/)")
|
2017-01-31 03:38:50 +01:00
|
|
|
|
2020-12-06 20:47:40 +01:00
|
|
|
local email_widget = wibox.widget.textbox()
|
2017-01-31 03:38:50 +01:00
|
|
|
email_widget:set_font('Play 9')
|
2023-11-26 13:16:29 +01:00
|
|
|
email_widget:set_text("Loading...")
|
2017-01-31 03:38:50 +01:00
|
|
|
|
2023-11-26 13:16:29 +01:00
|
|
|
|
2023-12-07 10:04:51 +01:00
|
|
|
local path_to_python_in_venv = currentPath .. "/.venv/bin/python"
|
2017-01-31 03:38:50 +01:00
|
|
|
|
|
|
|
watch(
|
2023-11-26 13:16:29 +01:00
|
|
|
path_to_python_in_venv.." "..currentPath.."count_unread_emails.py", 20, function(_, stdout)
|
|
|
|
local is_error = (stdout:match("ERROR") ~= nil)
|
|
|
|
email_widget:set_text("status: "..tostring(is_error))
|
|
|
|
if is_error then
|
|
|
|
email_widget:set_text(stdout)
|
|
|
|
return
|
|
|
|
end
|
2017-02-04 16:38:46 +01:00
|
|
|
local unread_emails_num = tonumber(stdout) or 0
|
2017-01-31 03:38:50 +01:00
|
|
|
if (unread_emails_num > 0) then
|
2023-11-26 13:16:29 +01:00
|
|
|
email_widget:set_text(unread_emails_num)
|
2017-01-31 03:38:50 +01:00
|
|
|
elseif (unread_emails_num == 0) then
|
2020-12-06 20:47:40 +01:00
|
|
|
email_widget:set_text("")
|
|
|
|
end
|
2017-01-31 03:38:50 +01:00
|
|
|
end
|
|
|
|
)
|
2020-12-06 20:47:40 +01:00
|
|
|
local function show_emails()
|
2023-11-26 13:16:29 +01:00
|
|
|
awful.spawn.easy_async(
|
|
|
|
path_to_python_in_venv.." "..currentPath.."read_unread_emails.py",
|
|
|
|
function(stdout)
|
2017-01-31 03:38:50 +01:00
|
|
|
naughty.notify{
|
|
|
|
text = stdout,
|
|
|
|
title = "Unread Emails",
|
2023-11-26 13:16:29 +01:00
|
|
|
timeout = 10, hover_timeout = 0.5,
|
|
|
|
width = 800,
|
|
|
|
parse = true,
|
2017-01-31 03:38:50 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2023-11-26 13:16:29 +01:00
|
|
|
email_widget:connect_signal("mouse::enter", function() show_emails() end)
|
2021-05-10 20:21:04 +02:00
|
|
|
|
2023-11-26 13:16:29 +01:00
|
|
|
-- show_emails()
|
|
|
|
return email_widget
|