jf-roku/source/migrations.bs
2023-11-15 22:19:23 -05:00

88 lines
3.7 KiB
Plaintext

import "pkg:/source/utils/misc.bs"
import "pkg:/source/utils/conditional.bs"
' @fileoverview Functions that update the registry based on the last run version and the currently running version
const CLIENT_VERSION_REQUIRING_BASE_MIGRATION = "2.0.0"
' Run all necessary registry mirations on the "global" Jellyfin registry section
sub runGlobalMigrations()
appLastRunVersion = m.global.app.lastRunVersion
' Global registry migrations
if isValid(appLastRunVersion) and not versionChecker(appLastRunVersion, CLIENT_VERSION_REQUIRING_BASE_MIGRATION)
m.wasMigrated = true
' last app version used was less than CLIENT_VERSION_REQUIRING_BASE_MIGRATION
print `Running ${CLIENT_VERSION_REQUIRING_BASE_MIGRATION} global registry migrations`
' no longer saving raw password to registry
' auth token and username are now stored in user settings and not global settings
savedUserId = get_setting("active_user")
if isValid(savedUserId)
registry_write("serverId", m.global.session.server.id, savedUserId)
' copy saved credentials to user block
savedUsername = get_setting("username")
if isValid(savedUsername)
registry_write("username", savedUsername, savedUserId)
end if
savedToken = get_setting("token")
if isValid(savedToken)
registry_write("token", savedToken, savedUserId)
end if
end if
unset_setting("port")
unset_setting("token")
unset_setting("username")
unset_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
end sub
sub runRegistryUserMigrations()
regSections = getRegistrySections()
for each section in regSections
if LCase(section) <> "jellyfin"
reg = CreateObject("roRegistrySection", section)
if reg.exists("LastRunVersion")
hasUserVersion = true
lastRunVersion = reg.read("LastRunVersion")
else
hasUserVersion = false
' app versions < 2.0.0 didn't save LastRunVersion at the user level
' fall back to using the apps lastRunVersion
lastRunVersion = m.global.app.lastRunVersion
registry_write("LastRunVersion", m.global.app.version, section)
end if
' BASE_MIGRATION
if not versionChecker(lastRunVersion, CLIENT_VERSION_REQUIRING_BASE_MIGRATION)
m.wasMigrated = true
print `Running Registry Migration for ${CLIENT_VERSION_REQUIRING_BASE_MIGRATION} for userid: ${section}`
' no longer saving password to registry
registry_delete("password", section)
' av1 playback no longer hidden behind user setting
registry_delete("playback.av1", section)
end if
' update lastRunVersion if needed
if hasUserVersion and lastRunVersion <> m.global.app.version
registry_write("LastRunVersion", m.global.app.version, section)
end if
end if
end for
end sub