2023-05-03 21:21:04 +00:00
|
|
|
import "pkg:/source/utils/config.brs"
|
|
|
|
|
2019-05-03 12:48:59 +00:00
|
|
|
sub setDataFromJSON()
|
|
|
|
json = m.top.json
|
|
|
|
loadFromJSON(json)
|
|
|
|
end sub
|
|
|
|
|
2021-06-26 10:18:09 +00:00
|
|
|
sub loadFromJSON(json)
|
2019-05-03 12:48:59 +00:00
|
|
|
m.top.id = json.User.id
|
|
|
|
|
|
|
|
m.top.username = json.User.name
|
|
|
|
m.top.token = json.AccessToken
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2019-05-03 12:48:59 +00:00
|
|
|
|
2021-06-26 10:18:09 +00:00
|
|
|
sub loadFromRegistry(id as string)
|
2019-05-03 12:48:59 +00:00
|
|
|
m.top.id = id
|
|
|
|
|
|
|
|
m.top.username = get_user_setting("username")
|
|
|
|
m.top.token = get_user_setting("token")
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2019-05-03 12:48:59 +00:00
|
|
|
|
2021-06-26 10:18:09 +00:00
|
|
|
sub saveToRegistry()
|
2019-05-03 12:48:59 +00:00
|
|
|
users = parseJson(get_setting("available_users", "[]"))
|
|
|
|
this_user = invalid
|
|
|
|
for each user in users
|
|
|
|
if user.id = m.top.id then this_user = user
|
|
|
|
end for
|
|
|
|
if this_user = invalid
|
|
|
|
users.push({
|
|
|
|
id: m.top.id,
|
|
|
|
username: m.top.username,
|
2023-06-01 12:43:27 +00:00
|
|
|
server: m.global.session.server.url
|
2019-05-03 12:48:59 +00:00
|
|
|
})
|
|
|
|
set_setting("available_users", formatJson(users))
|
|
|
|
end if
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2019-05-03 12:48:59 +00:00
|
|
|
|
2021-06-26 10:18:09 +00:00
|
|
|
sub removeFromRegistry()
|
2019-05-03 12:48:59 +00:00
|
|
|
new_users = []
|
|
|
|
users = parseJson(get_setting("available_users", "[]"))
|
|
|
|
for each user in users
|
|
|
|
if m.top.id <> user.id then new_users.push(user)
|
|
|
|
end for
|
|
|
|
|
|
|
|
set_setting("available_users", formatJson(new_users))
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2019-05-03 12:48:59 +00:00
|
|
|
|
2023-06-01 12:43:27 +00:00
|
|
|
function getPreference(key as string)
|
|
|
|
return get_user_setting("pref-" + key)
|
2019-05-03 12:48:59 +00:00
|
|
|
end function
|
|
|
|
|
|
|
|
function setPreference(key as string, value as string)
|
|
|
|
return set_user_setting("pref-" + key, value)
|
|
|
|
end function
|
|
|
|
|
2021-06-26 10:18:09 +00:00
|
|
|
sub setActive()
|
2019-05-03 12:48:59 +00:00
|
|
|
set_setting("active_user", m.top.id)
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2019-05-03 12:48:59 +00:00
|
|
|
|
2021-06-26 10:18:09 +00:00
|
|
|
sub setServer(hostname as string)
|
2019-05-03 12:48:59 +00:00
|
|
|
m.top.server = hostname
|
2022-05-30 12:57:40 +00:00
|
|
|
end sub
|