mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-02 03:28:28 -04:00
fix(network): cancel in-flight connection when setting autoconnect
fixes #2882 port 1.5
This commit is contained in:
@@ -744,6 +744,32 @@ func (b *IWDBackend) DisconnectWiFi() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *IWDBackend) abortInFlightConnection(ssid string) {
|
||||
b.stateMutex.Lock()
|
||||
if !b.state.IsConnecting || b.state.ConnectingSSID != ssid {
|
||||
b.stateMutex.Unlock()
|
||||
return
|
||||
}
|
||||
b.state.IsConnecting = false
|
||||
b.state.ConnectingSSID = ""
|
||||
b.state.LastError = ""
|
||||
b.stateMutex.Unlock()
|
||||
|
||||
b.attemptMutex.RLock()
|
||||
att := b.curAttempt
|
||||
b.attemptMutex.RUnlock()
|
||||
|
||||
if att != nil && att.ssid == ssid {
|
||||
att.mu.Lock()
|
||||
att.finalized = true
|
||||
att.mu.Unlock()
|
||||
}
|
||||
|
||||
if err := b.DisconnectWiFi(); err != nil {
|
||||
log.Warnf("[abortInFlightConnection] failed to abort connection to %s: %v", ssid, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *IWDBackend) ForgetWiFiNetwork(ssid string) error {
|
||||
b.stateMutex.RLock()
|
||||
currentSSID := b.state.WiFiSSID
|
||||
@@ -812,6 +838,10 @@ func (b *IWDBackend) SetWiFiAutoconnect(ssid string, autoconnect bool) error {
|
||||
return fmt.Errorf("failed to set autoconnect: %w", call.Err)
|
||||
}
|
||||
|
||||
if !autoconnect {
|
||||
b.abortInFlightConnection(ssid)
|
||||
}
|
||||
|
||||
b.updateState()
|
||||
|
||||
if b.onStateChange != nil {
|
||||
|
||||
@@ -359,6 +359,24 @@ func (b *NetworkManagerBackend) DisconnectWiFi() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *NetworkManagerBackend) abortInFlightConnection(ssid string) {
|
||||
b.stateMutex.Lock()
|
||||
if !b.state.IsConnecting || b.state.ConnectingSSID != ssid {
|
||||
b.stateMutex.Unlock()
|
||||
return
|
||||
}
|
||||
b.state.IsConnecting = false
|
||||
b.state.ConnectingSSID = ""
|
||||
b.state.LastError = ""
|
||||
b.stateMutex.Unlock()
|
||||
|
||||
b.clearCachedWiFiSecretBySSID(ssid)
|
||||
|
||||
if err := b.DisconnectWiFi(); err != nil {
|
||||
log.Warnf("[abortInFlightConnection] failed to abort connection to %s: %v", ssid, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *NetworkManagerBackend) ForgetWiFiNetwork(ssid string) error {
|
||||
conn, err := b.findConnection(ssid)
|
||||
if err != nil {
|
||||
@@ -963,6 +981,10 @@ func (b *NetworkManagerBackend) SetWiFiAutoconnect(ssid string, autoconnect bool
|
||||
return fmt.Errorf("failed to update connection: %w", err)
|
||||
}
|
||||
|
||||
if !autoconnect {
|
||||
b.abortInFlightConnection(ssid)
|
||||
}
|
||||
|
||||
b.updateWiFiNetworks()
|
||||
|
||||
if b.onStateChange != nil {
|
||||
|
||||
Reference in New Issue
Block a user