Use functions to save app and device data to global

This commit is contained in:
Charles Ewert 2023-04-22 14:57:35 -04:00
parent 8939ecc9c5
commit ece472b91c
2 changed files with 39 additions and 35 deletions

View File

@ -24,41 +24,8 @@ sub Main (args as dynamic) as void
m.global.addFields({ queueManager: CreateObject("roSGNode", "QueueManager") })
m.global.addFields({ audioPlayer: CreateObject("roSGNode", "AudioPlayer") })
appInfo = CreateObject("roAppInfo")
m.global.addFields({
app: {
id: appInfo.GetID(),
isDev: appInfo.IsDev(),
version: appInfo.GetVersion()
}
})
' delete object
appInfo = invalid 'bs:disable-line
deviceInfo = CreateObject("roDeviceInfo")
' remove special characters
regex = CreateObject("roRegex", "[^a-zA-Z0-9\ \-\_]", "")
filteredFriendly = regex.ReplaceAll(deviceInfo.getFriendlyName(), "")
m.global.addFields({
device: {
id: deviceInfo.getChannelClientID(),
uuid: deviceInfo.GetRandomUUID(),
name: deviceInfo.getModelDisplayName(),
friendlyName: filteredFriendly,
model: deviceInfo.GetModel(),
modelType: deviceInfo.GetModelType(),
osVersion: deviceInfo.GetOSVersion(),
locale: deviceInfo.GetCurrentLocale(),
clockFormat: deviceInfo.GetClockFormat(),
isAudioGuideEnabled: deviceInfo.IsAudioGuideEnabled(),
hasVoiceRemote: deviceInfo.HasFeature("voice_remote"),
displayType: deviceInfo.GetDisplayType(),
displayMode: deviceInfo.GetDisplayMode()
}
})
' delete object
deviceInfo = invalid 'bs:disable-line
SaveAppToGlobal()
SaveDeviceToGlobal()
app_start:
' First thing to do is validate the ability to use the API

37
source/utils/globals.brs Normal file
View File

@ -0,0 +1,37 @@
' Save information from roAppInfo to m.global.app
sub SaveAppToGlobal()
appInfo = CreateObject("roAppInfo")
m.global.addFields({
app: {
id: appInfo.GetID(),
isDev: appInfo.IsDev(),
version: appInfo.GetVersion()
}
})
end sub
' Save information from roDeviceInfo to m.global.device
sub SaveDeviceToGlobal()
deviceInfo = CreateObject("roDeviceInfo")
' remove special characters
regex = CreateObject("roRegex", "[^a-zA-Z0-9\ \-\_]", "")
filteredFriendly = regex.ReplaceAll(deviceInfo.getFriendlyName(), "")
m.global.addFields({
device: {
id: deviceInfo.getChannelClientID(),
uuid: deviceInfo.GetRandomUUID(),
name: deviceInfo.getModelDisplayName(),
friendlyName: filteredFriendly,
model: deviceInfo.GetModel(),
modelType: deviceInfo.GetModelType(),
osVersion: deviceInfo.GetOSVersion(),
locale: deviceInfo.GetCurrentLocale(),
clockFormat: deviceInfo.GetClockFormat(),
isAudioGuideEnabled: deviceInfo.IsAudioGuideEnabled(),
hasVoiceRemote: deviceInfo.HasFeature("voice_remote"),
displayType: deviceInfo.GetDisplayType(),
displayMode: deviceInfo.GetDisplayMode()
}
})
end sub