Attempt to fix wifi connectivity

This commit is contained in:
NeilClack
2026-03-13 20:58:28 -05:00
parent 514bba69f5
commit 5fef01107b
2 changed files with 35 additions and 55 deletions
+23 -33
View File
@@ -155,50 +155,34 @@ func (m *Manager) FindDevices() error {
return nil return nil
} }
// CheckInternetConnection performs a comprehensive check for an active internet connection. // CheckInternetConnection performs a check for an active internet connection.
func (m *Manager) CheckInternetConnection() (*ConnectionStatus, error) { func (m *Manager) CheckInternetConnection() (*ConnectionStatus, error) {
if err := m.FindDevices(); err != nil { if err := m.FindDevices(); err != nil {
return &ConnectionStatus{StatusError, "Failed to scan for network devices"}, err return &ConnectionStatus{StatusError, "Failed to scan devices"}, err
}
if len(m.Devices) == 0 {
return &ConnectionStatus{StatusNoDevicesFound, "No network hardware found."}, nil
} }
hasWifiAdapter := false // Check Ethernet first (Priority)
hasEthernetAdapter := false
for _, device := range m.Devices { for _, device := range m.Devices {
if device.Type == TypeEthernet { if device.Type == TypeEthernet && device.State == nmDeviceStateActivated {
hasEthernetAdapter = true if pingTest() {
if device.State == nmDeviceStateActivated { return &ConnectionStatus{StatusEthernetConnectedInternetUp, "Ethernet: Online"}, nil
if pingTest() {
return &ConnectionStatus{StatusEthernetConnectedInternetUp, "Ethernet connected with internet access."}, nil
}
return &ConnectionStatus{StatusEthernetConnectedNoInternet, "Ethernet connected, but no internet access."}, nil
} }
return &ConnectionStatus{StatusEthernetConnectedNoInternet, "Ethernet: No Internet"}, nil
} }
} }
// Check Wifi
for _, device := range m.Devices { for _, device := range m.Devices {
if device.Type == TypeWifi { if device.Type == TypeWifi && device.State == nmDeviceStateActivated {
hasWifiAdapter = true if pingTest() {
if device.State == nmDeviceStateActivated { return &ConnectionStatus{StatusWifiConnectedInternetUp, "Wi-Fi: Online"}, nil
if pingTest() {
return &ConnectionStatus{StatusWifiConnectedInternetUp, "Wi-Fi connected with internet access."}, nil
}
return &ConnectionStatus{StatusWifiConnectedNoInternet, "Wi-Fi connected, but no internet access."}, nil
} }
// Even if ping fails, the state IS activated (connected to AP)
return &ConnectionStatus{StatusWifiConnectedNoInternet, "Wi-Fi: Connected, checking internet..."}, nil
} }
} }
if hasWifiAdapter { return &ConnectionStatus{StatusWifiAvailableNotConnected, "Ready to connect"}, nil
return &ConnectionStatus{StatusWifiAvailableNotConnected, "Wi-Fi adapter is available but not connected."}, nil
}
if hasEthernetAdapter {
return &ConnectionStatus{StatusEthernetNotConnected, "Ethernet adapter is available but not connected."}, nil
}
return &ConnectionStatus{StatusNoDevicesFound, "No recognizable network hardware found."}, nil
} }
// StartScan performs a Wi-Fi scan asynchronously. The optional stopChan can be used to abort. // StartScan performs a Wi-Fi scan asynchronously. The optional stopChan can be used to abort.
@@ -369,10 +353,16 @@ func (m *Manager) Connect(wifiDevice Device, ap AccessPoint, passphrase string)
return nil return nil
} }
// pingTest performs a simple DNS lookup to check for internet connectivity. // pingTest with a short timeout to prevent the UI loop from hanging
func pingTest() bool { func pingTest() bool {
_, err := net.LookupHost("www.google.com") // Use a dialer with a timeout instead of LookupHost which can hang
return err == nil timeout := 2 * time.Second
conn, err := net.DialTimeout("tcp", "8.8.8.8:53", timeout)
if err != nil {
return false
}
conn.Close()
return true
} }
// getAllProperties is a helper to fetch all properties for a D-Bus object interface. // getAllProperties is a helper to fetch all properties for a D-Bus object interface.
+12 -22
View File
@@ -122,7 +122,7 @@ func (p *WiFiSetupPage) Init(app ApplicationInterface) error {
p.statusChan = make(chan *network.ConnectionStatus, 1) p.statusChan = make(chan *network.ConnectionStatus, 1)
p.errorChan = make(chan error) p.errorChan = make(chan error)
p.stopScan = make(chan struct{}) p.stopScan = make(chan struct{})
p.connectionTimeout = 15 * time.Second p.connectionTimeout = 30 * time.Second
// Start scanning and status monitoring // Start scanning and status monitoring
p.startScan() p.startScan()
@@ -394,33 +394,23 @@ func (p *WiFiSetupPage) handleConnectionStatusUpdate(status *network.ConnectionS
return return
} }
// Check if we successfully connected to our pending SSID // NEW LOGIC: Any "Connected" status should clear the "isConnecting" flag
switch status.StatusCode { // so the user knows the password worked and the hardware is associated.
case network.StatusWifiConnectedInternetUp: isConnected := status.StatusCode == network.StatusWifiConnectedInternetUp ||
status.StatusCode == network.StatusWifiConnectedNoInternet
if isConnected {
activeSSID := p.getActiveSSID() activeSSID := p.getActiveSSID()
if activeSSID == p.pendingSSID {
// We check if the SSID matches, OR if we've been trying long enough
// that any active connection is likely ours.
if activeSSID == p.pendingSSID || activeSSID != "" {
logger.Info("WiFi successfully associated with %s", activeSSID)
p.isConnecting = false p.isConnecting = false
p.pendingSSID = "" p.pendingSSID = ""
p.connectionError = "" p.connectionError = ""
p.refreshNetworkColors() p.refreshNetworkColors()
} }
case network.StatusWifiAvailableNotConnected:
// Connection failed - we're trying to connect but now show as not connected
if time.Since(p.connectionAttemptTime) > 5*time.Second {
p.isConnecting = false
if p.selectedAP != nil && p.selectedAP.IsProtected {
p.connectionError = "Connection failed - Incorrect password?"
p.isEnteringPassword = true
p.passwordInput = ""
p.updatePasswordTexture()
p.updatePasswordPromptTexture()
p.updatePasswordErrorTexture()
p.enterPasswordMode()
} else {
p.connectionError = "Connection failed"
p.pendingSSID = ""
}
}
} }
} }