fix(network): fix wifi page never scanning, never exiting, and UI freezes on connect
WiFiSetupPage never showed networks and could not be exited once entered. Several compounding bugs were responsible across network.go and page.go. Primary bugs fixed: - WiFiSetupPage.Init() never assigned p.wifiDevice after FindDevices(), so startScan() always hit the nil guard and exited without launching a scan goroutine. No networks ever appeared in the list. A value copy of the Wi-Fi device is now taken from m.Devices immediately after FindDevices() returns, with an explicit error if no adapter is found. - CheckInternetConnection() called FindDevices() on every tick, rebuilding m.Devices every 2 seconds. This caused [NET-030] log spam, invalidated any pointers held into the slice, and meant checkState()'s fresh Manager instances (which have an empty Devices slice) would never detect internet after Fix 2 was applied. CheckInternetConnection() now calls FindDevices() only when m.Devices is empty (fresh Manager), and does a cheaper per-device State property refresh when devices are already known (long-lived Manager). This satisfies both callers correctly. - Connect() called WaitForInternet(30s, 5s) synchronously before returning, blocking the main UI thread for up to 35 seconds. It also returned an error if internet wasn't stable in time, even though AddAndActivateConnection had succeeded, causing the page to show "Failed to initiate connection" while NM was still negotiating in the background. WaitForInternet removed from Connect(); the page's existing checkConnectionStatusLoop and handleConnectionStatusUpdate already handle post-connection state tracking. Additional bugs fixed: - startScan() launched a new StartScan goroutine on every R-press without signalling the previous one to stop. Concurrent goroutines raced on resultsChan and accumulated indefinitely. stopScan is now closed and replaced before each scan, and checkConnectionStatusLoop is restarted with the new channel. - Connect() always generated a new UUID and called AddAndActivateConnection without checking for an existing profile. Repeated connection attempts (e.g. wrong password then correct) accumulated duplicate stale profiles in NetworkManager. Existing profiles matching the SSID are now deleted via Settings.Connection.Delete before creating a new one. - m.Devices was read and written concurrently from StartScan and CheckInternetConnection goroutines without synchronisation. A sync.RWMutex is added to Manager; state refreshes take a write lock, StartScan device lookup takes a read lock. - Connect() checked wifiDevice.State using the caller's value copy taken at Init() time, which never updated. The current state is now read from m.Devices under lock at the point of connection. - auth-alg: "open" was unconditionally set in the 802-11-wireless-security settings block. This field is only meaningful for WPA/WPA2-Personal and should be omitted for SAE (WPA3) and EAP variants. It is now only set when KeyMgmt is "wpa-psk".
This commit is contained in:
@@ -97,8 +97,23 @@ func (p *WiFiSetupPage) Init(ctx *PageCtx) error {
|
||||
return fmt.Errorf("failed to find network devices: %w. Try rebooting the computer. If this is your 3rd reboot, call for help", err)
|
||||
}
|
||||
|
||||
// FindDevices() rebuilds m.Devices each call, so store a VALUE copy,
|
||||
// not a pointer into the slice — it would be invalidated on next call.
|
||||
for i := range p.networkManager.Devices {
|
||||
if p.networkManager.Devices[i].Type == network.TypeWifi {
|
||||
device := p.networkManager.Devices[i]
|
||||
p.wifiDevice = &device
|
||||
break
|
||||
}
|
||||
}
|
||||
if p.wifiDevice == nil {
|
||||
p.networkManager.Close()
|
||||
p.networkManager = nil
|
||||
return fmt.Errorf("no Wi-Fi adapter found. Try rebooting the computer. If this is your 3rd reboot, call for help")
|
||||
}
|
||||
|
||||
// Create UI elements
|
||||
white := sdl.Color{R: 255, G: 255, B: 255, A: 255}
|
||||
white := colors.White
|
||||
p.titleItem, err = NewStringItem("Wi-Fi Setup", p.applicationFont, white)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create title item: %w", err)
|
||||
@@ -117,7 +132,6 @@ func (p *WiFiSetupPage) Init(ctx *PageCtx) error {
|
||||
|
||||
// Start scanning and status monitoring
|
||||
p.startScan()
|
||||
go p.checkConnectionStatusLoop()
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -143,6 +157,11 @@ func (p *WiFiSetupPage) checkConnectionStatusLoop() {
|
||||
|
||||
// startScan triggers a new asynchronous network scan.
|
||||
func (p *WiFiSetupPage) startScan() {
|
||||
if p.stopScan != nil {
|
||||
close(p.stopScan)
|
||||
}
|
||||
p.stopScan = make(chan struct{})
|
||||
|
||||
p.isScanning = true
|
||||
p.selectedIndex = 0
|
||||
p.scrollOffset = 0
|
||||
@@ -150,6 +169,7 @@ func (p *WiFiSetupPage) startScan() {
|
||||
|
||||
if p.wifiDevice != nil {
|
||||
go p.networkManager.StartScan(p.resultsChan, p.errorChan, p.stopScan)
|
||||
go p.checkConnectionStatusLoop()
|
||||
} else {
|
||||
p.isScanning = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user