Fixed WiFi password bug. Ready for testing and merge
This commit is contained in:
@@ -95,7 +95,7 @@ func (p *WiFiSetupPage) Init(ctx *PageCtx) error {
|
||||
}
|
||||
for _, dev := range p.networkManager.Devices {
|
||||
if dev.Type == network.TypeWifi {
|
||||
d := dev
|
||||
d := dev
|
||||
p.wifiDevice = &d
|
||||
break
|
||||
}
|
||||
@@ -198,13 +198,14 @@ func (p *WiFiSetupPage) handlePasswordInput(sym sdl.Keycode, mod uint16) {
|
||||
switch sym {
|
||||
|
||||
case sdl.K_RETURN:
|
||||
p.exitPasswordMode()
|
||||
p.exitPasswordMode()
|
||||
|
||||
p.pendingSSID = p.selectedAP.SSID
|
||||
p.isConnecting = true
|
||||
p.connectionError = ""
|
||||
p.connectionAttemptTime = time.Now()
|
||||
|
||||
|
||||
|
||||
err := p.networkManager.Connect(*p.wifiDevice, *p.selectedAP, p.passwordInput)
|
||||
if err != nil {
|
||||
p.isConnecting = false
|
||||
@@ -383,7 +384,7 @@ func (p *WiFiSetupPage) Update(dt float32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleConnectionStatusUpdate checks if connection succeeded or failed
|
||||
// handleConnectionStatusUpdate CHECKS0 if connection succeeded or failed
|
||||
func (p *WiFiSetupPage) handleConnectionStatusUpdate(status *network.ConnectionStatus) {
|
||||
if !p.isConnecting {
|
||||
return
|
||||
@@ -411,48 +412,50 @@ func (p *WiFiSetupPage) handleConnectionStatusUpdate(status *network.ConnectionS
|
||||
// INCREASE THIS: 5 seconds is way too aggressive.
|
||||
// Give it at least 20 seconds before assuming the password was wrong.
|
||||
if time.Since(p.connectionAttemptTime) > 20*time.Second {
|
||||
p.isConnecting = false
|
||||
p.connectionError = "Connection failed - Check password or signal"
|
||||
p.isEnteringPassword = true
|
||||
p.enterPasswordMode()
|
||||
p.updatePasswordErrorTexture()
|
||||
if time.Since(p.connectionAttemptTime) > 15*time.Second {
|
||||
p.isConnecting = false
|
||||
p.connectionError = "Connection failed - Check password or signal"
|
||||
p.isEnteringPassword = true
|
||||
p.enterPasswordMode()
|
||||
p.updatePasswordErrorTexture()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// getActiveSSID queries NetworkManager for the currently active WiFi SSID
|
||||
// getAiveSSID queries NetworkManager for the currently active WiFi SSID
|
||||
func (p *WiFiSetupPage) getActiveSSID() string {
|
||||
if p.networkManager == nil || p.wifiDevice == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
nmObj := p.networkManager.Conn().Object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager")
|
||||
prop, err := nmObj.GetProperty("org.freedesktop.NetworkManager.ActiveConnections")
|
||||
conn := p.networkManager.Conn()
|
||||
|
||||
devObj := conn.Object("org.freedesktop.NetworkManager", p.wifiDevice.Path)
|
||||
activeApProp, err := devObj.GetProperty("org.freedesktop.NetworkManager.Device.Wireless.ActiveAccessPoint")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if paths, ok := prop.Value().([]dbus.ObjectPath); ok {
|
||||
for _, path := range paths {
|
||||
acObj := p.networkManager.Conn().Object("org.freedesktop.NetworkManager", path)
|
||||
devProp, err := acObj.GetProperty("org.freedesktop.NetworkManager.Connection.Active.Devices")
|
||||
if err == nil {
|
||||
if devPaths, ok := devProp.Value().([]dbus.ObjectPath); ok {
|
||||
for _, devPath := range devPaths {
|
||||
if string(devPath) == string(p.wifiDevice.Path) {
|
||||
idProp, err := acObj.GetProperty("org.freedesktop.NetworkManager.Connection.Active.Id")
|
||||
if err == nil {
|
||||
if id, ok := idProp.Value().(string); ok {
|
||||
return id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
activeApPath, ok := activeApProp.Value().(dbus.ObjectPath)
|
||||
if !ok || activeApPath == "/" || activeApPath == "" {
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
|
||||
apObj := conn.Object("org.freedesktop.NetworkManager", activeApPath)
|
||||
ssidProp, err := apObj.GetProperty("org.freedesktop.NetworkManager.AccessPoint.Ssid")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
ssidBytes, ok := ssidProp.Value().([]byte)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
logger.Info("Active SSID: %s", string(ssidBytes))
|
||||
|
||||
return string(ssidBytes)
|
||||
}
|
||||
|
||||
// refreshNetworkColors updates the colors of network items based on active status
|
||||
|
||||
Reference in New Issue
Block a user