Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/services/brew.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"strings"
"syscall"

"bbrew/internal/models"
)
Expand All @@ -22,10 +23,13 @@ func brewEnv() []string {
}

// brewCommand creates an exec.Cmd for brew with non-interactive environment settings.
// Setsid places the process in its own session so sudo cannot open /dev/tty,
// preventing password prompts from hanging the TUI.
func brewCommand(args ...string) *exec.Cmd {
cmd := exec.Command("brew", args...)
cmd.Stdin = nil
cmd.Env = brewEnv()
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
return cmd
}

Expand All @@ -34,6 +38,7 @@ func brewCommandContext(ctx context.Context, args ...string) *exec.Cmd {
cmd := exec.CommandContext(ctx, "brew", args...)
cmd.Stdin = nil
cmd.Env = brewEnv()
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
return cmd
}

Expand Down
96 changes: 66 additions & 30 deletions internal/services/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,20 @@ func (s *InputService) handleVulnInstallPrompt() {
s.closeModal()
s.layout.GetOutput().Clear()
go func() {
s.layout.GetNotifier().ShowWarning("Installing brew vulns...")
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowWarning("Installing brew vulns...")
})
cmd := brewCommand("install", "homebrew/brew-vulns/brew-vulns") // #nosec G204
if err := ExecuteCommand(cmd, s.outputWriter()); err != nil {
s.layout.GetNotifier().ShowError("Failed to install brew vulns")
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowError("Failed to install brew vulns")
})
return
}
s.appService.vulnsService.(*VulnsService).resetAvailability()
s.layout.GetNotifier().ShowSuccess("brew vulns installed! Press v again to scan.")
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowSuccess("brew vulns installed! Press v again to scan.")
})
}()
},
s.closeModal,
Expand Down Expand Up @@ -435,7 +441,9 @@ func (s *InputService) handleInstallPackageEvent() {
s.closeModal()
s.layout.GetOutput().Clear()
go func() {
s.layout.GetNotifier().ShowWarning(fmt.Sprintf("Installing %s...", info.Name))
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowWarning(fmt.Sprintf("Installing %s...", info.Name))
})
var err error
switch info.Type {
case models.PackageTypeFlatpak:
Expand All @@ -446,12 +454,16 @@ func (s *InputService) handleInstallPackageEvent() {
err = s.brewService.InstallPackage(info, s.outputWriter())
}

if err != nil {
s.layout.GetNotifier().ShowError(fmt.Sprintf("Failed to install %s", info.Name))
return
s.appService.app.QueueUpdateDraw(func() {
if err != nil {
s.layout.GetNotifier().ShowError(fmt.Sprintf("Failed to install %s", info.Name))
return
}
s.layout.GetNotifier().ShowSuccess(fmt.Sprintf("Installed %s", info.Name))
})
if err == nil {
s.appService.forceRefreshResults()
}
s.layout.GetNotifier().ShowSuccess(fmt.Sprintf("Installed %s", info.Name))
s.appService.forceRefreshResults()
}()
}, s.closeModal)
}
Expand All @@ -468,20 +480,26 @@ func (s *InputService) handleRemovePackageEvent() {
s.closeModal()
s.layout.GetOutput().Clear()
go func() {
s.layout.GetNotifier().ShowWarning(fmt.Sprintf("Removing %s...", info.Name))
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowWarning(fmt.Sprintf("Removing %s...", info.Name))
})
var err error
if info.Type == models.PackageTypeFlatpak {
err = s.flatpakService.RemovePackage(info, s.outputWriter())
} else {
err = s.brewService.RemovePackage(info, s.outputWriter())
}

if err != nil {
s.layout.GetNotifier().ShowError(fmt.Sprintf("Failed to remove %s", info.Name))
return
s.appService.app.QueueUpdateDraw(func() {
if err != nil {
s.layout.GetNotifier().ShowError(fmt.Sprintf("Failed to remove %s: may need sudo in terminal", info.Name))
return
}
s.layout.GetNotifier().ShowSuccess(fmt.Sprintf("Removed %s", info.Name))
})
if err == nil {
s.appService.forceRefreshResults()
}
s.layout.GetNotifier().ShowSuccess(fmt.Sprintf("Removed %s", info.Name))
s.appService.forceRefreshResults()
}()
}, s.closeModal)
}
Expand All @@ -498,20 +516,26 @@ func (s *InputService) handleUpdatePackageEvent() {
s.closeModal()
s.layout.GetOutput().Clear()
go func() {
s.layout.GetNotifier().ShowWarning(fmt.Sprintf("Updating %s...", info.Name))
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowWarning(fmt.Sprintf("Updating %s...", info.Name))
})
var err error
if info.Type == models.PackageTypeFlatpak {
err = s.flatpakService.UpdatePackage(info, s.outputWriter())
} else {
err = s.brewService.UpdatePackage(info, s.outputWriter())
}

if err != nil {
s.layout.GetNotifier().ShowError(fmt.Sprintf("Failed to update %s", info.Name))
return
s.appService.app.QueueUpdateDraw(func() {
if err != nil {
s.layout.GetNotifier().ShowError(fmt.Sprintf("Failed to update %s", info.Name))
return
}
s.layout.GetNotifier().ShowSuccess(fmt.Sprintf("Updated %s", info.Name))
})
if err == nil {
s.appService.forceRefreshResults()
}
s.layout.GetNotifier().ShowSuccess(fmt.Sprintf("Updated %s", info.Name))
s.appService.forceRefreshResults()
}()
}, s.closeModal)
}
Expand All @@ -523,21 +547,31 @@ func (s *InputService) handleUpdateAllPackagesEvent() {
s.closeModal()
s.layout.GetOutput().Clear()
go func() {
s.layout.GetNotifier().ShowWarning("Updating all Homebrew packages...")
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowWarning("Updating all Homebrew packages...")
})
if err := s.brewService.UpdateAllPackages(s.outputWriter()); err != nil {
s.layout.GetNotifier().ShowError("Failed to update Homebrew packages")
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowError("Failed to update Homebrew packages")
})
return
}

if s.flatpakService.IsFlatpakInstalled() {
s.layout.GetNotifier().ShowWarning("Updating all Flatpak packages...")
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowWarning("Updating all Flatpak packages...")
})
if err := s.flatpakService.UpdateAllPackages(s.outputWriter()); err != nil {
s.layout.GetNotifier().ShowError("Failed to update Flatpak packages")
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowError("Failed to update Flatpak packages")
})
return
}
}

s.layout.GetNotifier().ShowSuccess("Updated all Packages")
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowSuccess("Updated all Packages")
})
s.appService.forceRefreshResults()
}()
}, s.closeModal)
Expand Down Expand Up @@ -592,21 +626,21 @@ func (s *InputService) handleBatchPackageOperation(op batchOperation) {
pkgName := pkg.Name // Capture for closures

if op.skipCondition(pkg) {
s.layout.GetNotifier().ShowWarning(fmt.Sprintf("[%d/%d] Skipping %s (%s)", current, total, pkgName, op.skipReason))
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowWarning(fmt.Sprintf("[%d/%d] Skipping %s (%s)", current, total, pkgName, op.skipReason))
fmt.Fprintf(s.layout.GetOutput().View(), "[SKIP] %s (%s)\n", pkgName, op.skipReason)
})
continue
}

s.layout.GetNotifier().ShowWarning(fmt.Sprintf("[%d/%d] %s %s...", current, total, op.actionVerb, pkgName))
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowWarning(fmt.Sprintf("[%d/%d] %s %s...", current, total, op.actionVerb, pkgName))
fmt.Fprintf(s.layout.GetOutput().View(), "\n[%s] %s %s...\n", op.actionTag, op.actionVerb, pkgName)
})

if err := op.execute(pkg); err != nil {
s.layout.GetNotifier().ShowError(fmt.Sprintf("[%d/%d] Failed to process %s", current, total, pkgName))
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowError(fmt.Sprintf("[%d/%d] Failed to process %s", current, total, pkgName))
fmt.Fprintf(s.layout.GetOutput().View(), "[ERROR] Failed to process %s: %v\n", pkgName, err)
})
continue
Expand All @@ -617,7 +651,9 @@ func (s *InputService) handleBatchPackageOperation(op batchOperation) {
})
}

s.layout.GetNotifier().ShowSuccess(fmt.Sprintf("Completed! Processed %d packages", total))
s.appService.app.QueueUpdateDraw(func() {
s.layout.GetNotifier().ShowSuccess(fmt.Sprintf("Completed! Processed %d packages", total))
})
s.appService.forceRefreshResults()
}()
}, s.closeModal)
Expand Down
Loading