diff options
-rw-r--r-- | plugins/plugin_manager/init.lua | 2 | ||||
-rw-r--r-- | plugins/plugin_manager/plugin_view.lua | 17 | ||||
-rw-r--r-- | src/lpm.lua | 30 |
3 files changed, 28 insertions, 21 deletions
diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua index 82e5442..eea9efb 100644 --- a/plugins/plugin_manager/init.lua +++ b/plugins/plugin_manager/init.lua @@ -80,7 +80,7 @@ end local function run(cmd, progress) table.insert(cmd, 1, config.plugins.plugin_manager.lpm_binary_path) table.insert(cmd, "--json") - table.insert(cmd, "--mod-version=" .. MOD_VERSION_MAJOR) + table.insert(cmd, "--mod-version=" .. (rawget(_G, "MOD_VERSION") or MOD_VERSION_STRING)) -- #workaround hack for new system. table.insert(cmd, "--quiet") table.insert(cmd, "--progress") table.insert(cmd, "--userdir=" .. USERDIR) diff --git a/plugins/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua index a00b5da..98dcc7b 100644 --- a/plugins/plugin_manager/plugin_view.lua +++ b/plugins/plugin_manager/plugin_view.lua @@ -34,13 +34,13 @@ function PluginView:new() self.scrollable = true self.progress = nil self.show_incompatible_plugins = false - self.plugin_table_columns = { "ID", "Name", "Version", "Type", "Modversion", "Status", "Tags", "Author", "Description" } + self.plugin_table_columns = { "Name", "Version", "Type", "Status", "Tags", "Author", "Description" } self.hovered_plugin = nil self.hovered_plugin_idx = nil self.selected_plugin = nil self.selected_plugin_idx = nil self.initialized = false - self.offset_y = 0 + self.offset_y = 1 self.plugin_manager = require "plugins.plugin_manager" self.progress_callback = function(progress) self.progress = progress @@ -54,7 +54,7 @@ function PluginView:new() end local function get_plugin_text(plugin) - 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("%[[^]+%]%([^)]+%)", "") + return (plugin.name or plugin.id), (plugin.status == "core" and VERSION or plugin.version), plugin.type, plugin.status, join(", ", plugin.tags), plugin.author or "unknown", plugin.description-- (plugin.description or ""):gsub("%[[^]+%]%([^)]+%)", "") end @@ -96,7 +96,7 @@ function PluginView:on_mouse_moved(x, y, dx, dy) 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.offset_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 @@ -167,14 +167,15 @@ function PluginView:draw() local ox, oy = self:get_content_offset() - oy = oy + (lh + style.padding.y) * self.offset_y - core.push_clip_rect(self.position.x, self.position.y + (lh + style.padding.y) * self.offset_y, self.size.x, self.size.y) + oy = oy + lh * self.offset_y + local x, y = ox + style.padding.x, oy for i, v in ipairs(self.plugin_table_columns) do - common.draw_text(style.font, style.accent, v, "left", x, y, self.widths[i], lh) + common.draw_text(style.font, style.accent, v, "left", x, self.position.y, self.widths[i], lh) x = x + self.widths[i] + style.padding.x end - oy = oy + lh + + core.push_clip_rect(self.position.x, self.position.y + lh * self.offset_y, self.size.x, self.size.y) for i, plugin in ipairs(self:get_plugins()) do local x, y = ox, oy if y + lh >= self.position.y and y <= self.position.y + self.size.y then diff --git a/src/lpm.lua b/src/lpm.lua index 0f71211..c1924a0 100644 --- a/src/lpm.lua +++ b/src/lpm.lua @@ -454,6 +454,7 @@ function common.chdir(dir, callback) if not status then error(err) end end +local LATEST_MOD_VERSION = "3.0.0" local HOME, USERDIR, CACHEDIR, JSON, VERBOSE, FILTRATION, MOD_VERSION, QUIET, FORCE, AUTO_PULL_REMOTES, ARCH, ASSUME_YES, NO_INSTALL_OPTIONAL, TMPDIR, DATADIR, BINARY, POST, PROGRESS, repositories, lite_xls, system_bottle, progress_bar_label, write_progress_bar local function engage_locks(func, err) @@ -542,11 +543,11 @@ local function compare_version(a, b) -- compares semver local _, _, majorb, minorb, revisionb = tostring(b):find("(%d+)%.?(%d*)%.?(%d*)") if majora == nil then error("can't parse version " .. a) end if majorb == nil then error("can't parse version " .. b) end - majora, minora, revisiona = majora or 0, minora or 0, revisiona or 0 - majorb, minorb, revisionb = majorb or 0, minorb or 0, revisionb or 0 - if majora ~= majorb then return tonumber(majora) < tonumber(majorb) and -1 or 1 end - if minora ~= minorb then return tonumber(minora) < tonumber(minorb) and -1 or 1 end - if revisiona ~= revisionb then return tonumber(revisiona) < tonumber(revisionb) and -1 or 1 end + majora, minora, revisiona = tonumber(majora) or 0, tonumber(minora) or 0, tonumber(revisiona) or 0 + majorb, minorb, revisionb = tonumber(majorb) or 0, tonumber(minorb) or 0, tonumber(revisionb) or 0 + if majora ~= majorb then return majora < majorb and -3 or 3 end + if minora ~= minorb then return minora < minorb and -2 or 2 end + if revisiona ~= revisionb then return revisiona < revisionb and -1 or 1 end return 0 end @@ -560,6 +561,11 @@ local function match_version(version, pattern) return version == pattern end +local function compatible_modversion(lite_xl_modversion, addon_modversion) + local result = compare_version(lite_xl_modversion, addon_modversion) + return result >= 0 and result < 3 +end + -- There can exist many different versions of an addon. All statuses are relative to a particular lite bottle. -- available: Addon is available in a repository, and can be installed. There is no comparable version on the system. @@ -928,7 +934,7 @@ function Repository:generate_manifest(repo_id) if repo_id and name == "init" then name = repo_id end if name ~= "init" then local type = folder == "colors" and "color" or (folder == "libraries" and "library" or "plugin") - local addon = { description = nil, id = name:lower():gsub("[^a-z0-9%-_]", ""), name = name, mod_version = 3, version = "0.1", path = (filename ~= "init" and (addon_dir .. file) or nil), type = type } + local addon = { description = nil, id = name:lower():gsub("[^a-z0-9%-_]", ""), name = name, mod_version = LATEST_MOD_VERSION, version = "0.1", path = (filename ~= "init" and (addon_dir .. file) or nil), type = type } for line in io.lines(path .. addon_dir .. PATHSEP .. file) do local _, _, mod_version = line:find("%-%-.*mod%-version:%s*(%w+)") if mod_version then addon.mod_version = mod_version end @@ -947,7 +953,7 @@ function Repository:generate_manifest(repo_id) end for k, v in pairs(addon_map) do if not v.addon then - table.insert(addons, common.merge({ mod_version = 3, version = "0.1" }, v)) + table.insert(addons, common.merge({ mod_version = LATEST_MOD_VERSION, version = "0.1" }, v)) end end table.sort(addons, function(a,b) return a.id:lower() < b.id:lower() end) @@ -1059,7 +1065,7 @@ end function LiteXL:is_system() return system_bottle and system_bottle.lite_xl == self end function LiteXL:is_local() return not self.repository and self.path end -function LiteXL:is_compatible(addon) return not addon.mod_version or compare_version(self.mod_version, addon.mod_version) == 0 end +function LiteXL:is_compatible(addon) return not addon.mod_version or compatible_modversion(self.mod_version, addon.mod_version) end function LiteXL:is_installed() return system.stat(self.local_path) ~= nil end function LiteXL:install() @@ -1258,7 +1264,7 @@ function Bottle:get_addon(id, version, filter) end end if (addon.id == id or (wildcard and addon.id:find("^" .. id:sub(1, #id - 1)))) and match_version(addon.version, version) then - if (not filter.mod_version or not addon.mod_version or tonumber(addon.mod_version) == tonumber(filter.mod_version)) then + if (not filter.mod_version or not addon.mod_version or compatible_modversion(filter.mod_version, addon.mod_version)) then table.insert(candidates, addon) end end @@ -1354,7 +1360,7 @@ local function lpm_lite_xl_add(version, path) if not path then error("requires a path") end if not system.stat(path .. PATHSEP .. "lite-xl") then error("can't find " .. path .. PATHSEP .. "lite-xl") end if not system.stat(path .. PATHSEP .. "data") then error("can't find " .. path .. PATHSEP .. "data") end - table.insert(lite_xls, LiteXL.new(nil, { version = version, path = path:gsub(PATHSEP .. "$", ""), mod_version = MOD_VERSION or 3 })) + table.insert(lite_xls, LiteXL.new(nil, { version = version, path = path:gsub(PATHSEP .. "$", ""), mod_version = MOD_VERSION or LATEST_MOD_VERSION })) lpm_lite_xl_save() end @@ -2023,7 +2029,7 @@ not commonly used publically. if system_lite_xl then error("can't find existing system lite (does " .. system_lite_xl.binary_path .. " exist? was it moved?); run `lpm purge`, or specify --binary and --datadir.") end local lite_xl_datadirs = { DATADIR, directory:find(PATHSEP .. "bin$") and common.dirname(directory .. PATHSEP .. "share" .. PATHSEP .. "lite-xl"), directory .. PATHSEP .. "data" } local lite_xl_datadir = common.first(lite_xl_datadirs, function(p) return p and system.stat(p) end) - system_lite_xl = LiteXL.new(nil, { path = directory, datadir_path = lite_xl_datadir, binary_path = lite_xl_binary, mod_version = MOD_VERSION or 3, version = "system", tags = { "system", "local" } }) + system_lite_xl = LiteXL.new(nil, { path = directory, datadir_path = lite_xl_datadir, binary_path = lite_xl_binary, mod_version = MOD_VERSION or LATEST_MOD_VERSION, version = "system", tags = { "system", "local" } }) table.insert(lite_xls, system_lite_xl) lpm_lite_xl_save() else @@ -2031,7 +2037,7 @@ not commonly used publically. end system_bottle = Bottle.new(system_lite_xl, nil, true) else - system_bottle = Bottle.new(LiteXL.new(nil, { mod_version = MOD_VERSION or 3, version = "system", tags = { "system", "local" } }), nil, true) + system_bottle = Bottle.new(LiteXL.new(nil, { mod_version = MOD_VERSION or LATEST_MOD_VERSION, version = "system", tags = { "system", "local" } }), nil, true) end if not system_bottle then system_bottle = Bottle.new(nil, nil, true) end end, error_handler) |