2022-12-06 03:49:23 +08:00
|
|
|
local Config = require("lazy.core.config")
|
2023-10-09 17:25:42 +08:00
|
|
|
local Git = require("lazy.manage.git")
|
2022-12-06 03:49:23 +08:00
|
|
|
local Manage = require("lazy.manage")
|
2023-01-04 05:50:14 +08:00
|
|
|
local Plugin = require("lazy.core.plugin")
|
2023-01-18 15:24:43 +08:00
|
|
|
local State = require("lazy.state")
|
2023-10-09 17:25:42 +08:00
|
|
|
local Util = require("lazy.util")
|
2022-12-06 03:49:23 +08:00
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
M.running = false
|
|
|
|
M.updated = {}
|
2022-12-13 17:07:36 +08:00
|
|
|
M.reported = {}
|
2022-12-06 03:49:23 +08:00
|
|
|
|
|
|
|
function M.start()
|
|
|
|
M.fast_check()
|
2023-01-24 02:17:30 +08:00
|
|
|
if M.schedule() > 0 and not M.has_errors() then
|
2023-01-22 21:30:12 +08:00
|
|
|
Manage.log({
|
2023-01-24 02:17:11 +08:00
|
|
|
clear = false,
|
2023-01-22 21:30:12 +08:00
|
|
|
show = false,
|
|
|
|
check = true,
|
|
|
|
concurrency = Config.options.checker.concurrency,
|
|
|
|
})
|
|
|
|
end
|
2023-01-18 15:24:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.schedule()
|
|
|
|
State.read() -- update state
|
|
|
|
local next_check = State.checker.last_check + Config.options.checker.frequency - os.time()
|
|
|
|
next_check = math.max(next_check, 0)
|
|
|
|
vim.defer_fn(M.check, next_check * 1000)
|
2023-01-22 21:30:12 +08:00
|
|
|
return next_check
|
2022-12-06 03:49:23 +08:00
|
|
|
end
|
|
|
|
|
2022-12-23 14:43:58 +08:00
|
|
|
---@param opts? {report:boolean} report defaults to true
|
|
|
|
function M.fast_check(opts)
|
|
|
|
opts = opts or {}
|
2022-12-06 03:49:23 +08:00
|
|
|
for _, plugin in pairs(Config.plugins) do
|
2024-05-18 16:14:12 +08:00
|
|
|
if not plugin.pin and not plugin.dev and plugin._.installed then
|
2022-12-31 23:01:59 +08:00
|
|
|
plugin._.updates = nil
|
2022-12-20 18:58:54 +08:00
|
|
|
local info = Git.info(plugin.dir)
|
2022-12-20 20:44:21 +08:00
|
|
|
local ok, target = pcall(Git.get_target, plugin)
|
2023-01-03 16:36:35 +08:00
|
|
|
if ok and info and target and not Git.eq(info, target) then
|
2022-12-31 23:01:59 +08:00
|
|
|
plugin._.updates = { from = info, to = target }
|
2022-12-20 18:58:54 +08:00
|
|
|
end
|
2022-12-06 03:49:23 +08:00
|
|
|
end
|
|
|
|
end
|
2022-12-24 16:22:46 +08:00
|
|
|
M.report(opts.report ~= false)
|
2022-12-06 03:49:23 +08:00
|
|
|
end
|
|
|
|
|
2023-01-24 02:17:30 +08:00
|
|
|
function M.has_errors()
|
2023-01-04 05:50:14 +08:00
|
|
|
for _, plugin in pairs(Config.plugins) do
|
|
|
|
if Plugin.has_errors(plugin) then
|
2023-01-24 02:17:30 +08:00
|
|
|
return true
|
2023-01-04 05:50:14 +08:00
|
|
|
end
|
|
|
|
end
|
2023-01-24 02:17:30 +08:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.check()
|
|
|
|
State.checker.last_check = os.time()
|
|
|
|
State.write() -- update state
|
|
|
|
if M.has_errors() then
|
2023-01-18 15:24:43 +08:00
|
|
|
M.schedule()
|
2023-01-04 05:50:14 +08:00
|
|
|
else
|
|
|
|
Manage.check({
|
2023-01-24 02:17:11 +08:00
|
|
|
clear = false,
|
2023-01-04 05:50:14 +08:00
|
|
|
show = false,
|
|
|
|
concurrency = Config.options.checker.concurrency,
|
|
|
|
}):wait(function()
|
|
|
|
M.report()
|
2023-01-18 15:24:43 +08:00
|
|
|
M.schedule()
|
2023-01-04 05:50:14 +08:00
|
|
|
end)
|
|
|
|
end
|
2022-12-06 03:49:23 +08:00
|
|
|
end
|
|
|
|
|
2022-12-24 16:22:46 +08:00
|
|
|
---@param notify? boolean
|
|
|
|
function M.report(notify)
|
2022-12-06 03:49:23 +08:00
|
|
|
local lines = {}
|
2022-12-13 17:07:36 +08:00
|
|
|
M.updated = {}
|
2022-12-06 03:49:23 +08:00
|
|
|
for _, plugin in pairs(Config.plugins) do
|
2022-12-31 23:01:59 +08:00
|
|
|
if plugin._.updates then
|
2022-12-06 03:49:23 +08:00
|
|
|
table.insert(M.updated, plugin.name)
|
2022-12-13 17:07:36 +08:00
|
|
|
if not vim.tbl_contains(M.reported, plugin.name) then
|
|
|
|
table.insert(lines, "- **" .. plugin.name .. "**")
|
|
|
|
table.insert(M.reported, plugin.name)
|
|
|
|
end
|
2022-12-06 03:49:23 +08:00
|
|
|
end
|
|
|
|
end
|
2023-01-07 16:12:51 +08:00
|
|
|
if #lines > 0 and notify and Config.options.checker.notify and not Config.headless() then
|
2022-12-06 03:49:23 +08:00
|
|
|
table.insert(lines, 1, "# Plugin Updates")
|
|
|
|
Util.info(lines)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|