diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2023-01-17 17:09:16 -0500 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2023-01-17 17:09:16 -0500 |
commit | c2c049448c4357eeb8474f21e880fd7258d90d80 (patch) | |
tree | 8d127dd3951778424568ea3f117dbf5dcb6a3dab | |
parent | c73f371caa7c6d2591ba676afd940d53fe852e40 (diff) | |
download | lite-xl-plugin-manager-c2c049448c4357eeb8474f21e880fd7258d90d80.tar.gz lite-xl-plugin-manager-c2c049448c4357eeb8474f21e880fd7258d90d80.zip |
Fixed up plugin manager plugin, moving to optimization.
-rw-r--r-- | plugins/plugin_manager/init.lua | 80 | ||||
-rw-r--r-- | plugins/plugin_manager/plugin_view.lua | 6 | ||||
-rw-r--r-- | src/lpm.c | 1 | ||||
-rw-r--r-- | src/lpm.lua | 6 |
4 files changed, 47 insertions, 46 deletions
diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua index 5472798..7a9a494 100644 --- a/plugins/plugin_manager/init.lua +++ b/plugins/plugin_manager/init.lua @@ -126,20 +126,20 @@ end function PluginManager:refresh() local prom = Promise.new() - run({ "plugin", "list" }):done(function(plugins) - self.plugins = json.decode(plugins)["plugins"] - table.sort(self.plugins, function(a,b) return a.name < b.name end) - self.valid_plugins = {} - for i, plugin in ipairs(self.plugins) do - if plugin.status ~= "incompatible" then - table.insert(self.valid_plugins, plugin) - if plugin.name == "plugin_manager" and plugin.status == "installed" then - plugin.status = "special" + run({ "list" }):done(function(addons) + self.addons = json.decode(addons)["addons"] + table.sort(self.addons, function(a,b) return a.id < b.id end) + self.valid_addons = {} + for i, addon in ipairs(self.addons) do + if addon.status ~= "incompatible" then + table.insert(self.valid_addons, addon) + if addon.id == "plugin_manager" and addon.status == "installed" then + addon.status = "special" end end end self.last_refresh = os.time() - prom:resolve(plugins) + prom:resolve(addons) run({ "repo", "list" }):done(function(repositories) self.repositories = json.decode(repositories)["repositories"] end) @@ -148,13 +148,13 @@ function PluginManager:refresh() end -function PluginManager:get_plugins() +function PluginManager:get_addons() local prom = Promise.new() - if self.plugins then - prom:resolve(self.plugins) + if self.addons then + prom:resolve(self.addons) else self:refresh():done(function() - prom:resolve(self.plugins) + prom:resolve(self.addons) end) end return prom @@ -162,7 +162,7 @@ end local function run_stateful_plugin_command(plugin_manager, cmd, arg) local promise = Promise.new() - run({ "plugin", cmd, arg }):done(function(result) + run({ cmd, arg }):done(function(result) if config.plugins.plugin_manager.restart_on_change then command.perform("core:restart") else @@ -173,14 +173,14 @@ local function run_stateful_plugin_command(plugin_manager, cmd, arg) 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:install(addon) return run_stateful_plugin_command(self, "install", addon.id .. (addon.version and (":" .. addon.version) or "")) end +function PluginManager:uninstall(addon) return run_stateful_plugin_command(self, "uninstall", addon.id) end +function PluginManager:reinstall(addon) return run_stateful_plugin_command(self, "reinstall", addon.id) end -function PluginManager:get_plugin(name_and_version) +function PluginManager:get_addon(name_and_version) local promise = Promise.new() - PluginManager:get_plugins():done(function() + PluginManager:get_addons():done(function() local s = name_and_version:find(":") local name, version = name_and_version, nil if s then @@ -188,9 +188,9 @@ function PluginManager:get_plugin(name_and_version) version = name_and_version:sub(s+1) end local match = false - for i, plugin in ipairs(PluginManager.plugins) do - if not plugin.mod_version or tostring(plugin.mod_version) == tostring(MOD_VERSION) and (plugin.version == version or version == nil) then - promise:resolve(plugin) + for i, addon in ipairs(PluginManager.addons) do + if not addon.mod_version or tostring(addon.mod_version) == tostring(MOD_VERSION) and (addon.version == version or version == nil) then + promise:resolve(addon) match = true break end @@ -205,13 +205,13 @@ PluginManager.view = require "plugins.plugin_manager.plugin_view" command.add(nil, { ["plugin-manager:install"] = function() - PluginManager:get_plugins() + PluginManager:get_addons() core.command_view:enter("Enter plugin name", function(name) - PluginManager:get_plugin(name):done(function(plugin) + PluginManager:get_addon(name):done(function(addon) core.log("Attempting to install plugin " .. name .. "...") - PluginManager:install(plugin):done(function() - core.log("Successfully installed plugin " .. plugin.name .. ".") + PluginManager:install(addon):done(function() + core.log("Successfully installed plugin " .. addon.id .. ".") end) end):fail(function() core.error("Unknown plugin " .. name .. ".") @@ -219,10 +219,10 @@ command.add(nil, { end, function(text) local items = {} - if not PluginManager.plugins then return end - for i, plugin in ipairs(PluginManager.plugins) do - if not plugin.mod_version or tostring(plugin.mod_version) == tostring(MOD_VERSION) and plugin.status == "available" then - table.insert(items, plugin.name .. ":" .. plugin.version) + if not PluginManager.addons then return end + for i, addon in ipairs(PluginManager.addons) do + if not addon.mod_version or tostring(addon.mod_version) == tostring(MOD_VERSION) and addon.status == "available" then + table.insert(items, addon.id .. ":" .. addon.version) end end return common.fuzzy_match(items, text) @@ -230,13 +230,13 @@ command.add(nil, { ) end, ["plugin-manager:uninstall"] = function() - PluginManager:get_plugins() + PluginManager:get_addons() core.command_view:enter("Enter plugin name", function(name) - PluginManager:get_plugin(name):done(function(plugin) - core.log("Attempting to uninstall plugin " .. plugn.name .. "...") - PluginManager:install(plugin):done(function() - core.log("Successfully uninstalled plugin " .. plugin.name .. ".") + PluginManager:get_addon(name):done(function(addon) + core.log("Attempting to uninstall plugin " .. addon.id .. "...") + PluginManager:install(addon):done(function() + core.log("Successfully uninstalled plugin " .. addon.id .. ".") end) end):fail(function() core.error("Unknown plugin " .. name .. ".") @@ -244,10 +244,10 @@ command.add(nil, { end, function(text) local items = {} - if not PluginManager.plugins then return end - for i, plugin in ipairs(PluginManager.plugins) do - if plugin.status == "installed" then - table.insert(items, plugin.name .. ":" .. plugin.version) + if not PluginManager.addons then return end + for i, addon in ipairs(PluginManager.addons) do + if addon.status == "installed" then + table.insert(items, addon.id .. ":" .. addon.version) end end return common.fuzzy_match(items, text) diff --git a/plugins/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua index 4cc2502..a7d5ec7 100644 --- a/plugins/plugin_manager/plugin_view.lua +++ b/plugins/plugin_manager/plugin_view.lua @@ -33,7 +33,7 @@ function PluginView:new() PluginView.super.new(self) self.scrollable = true self.show_incompatible_plugins = false - self.plugin_table_columns = { "Name", "Version", "Modversion", "Status", "Tags", "Author", "Description" } + self.plugin_table_columns = { "ID", "Name", "Version", "Type", "Modversion", "Status", "Tags", "Author", "Description" } self.hovered_plugin = nil self.hovered_plugin_idx = nil self.selected_plugin = nil @@ -48,7 +48,7 @@ function PluginView:new() end local function get_plugin_text(plugin) - return plugin.name, plugin.version, plugin.mod_version, plugin.status, join(", ", plugin.tags), plugin.author or "unknown", plugin.description-- (plugin.description or ""):gsub("%[[^]+%]%([^)]+%)", "") + return plugin.id, (plugin.name or plugin.id), plugin.version, plugin.type, plugin.mod_version, plugin.status, join(", ", plugin.tags), plugin.author or "unknown", plugin.description-- (plugin.description or ""):gsub("%[[^]+%]%([^)]+%)", "") end @@ -112,7 +112,7 @@ end function PluginView:get_plugins() - return self.show_incompatible_plugins and self.plugin_manager.plugins or self.plugin_manager.valid_plugins + return self.show_incompatible_plugins and self.plugin_manager.addons or self.plugin_manager.valid_addons end @@ -969,6 +969,7 @@ int lpm_flock(lua_State* L) { UnlockFile(file, 0, 0, 1, 0); CloseHandle(file); #else + flock(fd, LOCK_UN); close(fd); #endif if (err) diff --git a/src/lpm.lua b/src/lpm.lua index b100d43..a950e27 100644 --- a/src/lpm.lua +++ b/src/lpm.lua @@ -1478,11 +1478,11 @@ end local function lpm_addon_list(type, id) local max_id = 4 - local result = { addons = { } } + local result = { [(type or "addon") .. "s"] = { } } for j,addon in ipairs(common.grep(system_bottle:all_addons(), function(p) return (not type or p.type == type) and (not id or p.id:find(id)) end)) do max_id = math.max(max_id, #addon.id) local repo = addon.repository - table.insert(result.addons, { + table.insert(result[(type or "addon") .. "s"], { id = addon.id, status = addon.repository and (addon:is_installed(system_bottle) and "installed" or (system_bottle.lite_xl:is_compatible(addon) and "available" or "incompatible")) or (addon:is_bundled(system_bottle) and "bundled" or (addon:is_core(system_bottle) and "core" or (addon:is_upgradable(system_bottle) and "upgradable" or "orphan"))), version = "" .. addon.version, @@ -1705,7 +1705,7 @@ It has the following commands: path can be specifeid. lpm lite-xl list Lists all installed versions of lite-xl. - lpm run <version> [...addons] Sets up a "bottle" to run the specified + lpm run <version> [...addons] Sets up a "bottle" to run the specified lite version, with the specified addons and then opens it. lpm describe [bottle] Describes the bottle specified in the form |