aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/plugin_manager/init.lua40
-rw-r--r--plugins/plugin_manager/plugin_view.lua55
2 files changed, 53 insertions, 42 deletions
diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua
index c062335..11a6304 100644
--- a/plugins/plugin_manager/init.lua
+++ b/plugins/plugin_manager/init.lua
@@ -63,6 +63,8 @@ function Promise:resolve(result) self.result = result self.success = true for i,
function Promise:reject(result) self.result = result self.success = false for i,v in ipairs(self._fail) do v(result) end return self end
function Promise:forward(promise) self:done(function(data) promise:resolve(data) end) self:fail(function(data) promise:reject(data) end) return self end
+local function join(joiner, t) local s = "" for i,v in ipairs(t) do if i > 1 then s = s .. joiner end s = s .. v end return s end
+
local running_processes = {}
local function run(cmd)
@@ -100,7 +102,7 @@ local function run(cmd)
v[2]:resolve(v[3])
else
local err = v[1]:read_stderr(2048)
- core.error("error running lpm: " .. (err or "?"))
+ core.error("error running " .. join(" ", cmd) .. ": " .. (err or "?"))
v[2]:reject(v[3])
end
break
@@ -153,31 +155,22 @@ function PluginManager:get_plugins()
return prom
end
-
-function PluginManager:install(plugin)
+local function run_stateful_plugin_command(plugin_manager, cmd, arg)
local promise = Promise.new()
- run({ "plugin", "install", plugin.name .. (plugin.version and (":" .. plugin.version) or "") }):done(function(result)
+ run({ "plugin", cmd, arg }):done(function(result)
if config.plugins.plugin_manager.restart_on_change then
command.perform("core:restart")
else
- self:refresh():forward(promise)
+ plugin_manager:refresh():forward(promise)
end
end)
return promise
end
-function PluginManager:uninstall(plugin)
- local promise = Promise.new()
- run({ "plugin", "uninstall", plugin.name }):done(function(result)
- if config.plugins.plugin_manager.restart_on_change then
- command.perform("core:restart")
- else
- self:refresh():forward(promise)
- end
- end)
- return promise
-end
+function PluginManager:install(plugin) return run_stateful_plugin_command(self, "install", plugin.name .. (plugin.version and (":" .. plugin.version) or "")) end
+function PluginManager:uninstall(plugin) return run_stateful_plugin_command(self, "uninstall", plugin.name) end
+function PluginManager:reinstall(plugin) return run_stateful_plugin_command(self, "reinstall", plugin.name) end
function PluginManager:get_plugin(name_and_version)
@@ -202,6 +195,9 @@ function PluginManager:get_plugin(name_and_version)
return promise
end
+PluginManager.promise = Promise
+PluginManager.view = require "plugins.plugin_manager.plugin_view"
+
command.add(nil, {
["plugin-manager:install"] = function()
core.command_view:enter("Enter plugin name",
@@ -274,14 +270,10 @@ command.add(nil, {
)
end,
["plugin-manager:refresh"] = function() PluginManager:refresh():done(function() core.log("Successfully refreshed plugin listing.") end) end,
+ ["plugin-manager:show"] = function()
+ local node = core.root_view:get_active_node_default()
+ node:add_view(PluginManager.view(PluginManager))
+ end
})
-PluginManager.promise = Promise
-PluginManager.initialized = Promise.new()
-PluginManager:refresh():done(function()
- PluginManager.initialized:resolve()
- PluginManager.view = require "plugins.plugin_manager.plugin_view"
-end)
-
-
return PluginManager
diff --git a/plugins/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua
index 7e7f04d..19eb9ae 100644
--- a/plugins/plugin_manager/plugin_view.lua
+++ b/plugins/plugin_manager/plugin_view.lua
@@ -9,7 +9,6 @@ local View = require "core.view"
local keymap = require "core.keymap"
local RootView = require "core.rootview"
local ContextMenu = require "core.contextmenu"
-local PluginManager = require "plugins.plugin_manager"
local PluginView = View:extend()
@@ -40,7 +39,8 @@ function PluginView:new()
self.selected_plugin = nil
self.selected_plugin_idx = nil
self.initialized = false
- PluginManager.initialized:done(function()
+ self.plugin_manager = require "plugins.plugin_manager"
+ self.plugin_manager:refresh():done(function()
self.initialized = true
self:refresh()
end)
@@ -112,7 +112,7 @@ end
function PluginView:get_plugins()
- return self.show_incompatible_plugins and PluginManager.plugins or PluginManager.valid_plugins
+ return self.show_incompatible_plugins and self.plugin_manager.plugins or self.plugin_manager.valid_plugins
end
@@ -131,7 +131,10 @@ end
function PluginView:draw()
self:draw_background(style.background)
- if not self.initialized then return end
+ if not self.initialized then
+ common.draw_text(style.big_font, style.dim, "Loading...", "center", self.position.x, self.position.y, self.size.x, self.size.y)
+ return
+ end
local th = style.font:get_height()
local lh = th + style.padding.y
@@ -154,7 +157,7 @@ function PluginView:draw()
end
x = x + style.padding.x
for j, v in ipairs({ get_plugin_text(plugin) }) do
- local color = plugin.status == "installed" and style.good or style.text
+ local color = (plugin.status == "installed" or plugin.status == "orphan") and style.good or (plugin.status == "core" and style.warn or style.text)
if self.loading then color = mul(color, style.dim) end
common.draw_text(style.font, color, v, "left", x, y, self.widths[j], lh)
x = x + self.widths[j] + style.padding.x
@@ -168,7 +171,7 @@ end
function PluginView:install(plugin)
self.loading = true
- PluginManager:install(plugin):done(function()
+ self.plugin_manager:install(plugin):done(function()
self.loading = false
self.selected_plugin, plugin_view.selected_plugin_idx = nil, nil
end)
@@ -176,24 +179,38 @@ end
function PluginView:uninstall(plugin)
self.loading = true
- PluginManager:uninstall(plugin):done(function()
+ self.plugin_manager:uninstall(plugin):done(function()
self.loading = false
self.selected_plugin, plugin_view.selected_plugin_idx = nil, nil
end)
end
-command.add(nil, {
- ["plugin-manager:show"] = function()
- local node = core.root_view:get_active_node_default()
- node:add_view(PluginView())
- end
-})
+function PluginView:reinstall(plugin)
+ self.loading = true
+ self.plugin_manager:reinstall(plugin):done(function()
+ self.loading = false
+ self.selected_plugin, plugin_view.selected_plugin_idx = nil, nil
+ end)
+end
command.add(PluginView, {
["plugin-manager:select"] = function(x, y)
plugin_view.selected_plugin, plugin_view.selected_plugin_idx = plugin_view.hovered_plugin, plugin_view.hovered_plugin_idx
end,
+ ["plugin-manager:select-prev"] = function()
+ local plugins = plugin_view:get_plugins()
+ if plugin_view.selected_plugin_idx > 1 then plugin_view.selected_plugin_idx = plugin_view.selected_plugin_idx - 1 end
+ plugin_view.selected_plugin = plugins[plugin_view.selected_plugin_idx]
+ end,
+ ["plugin-manager:select-next"] = function()
+ local plugins = plugin_view:get_plugins()
+ if plugin_view.selected_plugin_idx < #plugins then plugin_view.selected_plugin_idx = plugin_view.selected_plugin_idx + 1 end
+ plugin_view.selected_plugin = plugins[plugin_view.selected_plugin_idx]
+ end,
+ ["plugin-manager:select"] = function(x, y)
+ plugin_view.selected_plugin, plugin_view.selected_plugin_idx = plugin_view.hovered_plugin, plugin_view.hovered_plugin_idx
+ end,
})
command.add(function()
return core.active_view and core.active_view:is(PluginView) and plugin_view.selected_plugin and plugin_view.selected_plugin.status == "available"
@@ -206,17 +223,18 @@ end, {
["plugin-manager:install-hovered"] = function() plugin_view:install(plugin_view.hovered_plugin) end
})
command.add(function()
- return core.active_view and core.active_view:is(PluginView) and plugin_view.selected_plugin and plugin_view.selected_plugin.status == "installed"
+ return core.active_view and core.active_view:is(PluginView) and plugin_view.selected_plugin and (plugin_view.selected_plugin.status == "installed" or plugin_view.selected_plugin.status == "orphan")
end, {
["plugin-manager:uninstall-selected"] = function() plugin_view:uninstall(plugin_view.selected_plugin) end
})
command.add(function()
- return core.active_view and core.active_view:is(PluginView) and plugin_view.hovered_plugin and plugin_view.hovered_plugin.status == "installed"
+ return core.active_view and core.active_view:is(PluginView) and plugin_view.hovered_plugin and (plugin_view.hovered_plugin.status == "installed" or plugin_view.hovered_plugin.status == "orphan")
end, {
- ["plugin-manager:uninstall-hovered"] = function() plugin_view:uninstall(plugin_view.hovered_plugin) end
+ ["plugin-manager:uninstall-hovered"] = function() plugin_view:uninstall(plugin_view.hovered_plugin) end,
+ ["plugin-manager:reinstall-hovered"] = function() plugin_view:reinstall(plugin_view.hovered_plugin) end
})
command.add(function()
- return core.active_view and core.active_view:is(PluginView) and plugin_view.hovered_plugin and plugin_view.hovered_plugin.status == "installed"
+ return core.active_view and core.active_view:is(PluginView) and plugin_view.hovered_plugin and (plugin_view.hovered_plugin.status == "installed" or plugin_view.hovered_plugin.status == "core" or plugin_view.hovered_plugin.status == "orphan")
end, {
["plugin-manager:view-source-hovered"] = function()
local directory = plugin_view.hovered_plugin.type == "library" and "libraries" or "plugins"
@@ -237,7 +255,8 @@ keymap.add {
["up"] = "plugin-manager:select-prev",
["down"] = "plugin-manager:select-next",
["lclick"] = "plugin-manager:select",
- ["2lclick"] = { "plugin-manager:install-selected", "plugin-manager:uninstall-selected" }
+ ["2lclick"] = { "plugin-manager:install-selected", "plugin-manager:uninstall-selected" },
+ ["return"] = { "plugin-manager:install-selected", "plugin-manager:uninstall-selected" }
}