Attempt to fix wifi connectivity
This commit is contained in:
+23
-33
@@ -155,50 +155,34 @@ func (m *Manager) FindDevices() error {
|
||||
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) {
|
||||
if err := m.FindDevices(); err != nil {
|
||||
return &ConnectionStatus{StatusError, "Failed to scan for network devices"}, err
|
||||
}
|
||||
if len(m.Devices) == 0 {
|
||||
return &ConnectionStatus{StatusNoDevicesFound, "No network hardware found."}, nil
|
||||
return &ConnectionStatus{StatusError, "Failed to scan devices"}, err
|
||||
}
|
||||
|
||||
hasWifiAdapter := false
|
||||
hasEthernetAdapter := false
|
||||
|
||||
// Check Ethernet first (Priority)
|
||||
for _, device := range m.Devices {
|
||||
if device.Type == TypeEthernet {
|
||||
hasEthernetAdapter = true
|
||||
if device.State == nmDeviceStateActivated {
|
||||
if pingTest() {
|
||||
return &ConnectionStatus{StatusEthernetConnectedInternetUp, "Ethernet connected with internet access."}, nil
|
||||
}
|
||||
return &ConnectionStatus{StatusEthernetConnectedNoInternet, "Ethernet connected, but no internet access."}, nil
|
||||
if device.Type == TypeEthernet && device.State == nmDeviceStateActivated {
|
||||
if pingTest() {
|
||||
return &ConnectionStatus{StatusEthernetConnectedInternetUp, "Ethernet: Online"}, nil
|
||||
}
|
||||
return &ConnectionStatus{StatusEthernetConnectedNoInternet, "Ethernet: No Internet"}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Check Wifi
|
||||
for _, device := range m.Devices {
|
||||
if device.Type == TypeWifi {
|
||||
hasWifiAdapter = true
|
||||
if device.State == nmDeviceStateActivated {
|
||||
if pingTest() {
|
||||
return &ConnectionStatus{StatusWifiConnectedInternetUp, "Wi-Fi connected with internet access."}, nil
|
||||
}
|
||||
return &ConnectionStatus{StatusWifiConnectedNoInternet, "Wi-Fi connected, but no internet access."}, nil
|
||||
if device.Type == TypeWifi && device.State == nmDeviceStateActivated {
|
||||
if pingTest() {
|
||||
return &ConnectionStatus{StatusWifiConnectedInternetUp, "Wi-Fi: Online"}, 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, "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
|
||||
return &ConnectionStatus{StatusWifiAvailableNotConnected, "Ready to connect"}, nil
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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 {
|
||||
_, err := net.LookupHost("www.google.com")
|
||||
return err == nil
|
||||
// Use a dialer with a timeout instead of LookupHost which can hang
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user