diff options
author | Adam <adamdharrison@gmail.com> | 2022-09-18 17:37:45 -0400 |
---|---|---|
committer | Adam <adamdharrison@gmail.com> | 2022-09-18 17:37:45 -0400 |
commit | da37e3ed1e11853c5133c9851a4fc2dbf2ca8872 (patch) | |
tree | ceb417a9fdb539d0e5fa010151e0534348755103 /plugins | |
parent | d60333f917844e3fedfcdb6c8bba1eb8fc454cd9 (diff) | |
download | lite-xl-plugin-manager-da37e3ed1e11853c5133c9851a4fc2dbf2ca8872.tar.gz lite-xl-plugin-manager-da37e3ed1e11853c5133c9851a4fc2dbf2ca8872.zip |
Committing these before I really screw things up.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/plugin_manager/init.lua | 40 | ||||
-rw-r--r-- | plugins/plugin_manager/plugin_view.lua | 43 |
2 files changed, 61 insertions, 22 deletions
diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua index 1769bd0..97ec914 100644 --- a/plugins/plugin_manager/init.lua +++ b/plugins/plugin_manager/init.lua @@ -5,8 +5,6 @@ local common = require "core.common" local config = require "core.config" local command = require "core.command" local json = require "libraries.json" -local keymap = require "core.keymap" -local PluginView = require "plugins.plugin_manager.plugin_view" local PluginManager = { @@ -23,7 +21,11 @@ config.plugins.plugin_manager = common.merge({ -- Path to the folder that holds user-specified plugins. userdir = USERDIR, -- Path to ssl certificate directory. - ssl_certs = nil + ssl_certs = nil, + -- Whether or not to force install things. + force = false, + -- Dumps commands that run to stdout, as well as responses from lpm. + debug = true }, config.plugins.plugin_manager) if not config.plugins.plugin_manager.lpm_binary_path then @@ -68,8 +70,10 @@ local function run(cmd) table.insert(cmd, "--mod-version=" .. MOD_VERSION) table.insert(cmd, "--quiet") table.insert(cmd, "--userdir=" .. USERDIR) - -- print(table.unpack(cmd)) + table.insert(cmd, "--assume-yes") + if config.plugins.plugin_manager.force then table.insert(cmd, "--force") end local proc = process.start(cmd) + if config.plugins.plugin_manager.debug then for i, v in ipairs(cmd) do print((i > 1 and " " or "") .. v) end end local promise = Promise.new() table.insert(running_processes, { proc, promise, "" }) if #running_processes == 1 then @@ -83,6 +87,7 @@ local function run(cmd) local still_running = true while true do local chunk = v[1]:read_stdout(2048) + if config.plugins.plugin_manager.debug then print(chunk) end if chunk and #chunk == 0 then break end if chunk ~= nil then v[3] = v[3] .. chunk @@ -128,6 +133,19 @@ function PluginManager:refresh() end +function PluginManager:get_plugins() + local prom = Promise.new() + if self.plugins then + prom:resolve(self.plugins) + else + self:refresh():done(function() + prom:resolve(self.plugins) + end) + end + return prom +end + + function PluginManager:install(plugin) local promise = Promise.new() run({ "plugin", "install", plugin.name .. (plugin.version and (":" .. plugin.version) or "") }):done(function(result) @@ -195,15 +213,11 @@ command.add(nil, { ["plugin-manager:refresh"] = function() PluginManager:refresh():done(function() core.log("Successfully refreshed plugin listing.") end) end, }) -PluginManager.view = PluginView -PluginManager:refresh() - +PluginManager.promise = Promise +PluginManager.initialized = Promise.new() +PluginManager:refresh():done(function() + PluginManager.initialized:resolve() +end) -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" } -} return PluginManager diff --git a/plugins/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua index 5d5af8e..f661b00 100644 --- a/plugins/plugin_manager/plugin_view.lua +++ b/plugins/plugin_manager/plugin_view.lua @@ -9,7 +9,7 @@ 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() @@ -34,11 +34,15 @@ function PluginView:new() self.scrollable = true self.show_incompatible_plugins = false self.plugin_table_columns = { "Name", "Version", "Modversion", "Status", "Tags", "Description" } - self:refresh() self.hovered_plugin = nil self.hovered_plugin_idx = nil self.selected_plugin = nil self.selected_plugin_idx = nil + self.initialized = false + PluginManager.initialized:done(function() + self.initialized = true + self:refresh() + end) plugin_view = self end @@ -82,11 +86,13 @@ end function PluginView:on_mouse_moved(x, y, dx, dy) PluginView.super.on_mouse_moved(self, x, y, dx, dy) - local th = style.font:get_height() - local lh = th + style.padding.y - local offset = math.floor((y - self.position.y + self.scroll.y) / lh) - self.hovered_plugin = offset > 0 and self:get_plugins()[offset] - self.hovered_plugin_idx = offset > 0 and offset + if self.initialized then + local th = style.font:get_height() + local lh = th + style.padding.y + local offset = math.floor((y - self.position.y + self.scroll.y) / lh) + self.hovered_plugin = offset > 0 and self:get_plugins()[offset] + self.hovered_plugin_idx = offset > 0 and offset + end end @@ -105,13 +111,14 @@ end function PluginView:get_plugins() - if self.show_incompatible_plugins then return PluginManager.plugins end - return PluginManager.valid_plugins + return self.show_incompatible_plugins and PluginManager.plugins or PluginManager.valid_plugins end function PluginView:get_scrollable_size() + if not self.initialized then return math.huge end local th = style.font:get_height() + style.padding.y + local plugins = self:get_plugins() return th * #self:get_plugins() end @@ -123,6 +130,7 @@ end function PluginView:draw() self:draw_background(style.background) + if not self.initialized then return end local th = style.font:get_height() local lh = th + style.padding.y @@ -174,6 +182,14 @@ function PluginView:uninstall(plugin) end +command.add(nil, { + ["plugin-manager:show"] = function() + local node = core.root_view:get_active_node_default() + node:add_view(PluginView()) + 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 @@ -200,4 +216,13 @@ end, { ["plugin-manager:uninstall-hovered"] = function() plugin_view:uninstall(plugin_view.hovered_plugin) end }) + +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" } +} + + return PluginView |