Rewrite entire network package and update wifi page

This commit is contained in:
NeilClack
2026-06-24 18:29:59 -05:00
parent 2d2069fd63
commit 953d0d8bc9
2 changed files with 114 additions and 50 deletions
+25 -32
View File
@@ -91,13 +91,10 @@ func (p *WiFiSetupPage) Init(ctx *PageCtx) error {
// Find Wi-Fi device
if err := p.networkManager.FindDevices(); err != nil {
}
for _, dev := range p.networkManager.Devices {
if dev.Type == network.TypeWifi {
d := dev
p.wifiDevice = &d
break
}
// Clean up before returning error
p.networkManager.Close()
p.networkManager = nil
return fmt.Errorf("failed to find network devices: %w. Try rebooting the computer. If this is your 3rd reboot, call for help", err)
}
// Create UI elements
@@ -161,17 +158,11 @@ func (p *WiFiSetupPage) startScan() {
// HandleEvent processes user input.
func (p *WiFiSetupPage) HandleEvent(event *sdl.Event) error {
switch e := (*event).(type) {
case *sdl.TextInputEvent:
if p.isEnteringPassword {
// If we get a TextInputEvent, the system supports high-level input.
// Mark it supported so we don't double-type from KeyboardEvents.
if !p.textInputSupported {
p.textInputSupported = true
} else {
p.passwordInput += e.GetText()
p.updatePasswordTexture()
}
p.passwordInput += e.GetText() // Always append text
p.textInputSupported = true // Mark as supported
p.updatePasswordTexture()
}
case *sdl.KeyboardEvent:
@@ -180,13 +171,11 @@ func (p *WiFiSetupPage) HandleEvent(event *sdl.Event) error {
}
if p.isEnteringPassword {
// Pass the Modifiers (Shift/Caps) to the handler
p.handlePasswordInput(e.Keysym.Sym, e.Keysym.Mod)
} else {
p.handleNetworkSelection(e.Keysym.Sym)
}
}
return nil
}
@@ -323,7 +312,7 @@ func (p *WiFiSetupPage) handleNetworkSelection(sym sdl.Keycode) {
case sdl.K_RETURN:
if len(p.accessPoints) > 0 && p.selectedIndex < len(p.accessPoints) {
p.selectedAP = &p.accessPoints[p.selectedIndex].AP
p.pendingSSID = p.selectedAP.SSID
p.pendingSSID = p.selectedAP.SSID // Set for ALL networks (protected or not)
p.connectionError = ""
if p.selectedAP.IsProtected {
p.isEnteringPassword = true
@@ -338,7 +327,7 @@ func (p *WiFiSetupPage) handleNetworkSelection(sym sdl.Keycode) {
if err != nil {
p.isConnecting = false
p.pendingSSID = ""
p.connectionError = "Failed to initiate connection"
p.connectionError = fmt.Sprintf("Failed to connect: %s", err.Error()) // Include actual error
}
}
}
@@ -384,18 +373,17 @@ func (p *WiFiSetupPage) Update(dt float32) error {
// handleConnectionStatusUpdate CHECKS0 if connection succeeded or failed
func (p *WiFiSetupPage) handleConnectionStatusUpdate(status *network.ConnectionStatus) {
if !p.isConnecting {
if !p.isConnecting || p.pendingSSID == "" {
return
}
// milestone 1: We are associated with an AP (even if internet is still pending)
isConnected := status.StatusCode == network.StatusWifiConnectedInternetUp ||
// Only consider it successful if we're connected to the EXACT network we tried to join
isConnectedToPending := status.StatusCode == network.StatusWifiConnectedInternetUp ||
status.StatusCode == network.StatusWifiConnectedNoInternet
if isConnected {
if isConnectedToPending {
activeSSID := p.getActiveSSID()
// If we see our SSID, OR if we're connected to anything while trying, call it a win.
if activeSSID == p.pendingSSID || activeSSID != "" {
if activeSSID == p.pendingSSID { // ONLY accept if it's the network we tried
logger.Info("UI synced: Connected to %s", activeSSID)
p.isConnecting = false
p.pendingSSID = ""
@@ -405,14 +393,12 @@ func (p *WiFiSetupPage) handleConnectionStatusUpdate(status *network.ConnectionS
}
}
// milestone 2: Handle the "Not Connected" state during the handshake
// Handle failure: If we've been trying for too long, show error
if status.StatusCode == network.StatusWifiAvailableNotConnected {
// 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 {
if time.Since(p.connectionAttemptTime) > 15*time.Second {
p.isConnecting = false
p.connectionError = "Connection failed - Check password or signal"
p.isConnecting = false
p.connectionError = "Connection failed - Check password or signal"
if p.selectedAP != nil && p.selectedAP.IsProtected {
p.isEnteringPassword = true
p.enterPasswordMode()
p.updatePasswordErrorTexture()
@@ -553,6 +539,13 @@ func (p *WiFiSetupPage) updateConnectionStatusItem() {
// buildNetworkUIList creates the renderable textures for the list of discovered networks.
func (p *WiFiSetupPage) buildNetworkUIList(aps []network.AccessPoint) {
// Delete old textures to prevent memory leaks
for _, apItem := range p.accessPoints {
if apItem.Item.ID != 0 {
gl.DeleteTextures(1, &apItem.Item.ID)
}
}
// Get the currently active Wi-Fi SSID
activeSSID := p.getActiveSSID()
p.activeSSID = activeSSID