aboutsummaryrefslogtreecommitdiff
path: root/plugins/plugin_manager
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugin_manager')
-rw-r--r--plugins/plugin_manager/init.lua18
-rw-r--r--plugins/plugin_manager/plugin_view.lua50
2 files changed, 44 insertions, 24 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" },