fix: correct connect/disconnect button state on connection lifecycle
- Enable disconnect button immediately when connect is clicked, so the user can cancel without waiting for the StateConnecting IPC event. - Disable disconnect button on all error paths in the connect goroutine to restore the default disconnected button state. - Capture ipcClient once at eventLoop start instead of re-reading every iteration, preventing a second onConnect call from making the old event loop jump to the new client and consume events concurrently. - In eventLoop recv error recovery, only reset button states if the current ipcClient still matches the captured one, so a stale disconnection does not clobber the state of a newer session. - Disable connect button in StateReconnecting case (was missing). - Remove WriteOK from daemon startSession: the StateConnecting event already serves as the implicit acknowledgment; the OK response was being read by eventLoop as a no-op event, adding unnecessary noise.
This commit is contained in:
@@ -155,7 +155,6 @@ func (d *daemon) startSession(conn net.Conn, req ipc.Request) {
|
|||||||
d.session = nil
|
d.session = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = ipc.WriteOK(conn)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *daemon) stopSession() {
|
func (d *daemon) stopSession() {
|
||||||
|
|||||||
+12
-1
@@ -75,6 +75,7 @@ func (a *App) onConnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
a.connectBtn.Disable()
|
a.connectBtn.Disable()
|
||||||
|
a.disconnectBtn.Enable()
|
||||||
a.stateLabel.SetText(i18n.T("StateConnecting"))
|
a.stateLabel.SetText(i18n.T("StateConnecting"))
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -85,6 +86,7 @@ func (a *App) onConnect() {
|
|||||||
showError(i18n.T("DlgDaemonError"), err.Error(), a.window)
|
showError(i18n.T("DlgDaemonError"), err.Error(), a.window)
|
||||||
a.stateLabel.SetText(i18n.T("StateDisconnected"))
|
a.stateLabel.SetText(i18n.T("StateDisconnected"))
|
||||||
a.connectBtn.Enable()
|
a.connectBtn.Enable()
|
||||||
|
a.disconnectBtn.Disable()
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -102,6 +104,7 @@ func (a *App) onConnect() {
|
|||||||
a.window)
|
a.window)
|
||||||
a.stateLabel.SetText(i18n.T("StateDisconnected"))
|
a.stateLabel.SetText(i18n.T("StateDisconnected"))
|
||||||
a.connectBtn.Enable()
|
a.connectBtn.Enable()
|
||||||
|
a.disconnectBtn.Disable()
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -121,6 +124,7 @@ func (a *App) onConnect() {
|
|||||||
showError(i18n.T("DlgIPCError"), err.Error(), a.window)
|
showError(i18n.T("DlgIPCError"), err.Error(), a.window)
|
||||||
a.stateLabel.SetText(i18n.T("StateDisconnected"))
|
a.stateLabel.SetText(i18n.T("StateDisconnected"))
|
||||||
a.connectBtn.Enable()
|
a.connectBtn.Enable()
|
||||||
|
a.disconnectBtn.Disable()
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -146,16 +150,21 @@ func (a *App) onDisconnect() {
|
|||||||
|
|
||||||
// eventLoop reads IPC events from the daemon and updates the UI.
|
// eventLoop reads IPC events from the daemon and updates the UI.
|
||||||
func (a *App) eventLoop() {
|
func (a *App) eventLoop() {
|
||||||
for {
|
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
client := a.ipcClient
|
client := a.ipcClient
|
||||||
a.mu.Unlock()
|
a.mu.Unlock()
|
||||||
if client == nil {
|
if client == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
ev, err := client.Recv()
|
ev, err := client.Recv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fyne.Do(func() {
|
fyne.Do(func() {
|
||||||
|
a.mu.Lock()
|
||||||
|
current := a.ipcClient
|
||||||
|
a.mu.Unlock()
|
||||||
|
if current == client {
|
||||||
a.stateLabel.SetText(i18n.T("StateDisconnected"))
|
a.stateLabel.SetText(i18n.T("StateDisconnected"))
|
||||||
a.ipLabel.SetText(i18n.T("IpNone"))
|
a.ipLabel.SetText(i18n.T("IpNone"))
|
||||||
a.uptimeLabel.SetText(i18n.T("UptimeNone"))
|
a.uptimeLabel.SetText(i18n.T("UptimeNone"))
|
||||||
@@ -163,6 +172,7 @@ func (a *App) eventLoop() {
|
|||||||
a.txLabel.SetText(i18n.T("TxZero"))
|
a.txLabel.SetText(i18n.T("TxZero"))
|
||||||
a.connectBtn.Enable()
|
a.connectBtn.Enable()
|
||||||
a.disconnectBtn.Disable()
|
a.disconnectBtn.Disable()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -201,6 +211,7 @@ func (a *App) applyState(state string) {
|
|||||||
a.disconnectBtn.Enable()
|
a.disconnectBtn.Enable()
|
||||||
case stats.StateReconnecting:
|
case stats.StateReconnecting:
|
||||||
a.stateLabel.SetText(i18n.T("StateReconnecting"))
|
a.stateLabel.SetText(i18n.T("StateReconnecting"))
|
||||||
|
a.connectBtn.Disable()
|
||||||
a.disconnectBtn.Enable()
|
a.disconnectBtn.Enable()
|
||||||
case stats.StateDisconnected:
|
case stats.StateDisconnected:
|
||||||
a.stateLabel.SetText(i18n.T("StateDisconnected"))
|
a.stateLabel.SetText(i18n.T("StateDisconnected"))
|
||||||
|
|||||||
Reference in New Issue
Block a user