Skip to content

Commit eec1654

Browse files
committed
refactor(tui): resolve concurrency races and improve pkill process scoping
1 parent fd70778 commit eec1654

2 files changed

Lines changed: 273 additions & 136 deletions

File tree

go/tui/handlers.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,15 @@ func (m *TuiModel) triggerUpdate(pkg *bridge.CatalogEntry) (tea.Model, tea.Cmd)
440440
m.statusMsg = fmt.Sprintf("Updating %s…", pkg.ShortName)
441441
m.addLog(fmt.Sprintf(">>> Updating %s", pkg.Name))
442442

443+
workspaceRoot := m.workspaceRoot
444+
runtime := m.runtime
445+
pkgName := pkg.Name
446+
short := pkg.ShortName
447+
kind := pkg.Kind
448+
443449
go func() {
444-
short := pkg.ShortName
445450
kindDir := ""
446-
switch pkg.Kind {
451+
switch kind {
447452
case "app":
448453
kindDir = "apps"
449454
case "module":
@@ -452,23 +457,23 @@ func (m *TuiModel) triggerUpdate(pkg *bridge.CatalogEntry) (tea.Model, tea.Cmd)
452457
kindDir = "themes"
453458
}
454459
if kindDir != "" {
455-
pkgPath := filepath.Join(m.workspaceRoot, kindDir, short)
460+
pkgPath := filepath.Join(workspaceRoot, kindDir, short)
456461
gitDir := filepath.Join(pkgPath, ".git")
457462
if _, err := os.Stat(gitDir); err == nil {
458-
m.runtime.msgChan <- logLineMsg(">>> Local Git repository detected. Running git pull…")
459-
m.runProcessAndStreamLogs(pkgPath, "git", []string{"pull"})
463+
runtime.msgChan <- logLineMsg(">>> Local Git repository detected. Running git pull…")
464+
runtime.runProcessAndStreamLogs(pkgPath, "git", []string{"pull"})
460465
return
461466
}
462467
}
463468

464-
m.runtime.msgChan <- logLineMsg(fmt.Sprintf(">>> Running pnpm install %s@latest…", pkg.Name))
465-
if err := m.runProcessAndStreamLogsSilent(m.workspaceRoot, "pnpm", []string{"install", pkg.Name + "@latest"}); err != nil {
466-
m.runtime.msgChan <- taskFinishedMsg{Success: false, Err: err}
469+
runtime.msgChan <- logLineMsg(fmt.Sprintf(">>> Running pnpm install %s@latest…", pkgName))
470+
if err := runtime.runProcessAndStreamLogsSilent(workspaceRoot, "pnpm", []string{"install", pkgName + "@latest"}); err != nil {
471+
runtime.msgChan <- taskFinishedMsg{Success: false, Err: err}
467472
return
468473
}
469-
m.runtime.msgChan <- logLineMsg(">>> Preparing workspace modules…")
470-
err := m.runProcessAndStreamLogsSilent(m.workspaceRoot, "pnpm", []string{"run", "prepare:modules"})
471-
m.runtime.msgChan <- taskFinishedMsg{Success: err == nil, Err: err}
474+
runtime.msgChan <- logLineMsg(">>> Preparing workspace modules…")
475+
err := runtime.runProcessAndStreamLogsSilent(workspaceRoot, "pnpm", []string{"run", "prepare:modules"})
476+
runtime.msgChan <- taskFinishedMsg{Success: err == nil, Err: err}
472477
}()
473478
return m, nil
474479
}

0 commit comments

Comments
 (0)