mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-10-29 06:27:47 -04:00
fix(network): store pending PSK, reset WiFiSSID on disconnect, and fix popout actions (1.6) (#3888)
This commit is contained in:
6 files changed
+89
-9
No files matched your search
@@ -428,6 +428,7 @@ func (b *IWDBackend) signalHandler(sigChan chan *dbus.Signal) {
|
||||
|
||||
b.stateMutex.Lock()
|
||||
b.state.WiFiConnected = false
|
||||
b.state.WiFiSSID = ""
|
||||
if state == "disconnected" {
|
||||
b.state.NetworkStatus = StatusDisconnected
|
||||
}
|
||||
|
||||
@@ -342,6 +342,48 @@ func TestIWDBackend_PendingPSK(t *testing.T) {
|
||||
assert.False(t, ok, "expired pending PSK should not be returned")
|
||||
}
|
||||
|
||||
func TestIWDBackend_SetConnectError_ClearsSSIDWhenDisconnected(t *testing.T) {
|
||||
backend, _ := NewIWDBackend()
|
||||
backend.state = &BackendState{
|
||||
WiFiConnected: false,
|
||||
WiFiSSID: "StaleNetwork",
|
||||
IsConnecting: true,
|
||||
ConnectingSSID: "StaleNetwork",
|
||||
}
|
||||
|
||||
backend.setConnectError("bad-credentials")
|
||||
|
||||
assert.False(t, backend.state.IsConnecting)
|
||||
assert.Empty(t, backend.state.ConnectingSSID)
|
||||
assert.Empty(t, backend.state.WiFiSSID)
|
||||
assert.Equal(t, "bad-credentials", backend.state.LastError)
|
||||
}
|
||||
|
||||
func TestIWDBackend_FinalizeAttempt_ClearsSSIDWhenDisconnected(t *testing.T) {
|
||||
backend, _ := NewIWDBackend()
|
||||
backend.state = &BackendState{
|
||||
WiFiConnected: false,
|
||||
WiFiSSID: "StaleNetwork",
|
||||
IsConnecting: true,
|
||||
ConnectingSSID: "StaleNetwork",
|
||||
}
|
||||
|
||||
att := &connectAttempt{
|
||||
ssid: "StaleNetwork",
|
||||
netPath: "/test",
|
||||
saved: false,
|
||||
start: time.Now(),
|
||||
deadline: time.Now().Add(15 * time.Second),
|
||||
}
|
||||
|
||||
backend.finalizeAttempt(att, "bad-credentials")
|
||||
|
||||
assert.False(t, backend.state.IsConnecting)
|
||||
assert.Empty(t, backend.state.ConnectingSSID)
|
||||
assert.Empty(t, backend.state.WiFiSSID)
|
||||
assert.Equal(t, "bad-credentials", backend.state.LastError)
|
||||
}
|
||||
|
||||
type fakePromptBroker struct {
|
||||
asked chan PromptRequest
|
||||
reply PromptReply
|
||||
|
||||
@@ -41,6 +41,7 @@ func (b *IWDBackend) updateState() error {
|
||||
b.state.NetworkStatus = StatusWiFi
|
||||
} else {
|
||||
b.state.NetworkStatus = StatusDisconnected
|
||||
b.state.WiFiSSID = ""
|
||||
}
|
||||
b.stateMutex.Unlock()
|
||||
}
|
||||
@@ -55,7 +56,11 @@ func (b *IWDBackend) updateState() error {
|
||||
if err == nil {
|
||||
if name, ok := nameVar.Value().(string); ok {
|
||||
b.stateMutex.Lock()
|
||||
b.state.WiFiSSID = name
|
||||
if b.state.WiFiConnected {
|
||||
b.state.WiFiSSID = name
|
||||
} else {
|
||||
b.state.WiFiSSID = ""
|
||||
}
|
||||
b.stateMutex.Unlock()
|
||||
}
|
||||
}
|
||||
@@ -417,6 +422,9 @@ func (b *IWDBackend) setConnectError(code string) {
|
||||
b.state.IsConnecting = false
|
||||
b.state.ConnectingSSID = ""
|
||||
b.state.LastError = code
|
||||
if !b.state.WiFiConnected {
|
||||
b.state.WiFiSSID = ""
|
||||
}
|
||||
b.stateMutex.Unlock()
|
||||
}
|
||||
|
||||
@@ -471,6 +479,9 @@ func (b *IWDBackend) finalizeAttempt(att *connectAttempt, code string) {
|
||||
b.state.IsConnecting = false
|
||||
b.state.ConnectingSSID = ""
|
||||
b.state.LastError = code
|
||||
if !b.state.WiFiConnected {
|
||||
b.state.WiFiSSID = ""
|
||||
}
|
||||
b.stateMutex.Unlock()
|
||||
|
||||
b.updateState()
|
||||
@@ -634,6 +645,10 @@ func (b *IWDBackend) ConnectWiFi(req ConnectionRequest) error {
|
||||
return fmt.Errorf("network not found: %w", err)
|
||||
}
|
||||
|
||||
if req.Password != "" {
|
||||
b.storePendingPSK(req.SSID, req.Password)
|
||||
}
|
||||
|
||||
att := &connectAttempt{
|
||||
ssid: req.SSID,
|
||||
netPath: networkPath,
|
||||
@@ -731,6 +746,12 @@ func (b *IWDBackend) DisconnectWiFi() error {
|
||||
return fmt.Errorf("failed to disconnect: %w", call.Err)
|
||||
}
|
||||
|
||||
b.stateMutex.Lock()
|
||||
b.state.WiFiConnected = false
|
||||
b.state.WiFiSSID = ""
|
||||
b.state.NetworkStatus = StatusDisconnected
|
||||
b.stateMutex.Unlock()
|
||||
|
||||
b.updateState()
|
||||
|
||||
if b.onStateChange != nil {
|
||||
@@ -772,6 +793,10 @@ func (b *IWDBackend) ForgetWiFiNetwork(ssid string) error {
|
||||
isConnected := b.state.WiFiConnected
|
||||
b.stateMutex.RUnlock()
|
||||
|
||||
if isConnected && currentSSID == ssid {
|
||||
_ = b.DisconnectWiFi()
|
||||
}
|
||||
|
||||
obj := b.conn.Object(iwdBusName, iwdObjectPath)
|
||||
|
||||
var objects map[dbus.ObjectPath]map[string]map[string]dbus.Variant
|
||||
|
||||
@@ -1124,7 +1124,7 @@ Rectangle {
|
||||
required property var modelData
|
||||
required property int index
|
||||
|
||||
readonly property bool isConnected: modelData.ssid === NetworkService.currentWifiSSID
|
||||
readonly property bool isConnected: NetworkService.wifiConnected && modelData.ssid === NetworkService.currentWifiSSID
|
||||
readonly property bool isConnecting: NetworkService.isWifiConnecting && NetworkService.connectingSSID === modelData.ssid
|
||||
readonly property bool isPinned: root.getPinnedNetworks().includes(modelData.ssid)
|
||||
readonly property string networkName: modelData.ssid || I18n.tr("Unknown Network")
|
||||
@@ -1319,12 +1319,9 @@ Rectangle {
|
||||
cursorShape: enabled ? Qt.PointingHandCursor : Qt.BusyCursor
|
||||
onPressed: mouse => wifiRipple.trigger(mouse.x, mouse.y)
|
||||
onClicked: function (event) {
|
||||
if (wifiDelegate.isConnected) {
|
||||
event.accepted = true;
|
||||
return;
|
||||
}
|
||||
WifiConnectionActions.connectToNetwork(modelData, {
|
||||
connected: wifiDelegate.isConnected
|
||||
connected: wifiDelegate.isConnected,
|
||||
disconnectWhenConnected: true
|
||||
});
|
||||
event.accepted = true;
|
||||
}
|
||||
|
||||
@@ -457,7 +457,7 @@ Item {
|
||||
required property var modelData
|
||||
required property int index
|
||||
|
||||
readonly property bool isConnected: modelData.ssid === NetworkService.currentWifiSSID
|
||||
readonly property bool isConnected: NetworkService.wifiConnected && modelData.ssid === NetworkService.currentWifiSSID
|
||||
readonly property bool isConnecting: NetworkService.isWifiConnecting && NetworkService.connectingSSID === modelData.ssid
|
||||
readonly property bool isPinned: root.getPinnedWifiNetworks().includes(modelData.ssid)
|
||||
readonly property bool isExpanded: root.expandedWifiSsid === modelData.ssid
|
||||
@@ -863,7 +863,7 @@ Item {
|
||||
required property var modelData
|
||||
required property int index
|
||||
|
||||
readonly property bool isConnected: modelData.ssid === NetworkService.currentWifiSSID
|
||||
readonly property bool isConnected: NetworkService.wifiConnected && modelData.ssid === NetworkService.currentWifiSSID
|
||||
readonly property bool isConnecting: NetworkService.isWifiConnecting && NetworkService.connectingSSID === modelData.ssid
|
||||
readonly property bool isPinned: root.getPinnedWifiNetworks().includes(modelData.ssid)
|
||||
readonly property bool isOutOfRange: modelData.outOfRange || false
|
||||
|
||||
@@ -902,6 +902,21 @@ Singleton {
|
||||
onTriggered: root.scanWifi()
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: 20000
|
||||
repeat: true
|
||||
running: root.isConnecting
|
||||
onTriggered: {
|
||||
if (Date.now() - root.pendingConnectionStartTime > 16000) {
|
||||
root.isConnecting = false;
|
||||
root.connectingSSID = "";
|
||||
root.connectionStatus = "failed";
|
||||
root.connectionError = "timeout";
|
||||
root.pendingConnectionSSID = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function fetchWiredNetworkInfo(uuid) {
|
||||
if (!networkAvailable)
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user