aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/plugin_manager/init.lua18
-rw-r--r--plugins/plugin_manager/plugin_view.lua50
-rw-r--r--src/lpm.lua7
3 files changed, 49 insertions, 26 deletions
diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua
index 9ed1c28..7f4e5eb 100644
--- a/plugins/plugin_manager/init.lua
+++ b/plugins/plugin_manager/init.lua
@@ -103,13 +103,13 @@ local function run(cmd, progress)
while i < #running_processes + 1 do
local v = running_processes[i]
local still_running = true
+ local progress_line
while true do
local chunk = v[1]:read_stdout(2048)
if config.plugins.plugin_manager.debug and chunk ~= nil then io.stdout:write(chunk) io.stdout:flush() end
if chunk and v[1]:running() and #chunk == 0 then break end
if chunk ~= nil and #chunk > 0 then
v[3] = v[3] .. chunk
- local progress_line
progress_line, v[3] = extract_progress(v[3])
if progress and progress_line then
progress_line = json.decode(progress_line)
@@ -119,10 +119,12 @@ local function run(cmd, progress)
else
still_running = false
if v[1]:returncode() == 0 then
+ progress_line, v[3] = extract_progress(v[3])
v[2]:resolve(v[3])
else
local err = v[1]:read_stderr(2048)
core.error("error running " .. join(" ", cmd) .. ": " .. (err or "?"))
+ progress_line, v[3] = extract_progress(v[3])
v[2]:reject(v[3])
end
break
@@ -211,7 +213,19 @@ end
function PluginManager:install(addon, options) return run_stateful_plugin_command(self, "install", { addon.id .. (addon.version and (":" .. addon.version) or "") }, options) end
function PluginManager:reinstall(addon, options) return run_stateful_plugin_command(self, "install", { addon.id .. (addon.version and (":" .. addon.version) or ""), "--reinstall" }, options) end
function PluginManager:uninstall(addon, options) return run_stateful_plugin_command(self, "uninstall", { addon.id }, options) end
-function PluginManager:unstub(addon, options) return run_stateful_plugin_command(self, "unstub", { addon.id }, options) end
+function PluginManager:unstub(addon, options)
+ local promise = Promise.new()
+ if addon.path and system.get_file_info(addon.path) then
+ promise:resolve(addon)
+ else
+ run({ "unstub", addon.id }, options.progress):done(function(result)
+ local unstubbed_addon = json.decode(result).addons[1]
+ for k,v in pairs(unstubbed_addon) do addon[k] = v end
+ promise:resolve(addon)
+ end)
+ end
+ return promise
+end
function PluginManager:get_addon(name_and_version)
diff --git a/plugins/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua
index 31e3550..7b57272 100644
--- a/plugins/plugin_manager/plugin_view.lua
+++ b/plugins/plugin_manager/plugin_view.lua
@@ -204,7 +204,7 @@ end
function PluginView:install(plugin)
self.loading = true
- self.plugin_manager:install(plugin, { progress = self.progress_callback }):done(function()
+ return self.plugin_manager:install(plugin, { progress = self.progress_callback }):done(function()
self.loading = false
self.selected_plugin, plugin_view.selected_plugin_idx = nil, nil
end)
@@ -212,7 +212,7 @@ end
function PluginView:uninstall(plugin)
self.loading = true
- self.plugin_manager:uninstall(plugin, { progress = self.progress_callback }):done(function()
+ return self.plugin_manager:uninstall(plugin, { progress = self.progress_callback }):done(function()
self.loading = false
self.selected_plugin, plugin_view.selected_plugin_idx = nil, nil
end)
@@ -221,15 +221,14 @@ end
function PluginView:unstub(plugin)
self.loading = true
- self.plugin_manager:unstub(plugin, { progress = self.progress_callback }):done(function()
+ return self.plugin_manager:unstub(plugin, { progress = self.progress_callback }):done(function()
self.loading = false
- self.selected_plugin, plugin_view.selected_plugin_idx = nil, nil
end)
end
function PluginView:reinstall(plugin)
self.loading = true
- self.plugin_manager:reinstall(plugin, { progress = self.progress_callback }):done(function()
+ return self.plugin_manager:reinstall(plugin, { progress = self.progress_callback }):done(function()
self.loading = false
self.selected_plugin, plugin_view.selected_plugin_idx = nil, nil
end)
@@ -328,28 +327,35 @@ command.add(function()
return core.active_view and core.active_view:is(PluginView) and plugin_view.hovered_plugin
end, {
["plugin-manager:view-source-hovered"] = function()
- local directory = plugin_view.hovered_plugin.type == "library" and "libraries" or "plugins"
- local opened = false
- for i, path in ipairs({ plugin_view.hovered_plugin.path, plugin_view.hovered_plugin.path .. PATHSEP .. "init.lua" }) do
- local stat = system.get_file_info(path)
- if stat and stat.type == "file" then
- core.root_view:open_doc(core.open_doc(path))
- opened = true
- end
- end
- if not opened then core.error("Can't find source for plugin.") end
- end,
- ["plugin-manager:view-readme-hovered"] = function()
- local directory = plugin_view.hovered_plugin.type == "library" and "libraries" or "plugins"
- local opened = false
- plugin_view.hovered_plugin:unstub(plugin_view.hovered_plugin):done(function(plugin)
- for i, path in ipairs({ plugin_view.hovered_plugin.path .. PATHSEP .. "README.md" }) do
+ plugin_view:unstub(plugin_view.hovered_plugin):done(function(plugin)
+ local opened = false
+ for i, path in ipairs({ plugin.path, plugin.path .. PATHSEP .. "init.lua" }) do
local stat = system.get_file_info(path)
if stat and stat.type == "file" then
core.root_view:open_doc(core.open_doc(path))
opened = true
end
end
+ if not opened then core.error("Can't find source for plugin.") end
+ end)
+ end,
+ ["plugin-manager:view-readme-hovered"] = function()
+ plugin_view:unstub(plugin_view.hovered_plugin):done(function(plugin)
+ local opened = false
+ local directories = { plugin.path }
+ if plugin.repo_path then
+ table.insert(directories, plugin.repo_path)
+ table.insert(directories, plugin.repo_path:gsub(PATHSEP .. "plugins" .. PATHSEP .. plugin.id .. "$", "")
+ end
+ for _, directory in ipairs(directories) do
+ for i, path in ipairs({ directory .. PATHSEP .. "README.md", directory .. PATHSEP .. "readme.md" }) do
+ local stat = system.get_file_info(path)
+ if stat and stat.type == "file" then
+ core.root_view:open_doc(core.open_doc(path))
+ opened = true
+ end
+ end
+ end
if not opened then core.error("Can't find README for plugin.") end
end)
end
@@ -372,7 +378,7 @@ keymap.add {
}
-PluginView.menu:register(nil, {
+PluginView.menu:register(function() return core.active_view:is(PluginView) end, {
{ text = "Install", command = "plugin-manager:install-hovered" },
{ text = "Uninstall", command = "plugin-manager:uninstall-hovered" },
{ text = "View Source", command = "plugin-manager:view-source-hovered" },
diff --git a/src/lpm.lua b/src/lpm.lua
index 39f7529..40a4a16 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -667,6 +667,7 @@ function Addon:unstub()
local remote_entry = common.grep(manifest['addons'] or manifest['plugins'], function(e) return e.id == self.id end)[1]
if not remote_entry then error("can't find " .. self.type .. " on " .. self.remote) end
local addon = Addon.new(repo, remote_entry)
+
-- merge in attribtues that are probably more accurate than the stub
if addon.version ~= self.version then log_warning(self.id .. " stub on " .. self.repository:url() .. " has differing version from remote (" .. self.version .. " vs " .. addon.version .. "); may lead to install being inconsistent") end
-- if addon.mod_version ~= self.mod_version then log_warning(self.id .. " stub on " .. self.repository:url() .. " has differing mod_version from remote (" .. self.mod_version .. " vs " .. addon.mod_version .. ")") end
@@ -1423,7 +1424,8 @@ function Bottle:all_addons()
local_path = path,
mod_version = self.lite_xl.mod_version,
path = addon_type .. PATHSEP .. v,
- description = (hash[id] and hash[id][1].description or nil)
+ description = (hash[id] and hash[id][1].description or nil),
+ repo_path = (hash[id] and hash[id][1].local_path or nil)
}))
end
end
@@ -1788,6 +1790,7 @@ local function print_addon_info(type, addons, filters)
organization = addon.organization,
repository = addon.repository and addon.repository:url(),
path = addon:get_path(system_bottle),
+ repo_path = addon.repo_path,
url = url
}
if addon_matches_filter(hash, filters or {}) then
@@ -1955,7 +1958,7 @@ local function run_command(ARGS)
elseif (ARGS[2] == "plugin" or ARGS[2] == "color" or ARGS[2] == "library") and (#ARGS == 2 or ARGS[3] == "list") then return lpm_addon_list(ARGS[2], ARGS[4], ARGS)
elseif ARGS[2] == "upgrade" then return lpm_addon_upgrade(table.unpack(common.slice(ARGS, 3)))
elseif ARGS[2] == "install" then lpm_install(nil, table.unpack(common.slice(ARGS, 3)))
- elseif ARGS[2] == "unstub" then lpm_unstub(nil, table.unpack(common.slice(ARGS, 3)))
+ elseif ARGS[2] == "unstub" then return lpm_unstub(nil, table.unpack(common.slice(ARGS, 3)))
elseif ARGS[2] == "uninstall" then lpm_addon_uninstall(nil, table.unpack(common.slice(ARGS, 3)))
elseif ARGS[2] == "reinstall" then lpm_addon_reinstall(nil, table.unpack(common.slice(ARGS, 3)))
elseif ARGS[2] == "describe" then lpm_describe(nil, table.unpack(common.slice(ARGS, 3)))