Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
kidasov
Channel Surfer

Roregistry problem

Hello! I want to understand how to check if there is no information stored in roRegistry. I have a task.
<?xml version="1.0" encoding="UTF-8"?>
<component name="ReadAuthRegistryTask" extends="Task" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">
<script type="text/brightscript" uri="pkg:/components/tasks/ReadAuthRegistryTask/ReadAuthRegistryTask.brs" />

<interface>
<field id="authData" type="string" />
</interface>
</component>

sub init()
m.top.functionName = "executeTask"
m.top.authData = ""
end sub

function executeTask()
registrySection = CreateObject("roRegistrySection", "Authentication")
    m.top.authData = registrySection.Read("authData")
 
  if (m.top.authData.len() = 0)
m.top.authData = invalid
  end if 
 
  return m.top.authData
end function


' MainScene.brs

sub getFromLocalStorage(field, callback)
print("Get from local storage")
m.readAuthRegistryTask.observeField(field, callback)
m.readAuthRegistryTask.control = "RUN"
end sub

' callback
sub onUserAlreadyLoggedIn()
print("Callback called")
print(m.readAuthRegistryTask.authData)
end sub

' Callback onUserAlreadyLogged is not called.
getFromLocalStorage("authData", "onUserAlreadyLogged")



I want to execute onUserAlreadyLogged to check if authData field exists. Any help will be highly appreciated :) I thought that m.top.authData = invalid will fire obseveField but it didn't happen.
0 Kudos
2 REPLIES 2
joetesta
Roku Guru

Re: Roregistry problem

Looks like you did not include ReadAuthRegistryTask.brs file, correct?

sub getFromLocalStorage(field, callback)
 print("Get from local storage")
 m.readAuthRegistryTask.observeField(field, callback)
 m.readAuthRegistryTask.control = "RUN"
end sub


What I would do is to add another string field to your task node for the "incoming" registry section, that your task will reference via m.top.FIELDNAME to know what registry section to query.
something like <field id="regSection" type="string"/> 
then you pass it in, in the function I copied above, add the line before observefield line; m.readAuthRegistryTask.regSection = field
then your task can see that via m.top.regSection and once it reads the registry, the task should set its own m.top.authData field which should be the field that your observing in your calling function,
m.readAuthRegistryTask.observeField("authData", callback)

Hopefully you have a separate ReadAuthRegistryTask.brs file from what's shown here 🙂
hope this may help,
Joe
aspiring
0 Kudos
kidasov
Channel Surfer

Re: Roregistry problem

Thank you for your answer! Worked like a charm!
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.