From e412a2ffbf65ce18c0bc312272b43e0f96ec4250 Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Tue, 11 Apr 2023 09:06:49 +0200 Subject: [PATCH] Move to the next view when we are done elevating --- internal/ui_main_events.go | 50 +++++++++++++++++++++++++---------- internal/ui_main_functions.go | 15 +---------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/internal/ui_main_events.go b/internal/ui_main_events.go index 4314d70..398780d 100644 --- a/internal/ui_main_events.go +++ b/internal/ui_main_events.go @@ -3,6 +3,8 @@ package internal import ( "encoding/base64" + "github.com/HikariKnight/quickpassthrough/internal/logger" + "github.com/HikariKnight/quickpassthrough/pkg/command" tea "github.com/charmbracelet/bubbletea" ) @@ -12,7 +14,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case tea.KeyMsg: // If we are not done - if m.focused != INSTALL { + if m.focused != INSTALL && m.focused != DONE { // Setup keybindings switch msg.String() { case "ctrl+c", "q": @@ -22,9 +24,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case "enter": if m.width != 0 { // Process the selected item, if the return value is true then exit the application - if m.processSelection() { - return m, tea.ExitAltScreen - } + m.processSelection() } case "ctrl+z", "backspace": // Go backwards in the model @@ -49,17 +49,39 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Quit case "enter": - // Start installation and send the password to the command - m.install( - base64.StdEncoding.EncodeToString( - []byte( - m.authDialog.Value(), - ), - ), - ) + // If we are on the INSTALL dialog + if m.focused == INSTALL { + // Write to logger + logger.Printf("Getting authentication token by elevating with sudo once") - // Blank the password field - m.authDialog.SetValue("") + // Elevate with sudo + command.Elevate( + base64.StdEncoding.EncodeToString( + []byte( + m.authDialog.Value(), + ), + ), + ) + + // Write to logger + logger.Printf("Attempting to free hash from memory") + + // Blank the password field + m.authDialog.SetValue("") + + // Start installation and send the password to the command + m.install() + + // Move to the DONE dialog + m.focused++ + + // Exit the alt screen as the output on the done dialog needs to be scrollable + return m, tea.ExitAltScreen + + } else { + // Quit the application if we are on a different view + return m, tea.Quit + } } // Issue an UI update diff --git a/internal/ui_main_functions.go b/internal/ui_main_functions.go index f843443..4b8f058 100644 --- a/internal/ui_main_functions.go +++ b/internal/ui_main_functions.go @@ -8,7 +8,6 @@ import ( "github.com/HikariKnight/ls-iommu/pkg/errorcheck" "github.com/HikariKnight/quickpassthrough/internal/configs" "github.com/HikariKnight/quickpassthrough/internal/logger" - "github.com/HikariKnight/quickpassthrough/pkg/command" "github.com/HikariKnight/quickpassthrough/pkg/fileio" ) @@ -145,22 +144,10 @@ func (m *model) processSelection() bool { // This function starts the install process // It takes 1 auth string as variable -func (m *model) install(auth string) { +func (m *model) install() { // Get the config config := configs.GetConfig() - // Write to logger - logger.Printf("Getting authentication token by elevating with sudo once") - - // Elevate to sudo - command.Elevate(auth) - - // Write to logger - logger.Printf("Attempting to free hash from memory") - - // Blank out the variable - auth = "" - // Based on the bootloader, setup the configuration if config.Bootloader == "kernelstub" { // Write to logger