From 8f2bdbfa074bec7cebe0631af92c57e0dcc1ee93 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 8 Jul 2024 08:50:57 -0400 Subject: [PATCH] Move GetLastExitInfo call to playlet app --- CHANGELOG.md | 4 +++ playlet-app/src/source/Logger.bs | 29 +++++++++++++++++++++ playlet-app/src/source/Main.bs | 2 ++ playlet-lib/src/components/Logger/Logger.bs | 25 ------------------ 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff1f3191..00806d8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +- Nothing worth mentioning yet. + ## [0.24.6] - 2024-07-08 ### Fixed diff --git a/playlet-app/src/source/Logger.bs b/playlet-app/src/source/Logger.bs index 9c2abebb..f984fed9 100644 --- a/playlet-app/src/source/Logger.bs +++ b/playlet-app/src/source/Logger.bs @@ -17,4 +17,33 @@ namespace Logger buffer.AppendFile(LOGS_FILE_PATH) end function + function LogLastExitInfo() as void + ' roAppManager.GetLastExitInfo() is only available on Roku OS 13 and above + appManager = CreateObject("roAppManager") + hasMethod = FindMemberFunction(appManager, "GetLastExitInfo") <> invalid + if not hasMethod + return + end if + + lastExitInfo = appManager.GetLastExitInfo() + if lastExitInfo = invalid + return + end if + + msg = `************ Last Exit Info ************\n` + msg += `exit_code: ${lastExitInfo.exit_code}\n` + msg += `timestamp: ${lastExitInfo.timestamp}\n` + msg += `app_state: ${lastExitInfo.app_state}\n` + msg += `media_player_state: ${lastExitInfo.media_player_state}\n` + msg += `mem_limit: ${lastExitInfo.mem_limit}\n` + msg += `console_log:\n${lastExitInfo.console_log}\n` + msg += `********** End Last Exit Info **********\n` + + ' bs:disable-next-line LINT3012 + print(msg) + + buffer = CreateObject("roByteArray") + buffer.FromAsciiString(msg + `\n`) + buffer.AppendFile(LOGS_FILE_PATH) + end function end namespace diff --git a/playlet-app/src/source/Main.bs b/playlet-app/src/source/Main.bs index 9ce92b39..756feea3 100644 --- a/playlet-app/src/source/Main.bs +++ b/playlet-app/src/source/Main.bs @@ -24,6 +24,8 @@ function Main(args as object) as void Registry.ClearPlayletLibUrlsIfNeeded(args) Registry.ClearRegistryIfNeeded(args) + Logger.LogLastExitInfo() + scene = screen.CreateScene("BootstrapScene") screen.show() diff --git a/playlet-lib/src/components/Logger/Logger.bs b/playlet-lib/src/components/Logger/Logger.bs index d44ed8b2..e5126c0f 100644 --- a/playlet-lib/src/components/Logger/Logger.bs +++ b/playlet-lib/src/components/Logger/Logger.bs @@ -53,15 +53,6 @@ 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 - appMemoryMonitor = CreateObject("roAppMemoryMonitor") if appMemoryMonitor <> invalid and FindMemberFunction(appMemoryMonitor, "EnableMemoryWarningEvent") <> invalid appMemoryMonitor.SetMessagePort(port) @@ -175,19 +166,3 @@ 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 - appManager = CreateObject("roAppManager") - hasMethod = FindMemberFunction(appManager, "GetLastExitInfo") <> invalid - if not hasMethod - return invalid - end if - - lastExitInfo = appManager.GetLastExitInfo() - if lastExitInfo = invalid - return invalid - end if - - return ToString(lastExitInfo) -end function