diff --git a/playlet-lib/src/components/Logger/Logger.bs b/playlet-lib/src/components/Logger/Logger.bs index b923fa01..568d4b8d 100644 --- a/playlet-lib/src/components/Logger/Logger.bs +++ b/playlet-lib/src/components/Logger/Logger.bs @@ -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