Files
playlet-piped/playlet-lib/src/source/services/ApplicationInfo.bs
T

153 lines
4.9 KiB
Plaintext

import "pkg:/source/utils/StringUtils.bs"
class ApplicationInfo
public node as object
public roDeviceInfo as object
public roAppInfo as object
function new(node as object)
m.node = node
m.roDeviceInfo = CreateObject("roDeviceInfo")
m.roAppInfo = CreateObject("roAppInfo")
end function
function GetLocalIpAddress() as dynamic
if StringUtils.IsNullOrEmpty(m.ipAddress)
ips = m.roDeviceInfo.GetIPAddrs()
for each ip in ips
m.ipAddress = ips[ip]
return m.ipAddress
end for
end if
return m.ipAddress
end function
function GetUserCountryCode() as string
if StringUtils.IsNullOrEmpty(m.countryCode)
m.countryCode = m.roDeviceInfo.GetUserCountryCode()
end if
return m.countryCode
end function
function GetAppInfo() as object
if m.appInfo = invalid
m.appInfo = {
id: m.roAppInfo.GetID()
app_version: m.roAppInfo.GetVersion()
app_git_commit_hash: m.roAppInfo.GetValue("git_commit_sha")
lib_version: m.GetLibVersion()
lib_git_commit_hash: m.GetLibGitCommitHash()
}
m.appInfo["lib_version_latest"] = "N/A"
m.appInfo["lib_url"] = "N/A"
m.appInfo["lib_url_type"] = "N/A"
scene = m.node.getScene()
if scene.playletLibLoadedUrl <> invalid
m.appInfo["lib_url"] = scene.playletLibLoadedUrl.link
m.appInfo["lib_url_type"] = scene.playletLibLoadedUrl.type
end if
end if
if m.appInfo.lib_version_latest = "N/A"
if not StringUtils.IsNullOrEmpty(m.node.lib_version_latest)
m.appInfo["lib_version_latest"] = m.node.lib_version_latest
else
m.node@.GetLatestPlayletLibVersion()
end if
end if
return m.appInfo
end function
function GetDeviceInfo() as object
if m.deviceInfo = invalid
m.deviceInfo = {
model: m.roDeviceInfo.GetModel()
model_display_name: m.roDeviceInfo.GetModelDisplayName()
model_type: m.roDeviceInfo.GetModelType()
model_details: m.roDeviceInfo.GetModelDetails()
os_version: m.roDeviceInfo.GetOSVersion()
display_type: m.roDeviceInfo.GetDisplayType()
display_mode: m.roDeviceInfo.GetDisplayMode()
display_aspect_ratio: m.roDeviceInfo.GetDisplayAspectRatio()
display_size: m.roDeviceInfo.GetDisplaySize()
video_mode: m.roDeviceInfo.GetVideoMode()
ui_resolution: m.roDeviceInfo.GetUIResolution()
graphics_platform: m.roDeviceInfo.GetGraphicsPlatform()
internet_status: m.roDeviceInfo.GetInternetStatus()
user_country_code: m.roDeviceInfo.GetUserCountryCode()
friendly_name: m.roDeviceInfo.GetFriendlyName()
current_locale: m.roDeviceInfo.GetCurrentLocale()
}
end if
return m.deviceInfo
end function
function GetLibVersion() as string
values = m.GetLibManifestValues()
if values = invalid
return "0.0.0"
end if
major = 0
minor = 0
build = 0
if values.DoesExist("major_version")
value = values["major_version"]
if IsString(value)
major = value.toInt()
end if
end if
if values.DoesExist("minor_version")
value = values["minor_version"]
if IsString(value)
minor = value.toInt()
end if
end if
if values.DoesExist("build_version")
value = values["build_version"]
if IsString(value)
build = value.toInt()
end if
end if
return `${major}.${minor}.${build}`
end function
function GetLibGitCommitHash() as string
values = m.GetLibManifestValues()
if values.DoesExist("git_commit_sha")
return values["git_commit_sha"]
end if
return ""
end function
function GetLibManifestValues() as object
if m.libManifestValues = invalid
libManifest = ReadAsciiFile("libpkg:/manifest")
lines = libManifest.Tokenize(`\n`)
values = {}
for each line in lines
if line.left(1) = "#"
continue for
end if
keyValuePair = line.Tokenize("=")
if keyValuePair.Count() <> 2
continue for
end if
values[keyValuePair[0]] = keyValuePair[1]
end for
m.libManifestValues = values
end if
return m.libManifestValues
end function
end class