No, I'm not closing any screens. Or at least not explicitly. I pasted the entire file below for a better reference.
The process attempts to locate a code in the registry. If a code is not found then the roKeyboardScreen is displayed to collect the access code. After the user enters the code the script then takes that code and attempts to query the url for verification.
After your post, that got me to thinking. I don't have a background screen open. So maybe after the roKeyboardScreen returns the entered characters, is that screen then being closed?
' *****************************************************************************
' **
' ** Verify the user's access to the channel
' **
' *****************************************************************************
Function verify_user()
console_log("Verifying User")
' Check to see if there is something in the registry for the account
user_account = registry_read("user_account")
console_log("Read from the registry")
' If nothing is found, then request account information
' "Roku access code"?
if user_account = invalid then
console_log("Nothing was found in the registry for the user")
user_account = get_access_code()
endif
console_log("Verifying code")
' If something IS found in the registry, then query the server to check for
' account validation
verification = verify_access_code(user_account)
' If the account is not valid, delete the registry entry and request
' account information
if verification = false then
registry_delete("user_account")
verify_user()
else
' If the account IS valid, then go to the grid screen
m.access_code = verification
registry_write("user_account", verification)
return true
endif
End Function
' *****************************************************************************
' **
' ** Display the keyboard screen to collect the user's access code
' **
' *****************************************************************************
Function get_access_code()
console_log("Asking user for access code")
screen = CreateObject("roKeyboardScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.SetTitle("Access Code")
screen.SetDisplayText("Please enter your access code for this Roku channel")
screen.SetMaxLength(8)
screen.AddButton(1, "Finished")
screen.AddButton(2, "Back")
screen.Show()
while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roKeyboardScreenEvent"
if msg.isScreenClosed()
'exit while
End
else if msg.isButtonPressed() then
if msg.GetIndex() = 1
searchText = screen.GetText()
console_log("Returning entered code ("+searchText+")")
return searchText
exit while
else if msg.GetIndex() = 2
console_log("Exiting app")
End
endif
endif
endif
end while
End Function
' *****************************************************************************
' **
' ** Query the site for verification of the access code
' **
' *****************************************************************************
Function verify_access_code(access_code=invalid)
' If we don't have the access code to verify then we have nothting to do
' Return false and don't do anything
if access_code = invalid OR access_code = ""
return false
endif
console_log("Submitting access code for verification")
console_log("Access code is a "+type(access_code))
' Hit up the verification URL with the access_code for verification
request = CreateObject("roUrlTransfer")
access_url = m.access_code_verification_url+"?access_code="+access_code
console_log(access_url)
request.SetUrl(access_url)
console_log("Access URL is a "+type(access_url))
html = request.GetToString()
console_log(html)
xml = CreateObject("roXMLElement")
xml.Parse(html)
console_log("XML Parsed")
if xml.verified then
console_log("Access code verified")
return access_code
else
console_log("Access code was not verified")
return false
endif
End Function
שלום חבר
Dean at the School of Truth: a part of Autodidact University.
"A programmer is just a tool which converts caffeine into code"
Temet nosce
Vi Veri Veniversum Vivus Vici
Si vis pacem, para bellum