jf-roku/source/migrations.bs
1hitsong 40925199d4 Review Updates & Bug Fix
Fix Roku component reuse bug
Don't repeat loadingTimer
Move ImageSizes enum to source folder
Update setting text & translation
Check selectedRowItem is valid and not empty
2023-11-26 12:12:33 -05:00

96 lines
4.1 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)
' last app version used < CLIENT_VERSION_REQUIRING_BASE_MIGRATION
m.wasMigrated = true
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
' migrate saved credentials for "active_user" if found
savedUserId = get_setting("active_user")
if isValid(savedUserId)
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
' remove settings from global "jellyfin" registry block
unset_setting("port")
unset_setting("token")
unset_setting("username")
unset_setting("password")
' remove any saved credentials found in saved_servers assocArray
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}`
' If this is an existing user, set the useWebSectionArrangement setting to false
' This way the home view for upgrading users is not changed without them opting in
useWebSectionArrangement = registry_read("ui.home.useWebSectionArrangement", section)
if not isValid(useWebSectionArrangement)
registry_write("ui.home.useWebSectionArrangement", "false", section)
end if
' 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