Skip to content

Commit 5a79762

Browse files
committed
refactor: remove automatic dev server reboot on theme changes and simplify theme state management
1 parent 7582cc7 commit 5a79762

5 files changed

Lines changed: 56 additions & 65 deletions

File tree

bin/lib/installWizardFlow.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,13 @@ export async function executeInstallPlan(ctx) {
331331
ctx.setConfigRestartHintTimer(null)
332332
}
333333
if (ctx.isDevServerUp()) {
334-
if (nextTheme !== config.theme) {
335-
ctx.rebootDevServer()
336-
} else {
337-
ctx.setConfigRestartHintUntil(Date.now() + 5000)
338-
ctx.setConfigRestartHintTimer(setTimeout(() => {
339-
ctx.setConfigRestartHintUntil(0)
340-
ctx.setConfigRestartHintTimer(null)
341-
ctx.renderClient()
342-
ctx.screen.render()
343-
}, 5000))
344-
}
334+
ctx.setConfigRestartHintUntil(Date.now() + 5000)
335+
ctx.setConfigRestartHintTimer(setTimeout(() => {
336+
ctx.setConfigRestartHintUntil(0)
337+
ctx.setConfigRestartHintTimer(null)
338+
ctx.renderClient()
339+
ctx.screen.render()
340+
}, 5000))
345341
}
346342

347343
ctx.renderAll()
@@ -689,17 +685,13 @@ export async function runStartupInstallFlow(ctx, { isStartup = false } = {}) {
689685
ctx.setConfigRestartHintTimer(null)
690686
}
691687
if (ctx.isDevServerUp()) {
692-
if (nextTheme !== config.theme) {
693-
ctx.rebootDevServer()
694-
} else {
695-
ctx.setConfigRestartHintUntil(Date.now() + 5000)
696-
ctx.setConfigRestartHintTimer(setTimeout(() => {
697-
ctx.setConfigRestartHintUntil(0)
698-
ctx.setConfigRestartHintTimer(null)
699-
ctx.renderClient()
700-
ctx.screen.render()
701-
}, 5000))
702-
}
688+
ctx.setConfigRestartHintUntil(Date.now() + 5000)
689+
ctx.setConfigRestartHintTimer(setTimeout(() => {
690+
ctx.setConfigRestartHintUntil(0)
691+
ctx.setConfigRestartHintTimer(null)
692+
ctx.renderClient()
693+
ctx.screen.render()
694+
}, 5000))
703695
}
704696

705697
ctx.renderAll()

go/tui/helpers.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,17 @@ func catalogSourceLabel(item bridge.CatalogEntry, localGitDirs map[string]bool)
809809
return "—"
810810
}
811811

812+
// activeThemeName returns the currently selected theme (pending overrides saved config).
813+
func activeThemeName(ctx *bridge.WorkspaceContext, pendingTheme *string) string {
814+
if pendingTheme != nil {
815+
return *pendingTheme
816+
}
817+
if ctx != nil && ctx.Config.Theme != nil {
818+
return *ctx.Config.Theme
819+
}
820+
return ""
821+
}
822+
812823
func (m *TuiModel) getInstallMethods(pkg *bridge.CatalogEntry) []InstallMethod {
813824
var methods []InstallMethod
814825

go/tui/helpers_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,27 @@ func TestCatalogSourceLabel(t *testing.T) {
7171
})
7272
}
7373
}
74+
75+
func TestActiveThemeName(t *testing.T) {
76+
nova := "@owdproject/theme-nova"
77+
gnome := "@owdproject/theme-gnome"
78+
ctx := &bridge.WorkspaceContext{
79+
Config: bridge.Config{Theme: &nova},
80+
}
81+
82+
if got := activeThemeName(ctx, nil); got != nova {
83+
t.Fatalf("expected saved theme %q, got %q", nova, got)
84+
}
85+
86+
if got := activeThemeName(ctx, &gnome); got != gnome {
87+
t.Fatalf("expected pending theme %q, got %q", gnome, got)
88+
}
89+
90+
if got := activeThemeName(nil, &gnome); got != gnome {
91+
t.Fatalf("expected pending theme without ctx %q, got %q", gnome, got)
92+
}
93+
94+
if got := activeThemeName(nil, nil); got != "" {
95+
t.Fatalf("expected empty theme, got %q", got)
96+
}
97+
}

go/tui/tui.go

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,6 @@ func (m *TuiModel) loadCatalogCmd(force bool) tea.Cmd {
9999
}
100100
}
101101

102-
func (m *TuiModel) rebootServerCmd() tea.Cmd {
103-
return func() tea.Msg {
104-
m.runtime.msgChan <- logLineMsg("ℹ Theme change detected. Rebooting dev server…")
105-
var metaDir string
106-
if m.ctx != nil {
107-
metaDir = m.ctx.Paths.MetaDir
108-
}
109-
stopServeTaskSync(m.workspaceRoot, metaDir, m.runtime)
110-
time.Sleep(1500 * time.Millisecond)
111-
m.RunServeTask()
112-
return nil
113-
}
114-
}
115-
116102
func (m *TuiModel) checkServerStatusCmd() tea.Cmd {
117103
return func() tea.Msg {
118104
if m.ctx == nil {
@@ -317,13 +303,10 @@ func (m *TuiModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
317303
if len(items) > 0 && m.selectedIndex < len(items) {
318304
pkg := items[m.selectedIndex]
319305
if m.activeTab == 3 { // Themes (radiobox)
320-
active := false
321-
if m.ctx != nil && m.ctx.Config.Theme != nil && *m.ctx.Config.Theme == pkg.Name {
322-
active = true
323-
}
324-
if active {
306+
current := activeThemeName(m.ctx, m.pendingTheme)
307+
if current == pkg.Name && m.pendingTheme != nil {
325308
m.pendingTheme = nil
326-
} else {
309+
} else if current != pkg.Name {
327310
themeName := pkg.Name
328311
m.pendingTheme = &themeName
329312
}
@@ -395,15 +378,6 @@ func (m *TuiModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
395378
m.err = msg.Err
396379
m.statusMsg = fmt.Sprintf("Error loading workspace: %v", msg.Err)
397380
} else {
398-
themeChanged := false
399-
if m.ctx != nil && m.ctx.Config.Theme != nil && msg.Ctx.Config.Theme != nil {
400-
if *m.ctx.Config.Theme != *msg.Ctx.Config.Theme {
401-
themeChanged = true
402-
}
403-
} else if (m.ctx != nil && m.ctx.Config.Theme == nil && msg.Ctx.Config.Theme != nil) || (m.ctx != nil && m.ctx.Config.Theme != nil && msg.Ctx.Config.Theme == nil) {
404-
themeChanged = true
405-
}
406-
407381
m.ctx = msg.Ctx
408382
m.statusMsg = "Workspace loaded."
409383

@@ -413,12 +387,6 @@ func (m *TuiModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
413387
m.StartLogTailer(logPath)
414388
}
415389

416-
if themeChanged && m.serverRunning {
417-
m.statusMsg = "Rebooting server for theme change…"
418-
m.activeTask = TaskServe
419-
return m, m.rebootServerCmd()
420-
}
421-
422390
return m, m.checkServerStatusCmd()
423391
}
424392

@@ -505,6 +473,9 @@ func (m *TuiModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
505473
if msg.Success {
506474
m.statusMsg = "Task completed."
507475
m.addLog("✓ Wizard completed successfully")
476+
if m.serverRunning {
477+
m.addLog("ℹ desktop.config.ts updated — Nuxt restarts automatically (see dev server log)")
478+
}
508479

509480
if m.startServerAfterSetup {
510481
m.startServerAfterSetup = false

go/tui/view.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,7 @@ func (m *TuiModel) renderCatalogRow(item bridge.CatalogEntry, selected bool, w,
358358
// ── Badge (checkbox / radiobox) ─────────────────────────────
359359
var badge string
360360
if item.Kind == "theme" {
361-
active := false
362-
if m.ctx != nil && m.ctx.Config.Theme != nil && *m.ctx.Config.Theme == item.Name {
363-
active = true
364-
}
365-
if m.pendingTheme != nil && *m.pendingTheme == item.Name {
366-
active = true
367-
}
368-
if active {
361+
if activeThemeName(m.ctx, m.pendingTheme) == item.Name {
369362
badge = accentStyle.Render("◉")
370363
} else {
371364
badge = subtleStyle.Render("○")

0 commit comments

Comments
 (0)