Forum Discussion

kidasov's avatar
kidasov
Channel Surfer
8 years ago

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.

2 Replies

  • 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