Skip to content

Commit 5a896d4

Browse files
committed
refactor(sync-server): remove redudant reconnecting boolean from struct
1 parent 720ae4b commit 5a896d4

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

internal/tui/speaker_notes.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ type SpeakerNotesModel struct {
4343
syncClient *SyncClient
4444
slideChangeChan chan int
4545
connectionStatus ConnectionStatus
46-
reconnecting bool
4746
}
4847

4948
type SlideChangeMsg struct {
@@ -67,28 +66,26 @@ func NewSpeakerNotes(rootSlide *Slide) SpeakerNotesModel {
6766
slide = slide.Next
6867
}
6968

70-
// Create sync client to connect to the main presentation
69+
// Attempt to create a sync client to connect to the main presentation
7170
syncClient, err := NewSyncClient()
71+
72+
var status ConnectionStatus
7273
if err != nil {
7374
slog.Warn("Failed to connect to sync server - run the main presentation first", "error", err)
74-
syncClient = nil
75+
status = StatusDisconnectedWaiting
76+
} else {
77+
status = StatusConnected
7578
}
7679

7780
// Create buffered channel for slide changes
7881
slideChangeChan := make(chan int, 10)
7982

80-
status := StatusConnected
81-
if syncClient == nil {
82-
status = StatusDisconnectedWaiting
83-
}
84-
8583
return SpeakerNotesModel{
8684
currentSlide: 0,
8785
slides: slides,
8886
syncClient: syncClient,
8987
slideChangeChan: slideChangeChan,
9088
connectionStatus: status,
91-
reconnecting: false,
9289
}
9390
}
9491

@@ -167,15 +164,13 @@ func (m SpeakerNotesModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
167164
return m, m.waitForSlideChange()
168165
case ReconnectAttemptMsg:
169166
m.connectionStatus = StatusReconnecting
170-
m.reconnecting = true
171167
// Wait a bit before trying again
172168
return m, tea.Tick(time.Millisecond*200, func(time.Time) tea.Msg {
173169
return m.attemptReconnect()()
174170
})
175171
case ReconnectedMsg:
176172
m.syncClient = msg.Client
177173
m.connectionStatus = StatusConnected
178-
m.reconnecting = false
179174
// Start listening for slide changes again
180175
go m.listenForSlideChangesWithReconnect()
181176
return m, m.waitForSlideChange()

0 commit comments

Comments
 (0)