🐛 fix(wakatime): address missing wakatime data
When the wakatime_stats cache file is missing or empty, return an empty string so lualine will hide the component
This commit is contained in:
@@ -11,12 +11,13 @@ local function read_cache()
|
|||||||
file:close()
|
file:close()
|
||||||
return content
|
return content
|
||||||
end
|
end
|
||||||
return "Error: Cache file not found"
|
return "" -- Return empty string if file is not found or empty
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_wakatime_today()
|
local function get_wakatime_today()
|
||||||
local result = read_cache()
|
local result = read_cache()
|
||||||
if not result or result == "" then
|
if not result or result:match("^%s*$") then
|
||||||
|
-- Return empty string if result is nil or only whitespace
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ local function get_wakatime_today()
|
|||||||
result:match("command not found")
|
result:match("command not found")
|
||||||
or result:match("No such file or directory")
|
or result:match("No such file or directory")
|
||||||
then
|
then
|
||||||
return "Error: wakatime-cli not found"
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
return result:match("^%s*(.-)%s*$") -- Trim any whitespace
|
return result:match("^%s*(.-)%s*$") -- Trim any whitespace
|
||||||
@@ -37,21 +38,27 @@ end
|
|||||||
|
|
||||||
function M.get_icon()
|
function M.get_icon()
|
||||||
local text = M.get_today()
|
local text = M.get_today()
|
||||||
if text and text:match("Error:") then
|
if text ~= "" then
|
||||||
return " " -- Icon for error or issue
|
|
||||||
else
|
|
||||||
return " " -- Default icon
|
return " " -- Default icon
|
||||||
|
else
|
||||||
|
return "" -- No icon
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_icon_with_text()
|
function M.get_icon_with_text()
|
||||||
return M.get_icon() .. " " .. (M.get_today() or "Loading...")
|
local icon = M.get_icon()
|
||||||
|
local text = M.get_today()
|
||||||
|
if icon ~= "" or text ~= "" then
|
||||||
|
return icon .. text -- Combine icon and text
|
||||||
|
else
|
||||||
|
return "" -- No text or icon
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_total_minutes()
|
function M.get_total_minutes()
|
||||||
local wakatime_string = M.get_today()
|
local wakatime_string = M.get_today()
|
||||||
if not wakatime_string or wakatime_string:match("Error:") then
|
if wakatime_string == "" then
|
||||||
return 0 -- Return 0 if there's an error in the wakatime string
|
return 0 -- Return 0 if there's no data
|
||||||
end
|
end
|
||||||
|
|
||||||
local hours, mins = wakatime_string:match("(%d+)%s*hrs?%s*(%d+)%s*mins?")
|
local hours, mins = wakatime_string:match("(%d+)%s*hrs?%s*(%d+)%s*mins?")
|
||||||
|
|||||||
Reference in New Issue
Block a user