Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix login bugs, enable support for saving user's credentials, and add "Change User" and "Remember Me?" options #1374

Merged
merged 10 commits into from
Sep 21, 2023
9 changes: 6 additions & 3 deletions components/data/SceneManager.brs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import "pkg:/source/roku_modules/log/LogMixin.brs"
import "pkg:/source/utils/config.brs"
import "pkg:/source/utils/session.bs"

sub init()
m.log = log.Logger("SceneManager")
Expand Down Expand Up @@ -77,16 +79,17 @@ end sub
sub popScene()
group = m.groups.pop()
if group <> invalid
if group.isSubType("JFGroup")
groupType = group.subtype()
if groupType = "JFGroup"
unregisterOverhangData(group)
else if group.isSubType("JFVideo")
else if groupType = "JFVideo"
' Stop video to make sure app communicates stop playstate to server
group.control = "stop"
end if

group.visible = false

if group.isSubType("JFScreen")
if groupType = "JFScreen"
group.callFunc("OnScreenHidden")
end if
else
Expand Down
7 changes: 3 additions & 4 deletions components/data/UserData.brs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ sub loadFromRegistry(id as string)
end sub

sub saveToRegistry()
set_user_setting("username", m.top.username)
set_user_setting("token", m.top.token)

users = parseJson(get_setting("available_users", "[]"))
this_user = invalid
for each user in users
Expand Down Expand Up @@ -57,7 +54,9 @@ function setPreference(key as string, value as string)
end function

sub setActive()
set_setting("active_user", m.top.id)
if m.global.session.user.settings["global.rememberme"]
set_setting("active_user", m.top.id)
end if
end sub

sub setServer(hostname as string)
Expand Down
33 changes: 30 additions & 3 deletions components/settings/settings.brs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "pkg:/source/utils/config.brs"
import "pkg:/source/utils/misc.brs"
import "pkg:/source/roku_modules/log/LogMixin.brs"
import "pkg:/source/api/sdk.bs"

sub init()
m.log = log.Logger("Settings")
Expand Down Expand Up @@ -160,14 +161,40 @@ end sub


sub boolSettingChanged()

if m.boolSetting.focusedChild = invalid then return
selectedSetting = m.userLocation.peek().children[m.settingsMenu.itemFocused]

if m.boolSetting.checkedItem
set_user_setting(selectedSetting.settingName, "true")
session.user.settings.Save(selectedSetting.settingName, "true")
if Left(selectedSetting.settingName, 7) = "global."
' global user setting
' save to main registry block
set_setting(selectedSetting.settingName, "true")
' setting specific triggers
if selectedSetting.settingName = "global.rememberme"
print "m.global.session.user.id=", m.global.session.user.id
set_setting("active_user", m.global.session.user.id)
end if
else
' regular user setting
' save to user specific registry block
set_user_setting(selectedSetting.settingName, "true")
end if
else
set_user_setting(selectedSetting.settingName, "false")
session.user.settings.Save(selectedSetting.settingName, "false")
if Left(selectedSetting.settingName, 7) = "global."
' global user setting
' save to main registry block
set_setting(selectedSetting.settingName, "false")
' setting specific triggers
if selectedSetting.settingName = "global.rememberme"
unset_setting("active_user")
end if
else
' regular user setting
' save to user specific registry block
set_user_setting(selectedSetting.settingName, "false")
end if
end if
end sub

Expand Down
20 changes: 20 additions & 0 deletions locale/en_US/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1208,5 +1208,25 @@
<translation>Disable the HEVC codec on this device. This may improve playback for some devices (ultra).</translation>
<extracomment>User Setting - Setting description</extracomment>
</message>
<message>
<source>Global</source>
<translation>Global</translation>
<extracomment>User Setting - Setting title</extracomment>
</message>
<message>
<source>Global settings that affect everyone that uses this Roku device.</source>
<translation>Global settings that affect everyone that uses this Roku device.</translation>
<extracomment>User Setting - Setting description</extracomment>
</message>
<message>
<source>Remember Me?</source>
<translation>Remember Me?</translation>
<extracomment>User Setting - Setting title</extracomment>
</message>
<message>
<source>Remember the currently logged in user and try to log them in again next time you start the Jellyfin app.</source>
<translation>Remember the currently logged in user and try to log them in again next time you start the Jellyfin app.</translation>
<extracomment>User Setting - Setting description</extracomment>
</message>
</context>
</TS>
14 changes: 14 additions & 0 deletions settings/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
[
{
"title": "Global",
"description": "Global settings that affect everyone that uses this Roku device.",
"children": [
{
"title": "Remember Me?",
"description": "Remember the currently logged in user and try to log them in again next time you start the Jellyfin app.",
"settingName": "global.rememberme",
"type": "bool",
"default": "false"
}

]
},
{
"title": "Playback",
"description": "Settings relating to playback and supported codec and media types.",
Expand Down
35 changes: 34 additions & 1 deletion source/Main.brs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ sub Main (args as dynamic) as void
end if

' Only show the Whats New popup the first time a user runs a new client version.
if m.global.app.version <> get_setting("LastRunVersion")
appLastRunVersion = get_setting("LastRunVersion")
if m.global.app.version <> appLastRunVersion
' Ensure the user hasn't disabled Whats New popups
if m.global.session.user.settings["load.allowwhatsnew"] = true
set_setting("LastRunVersion", m.global.app.version)
Expand All @@ -72,6 +73,34 @@ sub Main (args as dynamic) as void
end if
end if

' Registry migrations
if isValid(appLastRunVersion) and not versionChecker(appLastRunVersion, "1.7.0")
' last app version used less than 1.7.0
' no longer saving raw password to registry
' auth token and username are now stored in user settings and not global settings
print "Running 1.7.0 registry migrations"
' remove global settings
unset_setting("token")
unset_setting("username")
unset_setting("password")
' remove user settings
unset_user_setting("password")
' remove saved credentials from saved_servers
saved = get_setting("saved_servers")
if isValid(saved)
savedServers = ParseJson(saved)
if isValid(savedServers.serverList) and savedServers.serverList.Count() > 0
newServers = { serverList: [] }
for each item in savedServers.serverList
item.Delete("username")
item.Delete("password")
newServers.serverList.Push(item)
end for
set_setting("saved_servers", FormatJson(newServers))
end if
end if
end if

' Handle input messages
input = CreateObject("roInput")
input.SetMessagePort(m.port)
Expand Down Expand Up @@ -524,6 +553,10 @@ sub Main (args as dynamic) as void
SignOut(false)
sceneManager.callFunc("clearScenes")
goto app_start
else if button.id = "change_user"
SignOut(false)
sceneManager.callFunc("clearScenes")
goto app_start
else if button.id = "sign_out"
SignOut()
sceneManager.callFunc("clearScenes")
Expand Down
Loading