Fix WiFi password entry
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"rhemawavetech.com/rhemawave/internal/db"
|
||||
"rhemawavetech.com/rhemawave/internal/fontManager"
|
||||
"rhemawavetech.com/rhemawave/internal/keybinds"
|
||||
"rhemawavetech.com/rhemawave/internal/logger"
|
||||
"rhemawavetech.com/rhemawave/internal/network"
|
||||
"rhemawavetech.com/rhemawave/internal/shaderManager"
|
||||
)
|
||||
@@ -165,83 +166,91 @@ func (p *WiFiSetupPage) startScan() {
|
||||
|
||||
// HandleEvent processes user input.
|
||||
func (p *WiFiSetupPage) HandleEvent(event *sdl.Event) error {
|
||||
if p.isEnteringPassword && !sdl.IsTextInputActive() {
|
||||
p.enterPasswordMode()
|
||||
}
|
||||
|
||||
switch e := (*event).(type) {
|
||||
|
||||
case *sdl.TextInputEvent:
|
||||
if p.isEnteringPassword {
|
||||
if !p.textInputSupported {
|
||||
// First TextInputEvent: the keyboard fallback already
|
||||
// handled this character, so just record that text input
|
||||
// is supported and skip the duplicate append.
|
||||
p.textInputSupported = true
|
||||
} else {
|
||||
p.passwordInput += e.GetText()
|
||||
p.updatePasswordTexture()
|
||||
text := e.GetText()
|
||||
|
||||
// Append text exactly as SDL delivers it
|
||||
p.passwordInput += text
|
||||
|
||||
// Log every character
|
||||
for _, r := range text {
|
||||
logger.Info("WiFi Password character entered: %c", r)
|
||||
}
|
||||
|
||||
p.updatePasswordTexture()
|
||||
}
|
||||
|
||||
case *sdl.KeyboardEvent:
|
||||
if e.Type != sdl.KEYDOWN {
|
||||
return nil
|
||||
}
|
||||
|
||||
if p.isEnteringPassword {
|
||||
p.handlePasswordInput(e.Keysym.Sym, e.Keysym.Mod)
|
||||
p.handlePasswordInput(e.Keysym.Sym)
|
||||
} else {
|
||||
p.handleNetworkSelection(e.Keysym.Sym)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// handlePasswordInput manages keyboard events during password entry.
|
||||
func (p *WiFiSetupPage) handlePasswordInput(sym sdl.Keycode, mod uint16) {
|
||||
func (p *WiFiSetupPage) handlePasswordInput(sym sdl.Keycode) {
|
||||
switch sym {
|
||||
|
||||
case sdl.K_RETURN:
|
||||
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
|
||||
p.pendingSSID = ""
|
||||
p.connectionError = "Failed to initiate connection"
|
||||
}
|
||||
|
||||
p.isEnteringPassword = false
|
||||
|
||||
case sdl.K_BACKSPACE:
|
||||
if len(p.passwordInput) > 0 {
|
||||
p.passwordInput = p.passwordInput[:len(p.passwordInput)-1]
|
||||
logger.Info("WiFi Password backspace pressed")
|
||||
p.updatePasswordTexture()
|
||||
}
|
||||
|
||||
case sdl.K_ESCAPE:
|
||||
logger.Info("WiFi Password entry cancelled")
|
||||
|
||||
p.isEnteringPassword = false
|
||||
p.pendingSSID = ""
|
||||
p.connectionError = ""
|
||||
p.exitPasswordMode()
|
||||
default:
|
||||
// Keyboard fallback: if TextInputEvent was not received for this
|
||||
// event cycle, convert printable keycodes to characters directly.
|
||||
// This handles kiosk systems without an input method framework.
|
||||
if !p.textInputSupported {
|
||||
if ch := keycodeToChar(sym, mod); ch != 0 {
|
||||
p.passwordInput += string(ch)
|
||||
p.updatePasswordTexture()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// enterPasswordMode disables global keybinds and starts SDL text input.
|
||||
func (p *WiFiSetupPage) enterPasswordMode() {
|
||||
keybinds.Enabled = false
|
||||
|
||||
p.passwordInput = ""
|
||||
|
||||
logger.Info("WiFi Password entry started")
|
||||
|
||||
sdl.StartTextInput()
|
||||
}
|
||||
|
||||
// exitPasswordMode re-enables global keybinds and stops SDL text input.
|
||||
func (p *WiFiSetupPage) exitPasswordMode() {
|
||||
logger.Info("WiFi Password entry finished")
|
||||
|
||||
keybinds.Enabled = true
|
||||
sdl.StopTextInput()
|
||||
}
|
||||
@@ -257,6 +266,7 @@ func keycodeToChar(sym sdl.Keycode, mod uint16) rune {
|
||||
if shifted {
|
||||
ch -= 'a' - 'A'
|
||||
}
|
||||
logger.Info("Wifi Password entered: %v", ch)
|
||||
return ch
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user