add last exit info

This commit is contained in:
Brahim Hadriche committed 2024-05-06 20:58:38 -04:00
1 parent 9af9033462
commit 18445fdcc4
1 file changed
+35
@@ -1,5 +1,6 @@
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.bs"
function Init()
m.top.functionName = "LoggerLoop"
@@ -52,6 +53,15 @@ function LoggerLoop()
buffer.AppendFile(logsFile)
end if
lastExitInfo = GetLastExitInfo()
if not StringUtils.IsNullOrEmpty(lastExitInfo)
line = `************ Last Exit Info ************\n${lastExitInfo}\n********** End Last Exit Info **********\n`
' bs:disable-next-line LINT3012
print line
buffer.FromAsciiString(line)
buffer.AppendFile(logsFile)
end if
while true
msg = wait(0, port)
msgType = type(msg)
@@ -118,3 +128,28 @@ function FormatTime(dateTime as object) as string
return "[" + hours + ":" + minutes + ":" + seconds + "." + milliseconds + "]"
end function
function GetLastExitInfo() as dynamic
' roAppManager.GetLastExitInfo() is only available on Roku OS 13 and above
if not IsOs13OrHigher()
return invalid
end if
appManager = CreateObject("roAppManager")
lastExitInfo = appManager.GetLastExitInfo()
if lastExitInfo = invalid
return invalid
end if
return ToString(lastExitInfo)
end function
function IsOs13OrHigher() as boolean
deviceInfo = CreateObject("roDeviceInfo")
osVersion = deviceInfo.GetOSVersion()
if osVersion = invalid or StringUtils.IsNullOrEmpty(osVersion.major)
return false
end if
return ValidInt(osVersion.major.ToInt()) >= 13
end function