Add NagView message for refused plugins

This commit is contained in:
Francesco Abbate 2021-04-07 09:42:19 +02:00
parent d7cc1f9f9d
commit 119f406d3c
1 changed files with 28 additions and 4 deletions

View File

@ -441,7 +441,7 @@ function core.init()
core.project_scan_thread_id = core.add_thread(project_scan_thread) core.project_scan_thread_id = core.add_thread(project_scan_thread)
command.add_defaults() command.add_defaults()
local got_user_error = not core.load_user_directory() local got_user_error = not core.load_user_directory()
local got_plugin_error = not core.load_plugins() local plugins_success, plugins_refuse_list = core.load_plugins()
do do
local pdir, pname = project_dir_abs:match("(.*)[/\\\\](.*)") local pdir, pname = project_dir_abs:match("(.*)[/\\\\](.*)")
@ -457,9 +457,28 @@ function core.init()
core.error(delayed_error) core.error(delayed_error)
end end
if got_plugin_error or got_user_error or got_project_error then if not plugins_success or got_user_error or got_project_error then
command.perform("core:open-log") command.perform("core:open-log")
end end
if #plugins_refuse_list.userdir.plugins > 0 or #plugins_refuse_list.datadir.plugins > 0 then
local opt = {
{ font = style.font, text = "Exit", default_no = true },
{ font = style.font, text = "Continue" , default_yes = true }
}
local msg = {}
for _, entry in pairs(plugins_refuse_list) do
if #entry.plugins > 0 then
msg[#msg + 1] = string.format("from %s: %s", common.home_encode(entry.dir), table.concat(entry.plugins, ", "))
end
end
core.nag_view:show(
"Refused Plugins",
string.format("Refused plugins %s", table.concat(msg, " and ")),
opt, function(item)
if item.text == "Exit" then os.exit(1) end
end)
end
end end
@ -583,6 +602,10 @@ end
function core.load_plugins() function core.load_plugins()
local no_errors = true local no_errors = true
local refused_list = {
userdir = {dir = USERDIR, plugins = {}},
datadir = {dir = DATADIR, plugins = {}},
}
for _, root_dir in ipairs {USERDIR, DATADIR} do for _, root_dir in ipairs {USERDIR, DATADIR} do
local plugin_dir = root_dir .. "/plugins" local plugin_dir = root_dir .. "/plugins"
local files = system.list_dir(plugin_dir) local files = system.list_dir(plugin_dir)
@ -591,7 +614,8 @@ function core.load_plugins()
local version_match = check_plugin_version(plugin_dir .. '/' .. filename) local version_match = check_plugin_version(plugin_dir .. '/' .. filename)
if not version_match then if not version_match then
core.log_quiet("Version mismatch for plugin %q from %s", basename, plugin_dir) core.log_quiet("Version mismatch for plugin %q from %s", basename, plugin_dir)
no_errors = false local ls = refused_list[root_dir == USERDIR and 'userdir' or 'datadir'].plugins
ls[#ls + 1] = filename
end end
if version_match and config[basename] ~= false then if version_match and config[basename] ~= false then
local modname = "plugins." .. basename local modname = "plugins." .. basename
@ -603,7 +627,7 @@ function core.load_plugins()
end end
end end
end end
return no_errors return no_errors, refused_list
end end