Skip to main content
The registry manager provides read, write, and delete helpers that all operate within the "GlobalTV" registry section. Higher-level helpers handle credentials, server state, and UI preferences as typed values.

Registry section and keys

All data is stored in the GlobalTV section of the Roku persistent registry (roRegistrySection). | Key constant | Registry key | Value type | Description | |--------------------------|----------------------|------------|--------------------------------------------|| | REG_KEY_USER | username | String | Authenticated username | | REG_KEY_PASS | password | String | Authenticated password | | REG_KEY_SERVER | lastServer | String | Last successfully used server base URL | | REG_KEY_CHANNEL | lastChannelIndex | String | Last viewed channel index (integer) | | REG_KEY_SAFE_MARGIN | uiSafeMarginPct | String | UI safe-area margin percentage (0–10) | | REG_KEY_SERVER_PROFILES| serverProfiles | String | JSON-encoded array of server profile objects |

Low-level functions

GTV_RegRead

function GTV_RegRead(key as String, defaultVal = "" as String) as String
Reads a value from the GlobalTV registry section.
key
String
required
The registry key to read.
defaultVal
String
Value returned when the key does not exist. Defaults to "".
Return value — The stored string, or defaultVal if the key is absent.

GTV_RegWrite

sub GTV_RegWrite(key as String, value as String)
Writes a value to the GlobalTV registry section and immediately calls Flush() to persist it to disk.
key
String
required
The registry key to write.
value
String
required
The string value to store.

GTV_RegDelete

sub GTV_RegDelete(key as String)
Deletes a key from the GlobalTV registry section if it exists, then calls Flush().
key
String
required
The registry key to delete.

Credential functions

GTV_RegHasCredentials

function GTV_RegHasCredentials() as Boolean
Returns true if both username and password keys are non-empty in the registry.

GTV_RegLoadCredentials

function GTV_RegLoadCredentials() as Object
Loads stored credentials. Return value — An roAssociativeArray {username: String, password: String}, or invalid if either value is empty. Example
creds = GTV_RegLoadCredentials()
if creds <> invalid
    ' Proceed with auto-login
    GTV_Log("Auth", "Resuming session for " + creds.username)
end if

GTV_RegSaveCredentials

sub GTV_RegSaveCredentials(username as String, password as String)
Persists username and password to the registry.
username
String
required
The username to store.
password
String
required
The password to store.

GTV_RegClearCredentials

sub GTV_RegClearCredentials()
Deletes both username and password keys from the registry. Use this on logout or auth failure. Example
' On logout
GTV_RegClearCredentials()
GTV_RegClearCache()
m.global.isAuthenticated = false

Session cache functions

GTV_RegClearCache

sub GTV_RegClearCache()
Deletes the lastServer and lastChannelIndex keys. Call this when you want to force a fresh server probe and channel reset on the next launch.

GTV_RegLoadLastServer

function GTV_RegLoadLastServer() as String
Reads the last-used server URL and passes it through GTV_ServerNormalizeBaseUrl before returning. Returns "" if no server has been saved.

GTV_RegSaveLastServer

sub GTV_RegSaveLastServer(serverUrl as String)
Normalizes serverUrl and writes it to the lastServer registry key.

GTV_RegLoadLastChannelIndex

function GTV_RegLoadLastChannelIndex() as Integer
Returns the last-viewed channel index as an integer. Returns 0 if the key is absent.

GTV_RegSaveLastChannelIndex

sub GTV_RegSaveLastChannelIndex(idx as Integer)
Stores the channel index as a string (idx.ToStr()).

UI preference functions

GTV_RegLoadSafeMarginPct

function GTV_RegLoadSafeMarginPct() as Integer
Reads the UI safe-area margin percentage from the registry. Falls back to GTV_GetSafeMarginPct() (the AppConstants default) if the key is absent. The returned value is clamped to UI_SAFE_MARGIN_MIN_PCTUI_SAFE_MARGIN_MAX_PCT (0–10).

GTV_RegSaveSafeMarginPct

sub GTV_RegSaveSafeMarginPct(pct as Integer)
Clamps pct to the 0–10 range and writes it to the registry.
pct
Integer
required
Desired safe-area margin as a whole-number percentage (0–10).

Persistence model

Every write calls roRegistrySection.Flush() immediately. There is no deferred batching — each GTV_RegWrite or GTV_RegDelete call is a synchronous disk operation.
Credentials are stored as plain strings in the Roku registry. The registry is private to the channel and cleared when the channel is uninstalled from the device.
' Typical login flow
GTV_RegSaveCredentials(username, password)
GTV_RegSaveLastServer(activeServer)

' Typical logout flow
GTV_RegClearCredentials()
GTV_RegClearCache()

Build docs developers (and LLMs) love