From f91c4d2671012a52ac0ed988426fe8bbdb1216c9 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 30 Nov 2023 14:19:32 -0500 Subject: Split off loading screen functionality. --- plugins/plugin_manager/plugin_view.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'plugins/plugin_manager/plugin_view.lua') diff --git a/plugins/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua index 9e9d67c..b864675 100644 --- a/plugins/plugin_manager/plugin_view.lua +++ b/plugins/plugin_manager/plugin_view.lua @@ -145,20 +145,23 @@ local function draw_loading_bar(x, y, width, height, percent) renderer.draw_rect(x, y, width * percent, height, style.caret) end +function PluginView:draw_loading_screen(label, percent) + common.draw_text(style.big_font, style.dim, "Loading...", "center", self.position.x, self.position.y, self.size.x, self.size.y) + local width = self.size.x / 2 + local offset_y = self.size.y / 2 + if self.progress then + common.draw_text(style.font, style.dim, label, "center", self.position.x, self.position.y + offset_y + lh, self.size.x, lh) + draw_loading_bar(self.position.x + (self.size.x / 2) - (width / 2), self.position.y + self.size.y / 2 + (lh * 2), width, lh, percent) + end +end + function PluginView:draw() self:draw_background(style.background) local th = style.font:get_height() local lh = th + style.padding.y if not self.initialized or not self.widths then - common.draw_text(style.big_font, style.dim, "Loading...", "center", self.position.x, self.position.y, self.size.x, self.size.y) - local width = self.size.x / 2 - local offset_y = self.size.y / 2 - if self.progress then - common.draw_text(style.font, style.dim, self.progress.label, "center", self.position.x, self.position.y + offset_y + lh, self.size.x, lh) - draw_loading_bar(self.position.x + (self.size.x / 2) - (width / 2), self.position.y + self.size.y / 2 + (lh * 2), width, lh, self.progress.percent) - end - return + return self:draw_loading_screen(self.progress.label, self.progress.percent) end -- cgit v1.2.3 From 7cfcdcea4b4a4984cd6625a60e9fc2a44d0ec9c9 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 30 Nov 2023 14:47:42 -0500 Subject: Added in loading screen for welcome dialog. --- plugins/plugin_manager/init.lua | 16 ++++++++++++++-- plugins/plugin_manager/plugin_view.lua | 6 ++++-- plugins/welcome.lua | 10 +++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) (limited to 'plugins/plugin_manager/plugin_view.lua') diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua index e30d7f6..2fde4e3 100644 --- a/plugins/plugin_manager/init.lua +++ b/plugins/plugin_manager/init.lua @@ -5,6 +5,7 @@ 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 PluginManager = { @@ -128,7 +129,11 @@ local function run(cmd, progress) 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]) + if err then + v[2]:reject(json.decode(err).error) + else + v[2]:reject(err) + end end break end @@ -208,6 +213,8 @@ local function run_stateful_plugin_command(plugin_manager, cmd, args, options) else plugin_manager:refresh(options):forward(promise) end + end):fail(function(arg) + promise:reject(arg) end) return promise end @@ -347,7 +354,7 @@ command.add(nil, { if pcall(require, "plugins.terminal") then local terminal = require "plugins.terminal" command.add(nil, { - ["plugin-manager:session"] = function() + ["plugin-manager:open-session"] = function() local arguments = { "-" } for i,v in ipairs(default_arguments) do table.insert(arguments, v) end local tv = terminal.class(common.merge(config.plugins.terminal, { @@ -359,4 +366,9 @@ if pcall(require, "plugins.terminal") then }) end +keymap.add({ + ['ctrl+shift+1'] = 'plugin-manager:show', + ['ctrl+shift+2'] = 'plugin-manager:open-session' +}) + return PluginManager diff --git a/plugins/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua index b864675..f8f503b 100644 --- a/plugins/plugin_manager/plugin_view.lua +++ b/plugins/plugin_manager/plugin_view.lua @@ -149,7 +149,9 @@ function PluginView:draw_loading_screen(label, percent) common.draw_text(style.big_font, style.dim, "Loading...", "center", self.position.x, self.position.y, self.size.x, self.size.y) local width = self.size.x / 2 local offset_y = self.size.y / 2 - if self.progress then + if label or percent then + local th = style.font:get_height() + local lh = th + style.padding.y common.draw_text(style.font, style.dim, label, "center", self.position.x, self.position.y + offset_y + lh, self.size.x, lh) draw_loading_bar(self.position.x + (self.size.x / 2) - (width / 2), self.position.y + self.size.y / 2 + (lh * 2), width, lh, percent) end @@ -161,7 +163,7 @@ function PluginView:draw() local lh = th + style.padding.y if not self.initialized or not self.widths then - return self:draw_loading_screen(self.progress.label, self.progress.percent) + return self:draw_loading_screen(self.progress and self.progress.label, self.progress and self.progress.percent) end diff --git a/plugins/welcome.lua b/plugins/welcome.lua index a90ea82..f0d0401 100644 --- a/plugins/welcome.lua +++ b/plugins/welcome.lua @@ -98,14 +98,18 @@ command.add(EmptyView, { core.log("Installing addons...") loading = { percent = 0, label = "Initializing..." } core.redraw = true - PluginManager:install({ id = "meta_addons" }, { progress = function(progress) loading = progress end, restart = false }):done(function() + PluginManager:install({ id = "meta_addons" }, { progress = function(progress) + loading = progress + core.redraw = true + end, restart = false }):done(function() loading = false core.log("Addons installed!") terminate_welcome() command.perform("core:restart") end):fail(function(err) - loading = true - core.error(err) + loading = false + core.redraw = true + core.error(err or "Error installing addons.") end) end, ["welcome:open-plugin-manager"] = function() -- cgit v1.2.3