jf-roku/components/data/user.xml

55 lines
1.5 KiB
XML
Raw Normal View History

2019-04-20 17:40:06 +00:00
<?xml version="1.0" encoding="utf-8" ?>
<component name="UserData" extends="ContentNode">
<interface>
<field id="id" type="string" />
<field id="username" type="string" />
<field id="token" type="string" />
<field id="json" type="associativearray" onChange="setDataFromJSON" />
<function name="getPreference" />
<function name="setPreference" />
<function name="loadFromRegistry" />
<function name="saveToRegistry" />
<function name="setActive" />
</interface>
<script type="text/brightscript" uri="pkg:/source/utils/config.brs" />
<script type="text/brightscript">
<![CDATA[
sub setDataFromJSON()
json = m.top.json
loadFromJSON(json)
end sub
function loadFromJSON(json)
m.top.id = json.User.id
m.top.username = json.User.username
m.top.token = json.AccessToken
end function
function loadFromRegistry(id as String)
m.top.id = id
m.top.username = get_user_setting("username")
m.top.token = get_user_setting("token")
end function
function saveToRegistry()
set_user_setting("username", m.top.username)
set_user_setting("token", m.top.token)
end function
function getPreference(key as String, default as String)
return get_user_setting("pref-" + key, default)
end function
function setPreference(key as String, value as String)
return set_user_setting("pref-" + key, value)
end function
function setActive()
set_setting("active_user", m.top.id)
end function
]]>
</script>
</component>