Synchronize connection and transmission state

This commit is contained in:
Brandon McGinty (chatgpt)
2026-08-10 00:45:22 -04:00
committed by Brandon McGinty
parent 3efbd019ce
commit 55772fa459
4 changed files with 64 additions and 23 deletions
+28 -3
View File
@@ -31,6 +31,7 @@ type Barnard struct {
Tx bool
AutoTransmit bool // auto-start transmission on connect
Connected bool
stateMutex sync.RWMutex
Ui *uiterm.Ui
UiOutput uiterm.Textview
@@ -149,10 +150,34 @@ func (b *Barnard) setSelectedUserValue(user *gumble.User) {
b.selectedUserMutex.Unlock()
}
func (b *Barnard) isTransmitting() bool {
b.stateMutex.RLock()
defer b.stateMutex.RUnlock()
return b.Tx
}
func (b *Barnard) setTransmitting(transmitting bool) {
b.stateMutex.Lock()
b.Tx = transmitting
b.stateMutex.Unlock()
}
func (b *Barnard) isConnected() bool {
b.stateMutex.RLock()
defer b.stateMutex.RUnlock()
return b.Connected
}
func (b *Barnard) setConnected(connected bool) {
b.stateMutex.Lock()
b.Connected = connected
b.stateMutex.Unlock()
}
func (b *Barnard) StopTransmission() {
if b.Tx {
if b.isTransmitting() {
b.Notify("micdown", "me", "")
b.Tx = false
b.setTransmitting(false)
b.UpdateGeneralStatus(" Idle ", false)
if b.ToneTest {
// Stop the tone generator.
@@ -209,7 +234,7 @@ func (b *Barnard) TreeItemKeyPress(ui *uiterm.Ui, tree *uiterm.Tree, item uiterm
// Update channel mute state
b.setChannelMuted(treeItem.Channel.ID, channelWillBeMuted)
if channelWillBeMuted && b.Client.Self.Channel.ID == treeItem.Channel.ID && b.Tx {
if channelWillBeMuted && b.Client.Self.Channel.ID == treeItem.Channel.ID && b.isTransmitting() {
b.StopTransmission()
}