From 2c1306c5639f56d854c3fe3a00ab1a98732c837a Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 23 Dec 2024 12:13:35 -0500 Subject: [PATCH] Fixed start up crash on older OS version (11.5) --- CHANGELOG.md | 6 ++++++ playlet-lib/src/components/Logger/Logger.bs | 3 ++- .../LoungeGenerateManualPairingCodeTask.bs | 3 ++- .../Web/PlayletWebServer/Middleware/DialRouter.bs | 3 ++- .../PlayletWebServer/Middleware/StateApiRouter.bs | 3 ++- playlet-lib/src/source/utils/MessagePortUtils.bs | 12 ++++++++++++ 6 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 playlet-lib/src/source/utils/MessagePortUtils.bs diff --git a/CHANGELOG.md b/CHANGELOG.md index 59861818..dbee2c8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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] + +### Fixed + +- Start up crash on older OS version (11.5) + ## [0.34.1] - 2024-12-23 ### Fixed diff --git a/playlet-lib/src/components/Logger/Logger.bs b/playlet-lib/src/components/Logger/Logger.bs index 139c0f54..c174546c 100644 --- a/playlet-lib/src/components/Logger/Logger.bs +++ b/playlet-lib/src/components/Logger/Logger.bs @@ -1,4 +1,5 @@ import "pkg:/source/utils/Logging.bs" +import "pkg:/source/utils/MessagePortUtils.bs" import "pkg:/source/utils/StringUtils.bs" import "pkg:/source/utils/Types.bs" @@ -10,7 +11,7 @@ function Init() m.top.ObserveField("logLine", port) scene = m.top.getScene() - scene.ObserveFieldScopedEx("systemLogEvent", port) + MessagePortUtils.ObserveFieldScopedExSafe(scene, "systemLogEvent", port) m.port = port diff --git a/playlet-lib/src/components/Services/LoungeService/LoungeGenerateManualPairingCodeTask.bs b/playlet-lib/src/components/Services/LoungeService/LoungeGenerateManualPairingCodeTask.bs index e9104179..860e3da3 100644 --- a/playlet-lib/src/components/Services/LoungeService/LoungeGenerateManualPairingCodeTask.bs +++ b/playlet-lib/src/components/Services/LoungeService/LoungeGenerateManualPairingCodeTask.bs @@ -1,5 +1,6 @@ import "pkg:/components/Services/LoungeService/LoungeApi.bs" import "pkg:/source/services/HttpClient.bs" +import "pkg:/source/utils/MessagePortUtils.bs" import "pkg:/source/utils/StringUtils.bs" @asynctask @@ -8,7 +9,7 @@ function LoungeGenerateManualPairingCodeTask(input as object) as object if StringUtils.IsNullOrEmpty(input.loungeToken) messagePort = CreateObject("roMessagePort") - loungeService.observeFieldScopedEx("loungeToken", messagePort) + MessagePortUtils.ObserveFieldScopedExSafe(loungeService, "loungeToken", messagePort) loungeService.join = true message = wait(30000, messagePort) loungeService.unobserveFieldScoped("loungeToken") diff --git a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/DialRouter.bs b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/DialRouter.bs index 333393c9..37da58fe 100644 --- a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/DialRouter.bs +++ b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/DialRouter.bs @@ -1,4 +1,5 @@ import "pkg:/source/services/XmlObject.bs" +import "pkg:/source/utils/MessagePortUtils.bs" namespace Http @@ -67,7 +68,7 @@ namespace Http loungeToken = m.loungeService.loungeToken if StringUtils.IsNullOrEmpty(loungeToken) messagePort = CreateObject("roMessagePort") - m.loungeService.observeFieldScopedEx("loungeToken", messagePort) + MessagePortUtils.ObserveFieldScopedExSafe(m.loungeService, "loungeToken", messagePort) m.loungeService.join = true message = wait(30000, messagePort) m.loungeService.unobserveFieldScoped("loungeToken") diff --git a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/StateApiRouter.bs b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/StateApiRouter.bs index 5be1b6a9..4bf658a1 100644 --- a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/StateApiRouter.bs +++ b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/StateApiRouter.bs @@ -1,3 +1,4 @@ +import "pkg:/source/utils/MessagePortUtils.bs" import "pkg:/source/utils/Types.bs" namespace Http @@ -42,7 +43,7 @@ namespace Http ' If the lib_version_latest field is not available, we can give it a few seconds ' To make a request to Github to get the latest version. msgPort = CreateObject("roMessagePort") - m.applicationInfoNode.observeFieldScopedEx("lib_version_latest", msgPort) + MessagePortUtils.ObserveFieldScopedExSafe(m.applicationInfoNode, "lib_version_latest", msgPort) wait(5000, msgPort) m.applicationInfoNode.unobserveFieldScoped("lib_version_latest") diff --git a/playlet-lib/src/source/utils/MessagePortUtils.bs b/playlet-lib/src/source/utils/MessagePortUtils.bs new file mode 100644 index 00000000..6581b79e --- /dev/null +++ b/playlet-lib/src/source/utils/MessagePortUtils.bs @@ -0,0 +1,12 @@ +namespace MessagePortUtils + + function ObserveFieldScopedExSafe(node as dynamic, field as string, port as dynamic) + ' ObserveFieldScopedEx was added in 12.0 + if FindMemberFunction(node, "ObserveFieldScopedEx") <> invalid + node.ObserveFieldScopedEx(field, port) + else + node.ObserveFieldScoped(field, port) + end if + end function + +end namespace