Skip to content

Commit

Permalink
add last exit info
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed May 7, 2024
1 parent 9af9033 commit 18445fd
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions playlet-lib/src/components/Logger/Logger.bs
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 18445fd

Please sign in to comment.