Move to the next view when we are done elevating

This commit is contained in:
HikariKnight 2023-04-11 09:06:49 +02:00
parent 57895a1901
commit e412a2ffbf
2 changed files with 37 additions and 28 deletions

View file

@ -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,8 +49,13 @@ 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(
// If we are on the INSTALL dialog
if m.focused == INSTALL {
// Write to logger
logger.Printf("Getting authentication token by elevating with sudo once")
// Elevate with sudo
command.Elevate(
base64.StdEncoding.EncodeToString(
[]byte(
m.authDialog.Value(),
@ -58,8 +63,25 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
),
)
// 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

View file

@ -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