fix migration logic. track lastrunversion per user

This commit is contained in:
Charles Ewert 2023-09-21 14:12:15 -04:00
parent 7a610a1140
commit a466048010
4 changed files with 58 additions and 22 deletions

View File

@ -61,30 +61,15 @@ sub Main (args as dynamic) as void
end if
end if
' Only show the Whats New popup the first time a user runs a new client version.
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)
dialog = createObject("roSGNode", "WhatsNewDialog")
m.scene.dialog = dialog
m.scene.dialog.observeField("buttonSelected", m.port)
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
' Global registry migrations
if isValid(m.global.app.lastRunVersion) and not versionChecker(m.global.app.lastRunVersion, "1.7.0")
' last app version used was less than 1.7.0
print "Running 1.7.0 global registry migrations"
' 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)
@ -99,6 +84,42 @@ sub Main (args as dynamic) as void
set_setting("saved_servers", FormatJson(newServers))
end if
end if
' now saving LastRunVersion globally and per user so that we can run user specific registry migrations
' duplicate LastRunVersion to all user settings in the registry so that we can run user specific migrations
regSections = getRegistrySections()
for each section in regSections
if section <> "Jellyfin"
registry_write("LastRunVersion", m.global.app.version, section)
end if
end for
end if
' User registry migrations
if m.global.session.user.lastRunVersion <> invalid and not versionChecker(m.global.session.user.lastRunVersion, "1.7.0")
' last run version was less than 1.7.0
print "Running 1.7.0 user registry migrations"
' no longer saving password to registry
unset_user_setting("password")
end if
' Save the global last run version of the app
if m.global.app.version <> m.global.app.lastRunVersion
' update global LastRunVersion
set_setting("LastRunVersion", m.global.app.version)
' Show the Whats New popup
if m.global.session.user.settings["load.allowwhatsnew"] = true
dialog = createObject("roSGNode", "WhatsNewDialog")
m.scene.dialog = dialog
m.scene.dialog.observeField("buttonSelected", m.port)
end if
end if
' Save the user last run version of the app
if m.global.session.user.lastRunVersion <> m.global.app.lastRunVersion
' update user LastRunVersion
set_user_setting("LastRunVersion", m.global.app.version)
session.user.Update("lastRunVersion", m.global.app.version)
end if
' Handle input messages

View File

@ -37,7 +37,7 @@ function RegistryReadAll(section as string) as dynamic
registryData = {}
for each item in regKeyList
' ignore session related tokens
if item <> "token" and item <> "username" and item <> "password"
if item <> "token" and item <> "username" and item <> "password" and item <> "LastRunVersion"
if registry.Exists(item)
registryData.AddReplace(item, registry.Read(item))
end if
@ -47,6 +47,12 @@ function RegistryReadAll(section as string) as dynamic
return registryData
end function
' Return an array of all the registry section keys
function getRegistrySections() as object
registry = CreateObject("roRegistry")
return registry.GetSectionList()
end function
' "Jellyfin" registry accessors for the default global settings
function get_setting(key, default = invalid)
value = registry_read(key, "Jellyfin")

View File

@ -28,11 +28,13 @@ end sub
' Save information from roAppInfo to m.global.app
sub SaveAppToGlobal()
appInfo = CreateObject("roAppInfo")
lastRunVersion = get_setting("LastRunVersion")
m.global.addFields({
app: {
id: appInfo.GetID(),
isDev: appInfo.IsDev(),
version: appInfo.GetVersion()
version: appInfo.GetVersion(),
lastRunVersion: lastRunVersion
}
})
end sub

View File

@ -11,7 +11,8 @@ namespace session
user: {
Configuration: {},
Policy: {},
settings: {}
settings: {},
lastRunVersion: invalid
}
}
})
@ -146,6 +147,12 @@ namespace session
' update global user session
session.Update("user", tmpSession.user)
' grab lastRunVersion for this user
lastRunVersion = get_user_setting("LastRunVersion")
if lastRunVersion <> invalid
session.user.Update("LastRunVersion", lastRunVersion)
end if
' update user session settings with values from registry
userSettings = RegistryReadAll(tmpSession.user.id)
for each setting in userSettings