Merge pull request #1293 from cewert/update-loginflow

This commit is contained in:
Charles Ewert 2023-06-29 13:03:04 -04:00 committed by GitHub
commit 931e2c8237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 41 deletions

View File

@ -5,7 +5,10 @@ function LoginFlow(startOver = false as boolean)
serverUrl = get_setting("server")
if isValid(serverUrl)
print "Previous server connection saved to registry"
session.server.UpdateURL(serverUrl)
startOver = not session.server.UpdateURL(serverUrl)
if startOver
print "Could not connect to previously saved server."
end if
else
startOver = true
print "No previous server connection saved to registry"
@ -245,6 +248,11 @@ function CreateServerGroup()
else if type(msg) = "roSGNodeEvent"
node = msg.getNode()
if node = "submit"
' Show Connecting to Server spinner
dialog = createObject("roSGNode", "ProgressDialog")
dialog.title = tr("Connecting to Server")
m.scene.dialog = dialog
serverUrl = standardize_jellyfin_url(screen.serverUrl)
'If this is a different server from what we know, reset username/password setting
if m.global.session.server.url <> serverUrl
@ -252,42 +260,46 @@ function CreateServerGroup()
set_setting("password", "")
end if
set_setting("server", serverUrl)
session.server.UpdateURL(serverUrl)
' Show Connecting to Server spinner
dialog = createObject("roSGNode", "ProgressDialog")
dialog.title = tr("Connecting to Server")
m.scene.dialog = dialog
serverInfoResult = ServerInfo()
isConnected = session.server.UpdateURL(serverUrl)
serverInfoResult = invalid
if isConnected
serverInfoResult = ServerInfo()
end if
dialog.close = true
if serverInfoResult = invalid
if isConnected = false or serverInfoResult = invalid
' Maybe don't unset setting, but offer as a prompt
' Server not found, is it online? New values / Retry
print "Server not found, is it online? New values / Retry"
screen.errorMessage = tr("Server not found, is it online?")
SignOut(false)
else if isValid(serverInfoResult.Error) and serverInfoResult.Error
' If server redirected received, update the URL
if isValid(serverInfoResult.UpdatedUrl)
serverUrl = serverInfoResult.UpdatedUrl
set_setting("server", serverUrl)
session.server.UpdateURL(serverUrl)
end if
' Display Error Message to user
message = tr("Error: ")
if isValid(serverInfoResult.ErrorCode)
message = message + "[" + serverInfoResult.ErrorCode.toStr() + "] "
end if
screen.errorMessage = message + tr(serverInfoResult.ErrorMessage)
SignOut(false)
else
screen.visible = false
if isValid(serverInfoResult.serverName)
return serverInfoResult.ServerName + " (Saved)"
if isValid(serverInfoResult.Error) and serverInfoResult.Error
' If server redirected received, update the URL
if isValid(serverInfoResult.UpdatedUrl)
serverUrl = serverInfoResult.UpdatedUrl
set_setting("server", serverUrl)
isConnected = session.server.UpdateURL(serverUrl)
if isConnected
screen.visible = false
return ""
end if
end if
' Display Error Message to user
message = tr("Error: ")
if isValid(serverInfoResult.ErrorCode)
message = message + "[" + serverInfoResult.ErrorCode.toStr() + "] "
end if
screen.errorMessage = message + tr(serverInfoResult.ErrorMessage)
SignOut(false)
else
return "Saved"
screen.visible = false
if isValid(serverInfoResult.serverName)
return serverInfoResult.ServerName + " (Saved)"
else
return "Saved"
end if
end if
end if
else if node = "delete_saved"

View File

@ -90,13 +90,15 @@ function ServerInfo()
' set the server to new location and try again
if right(headers.location, 19) = "/System/Info/Public"
set_setting("server", left(headers.location, len(headers.location) - 19))
session.server.UpdateURL(left(headers.location, len(headers.location) - 19))
info = ServerInfo()
if info.Error
info.UpdatedUrl = left(headers.location, len(headers.location) - 19)
info.ErrorMessage = info.ErrorMessage + " (Note: Server redirected us to " + info.UpdatedUrl + ")"
isConnected = session.server.UpdateURL(left(headers.location, len(headers.location) - 19))
if isConnected
info = ServerInfo()
if info.Error
info.UpdatedUrl = left(headers.location, len(headers.location) - 19)
info.ErrorMessage = info.ErrorMessage + " (Note: Server redirected us to " + info.UpdatedUrl + ")"
end if
return info
end if
return info
end if
end if

View File

@ -59,21 +59,29 @@ namespace session
end sub
' Add or update the jellyfin server URL from the global server session array (m.global.session.server)
sub UpdateURL(value as string)
' Returns a boolean based on if a connection to the Jellyfin server was made
function UpdateURL(value as string) as boolean
' validate parameters
if value = "" then return
if value = "" then return false
session.server.Update("url", value)
session.server.Populate()
end sub
success = session.server.Populate()
if not success
session.server.Delete()
end if
return success
end function
' Use the saved server url to populate the global server session array (m.global.session.server)
sub Populate()
' Returns a boolean based on if a connection to the Jellyfin server was made
function Populate() as boolean
' validate server url
if m.global.session.server.url = invalid or m.global.session.server.url = "" then return
if m.global.session.server.url = invalid or m.global.session.server.url = "" then return false
' get server info using API
myServerInfo = ServerInfo()
' validate data returned from API
if myServerInfo.id = invalid then return
if myServerInfo.id = invalid then return false
' make copy of global server session
tmpSessionServer = m.global.session.server
' update the temp array
@ -93,7 +101,8 @@ namespace session
tmpSessionServer.AddReplace("isLocalHTTPS", isLocalServerHTTPS)
' update global server session using the temp array
session.Update("server", tmpSessionServer)
end sub
return true
end function
end namespace
namespace user