feat: add selected update installs and polished UI

This commit is contained in:
2026-05-03 23:04:30 +02:00
parent 137290e3d7
commit e8d4d2e400
4 changed files with 211 additions and 13 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net"
"net/http"
@@ -50,6 +51,10 @@ type ignoreRequest struct {
Ignored bool `json:"ignored"`
}
type installRequest struct {
Packages []string `json:"packages"`
}
func Run(configPath, statePath string, openBrowser bool) error {
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
@@ -209,7 +214,15 @@ func (s *Server) install(w http.ResponseWriter, r *http.Request) {
return
}
name, args, err := terminalCommand(cfg)
var req installRequest
if r.Body != nil {
if err := json.NewDecoder(r.Body).Decode(&req); err != nil && !errors.Is(err, io.EOF) {
writeError(w, err, http.StatusBadRequest)
return
}
}
name, args, err := terminalCommand(cfg, req.Packages)
if err != nil {
writeError(w, err, http.StatusBadRequest)
return
@@ -242,7 +255,7 @@ func setIgnored(names []string, name string, ignored bool) []string {
}
func systemStatus(cfg config.Config) SystemStatus {
terminal, _, _ := terminalCommand(cfg)
terminal, _, _ := terminalCommand(cfg, nil)
return SystemStatus{
AURHelper: updater.AURHelper(),
Terminal: terminal,
@@ -298,10 +311,22 @@ func kernelVersion() string {
return strings.TrimSpace(string(out))
}
func terminalCommand(cfg config.Config) (string, []string, error) {
func terminalCommand(cfg config.Config, packages []string) (string, []string, error) {
updateCommand := "lazy-update-manager update; printf '\\nDone. Press enter to close... '; read _"
if len(packages) > 0 {
selected := shellPackageList(packages)
if selected == "" {
return "", nil, errors.New("no valid packages selected")
}
updateCommand = "sudo pacman -S --needed " + selected + "; printf '\\nDone. Press enter to close... '; read _"
if helper := updater.AURHelper(); helper != "" && cfg.CheckAUR {
updateCommand = helper + " -S --needed " + selected + "; printf '\\nDone. Press enter to close... '; read _"
}
}
if helper := updater.AURHelper(); helper != "" && cfg.CheckAUR {
updateCommand = helper + " -Syu; printf '\\nDone. Press enter to close... '; read _"
if len(packages) == 0 {
updateCommand = helper + " -Syu; printf '\\nDone. Press enter to close... '; read _"
}
}
candidates := []string{}
@@ -334,6 +359,37 @@ func terminalCommand(cfg config.Config) (string, []string, error) {
return "", nil, errors.New("no supported terminal found; set one in settings")
}
func shellPackageList(packages []string) string {
quoted := []string{}
seen := map[string]bool{}
for _, pkg := range packages {
pkg = strings.TrimSpace(pkg)
if pkg == "" || seen[pkg] || !validPackageName(pkg) {
continue
}
seen[pkg] = true
quoted = append(quoted, shellQuote(pkg))
}
return strings.Join(quoted, " ")
}
func validPackageName(value string) bool {
for _, r := range value {
if r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z' || r >= '0' && r <= '9' {
continue
}
if strings.ContainsRune("@._+-", r) {
continue
}
return false
}
return true
}
func shellQuote(value string) string {
return "'" + strings.ReplaceAll(value, "'", "'\\''") + "'"
}
func openURL(url string) error {
switch runtime.GOOS {
case "linux":