From fea1c22aa9959b6d8961048a570d95ea76adc21f Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Wed, 12 Aug 2026 18:47:59 -0400 Subject: [PATCH] [skip ci] prevent crashes on older pinned versions of playlet-lib --- playlet-app/src/source/Main.bs | 1 + playlet-app/src/source/PlayletLibUrls.bs | 37 +++++++++++ playlet-app/src/source/PlayletLibUrls.spec.bs | 61 +++++++++++++++++++ playlet-app/src/source/Registry.bs | 19 ++++++ .../PlayletLibVersionControl.svelte | 35 +++++++---- 5 files changed, 142 insertions(+), 11 deletions(-) create mode 100644 playlet-app/src/source/PlayletLibUrls.bs create mode 100644 playlet-app/src/source/PlayletLibUrls.spec.bs diff --git a/playlet-app/src/source/Main.bs b/playlet-app/src/source/Main.bs index f853f5ac..ca868521 100644 --- a/playlet-app/src/source/Main.bs +++ b/playlet-app/src/source/Main.bs @@ -23,6 +23,7 @@ function Main(args as object) as void Registry.ClearPlayletLibUrlsIfNeeded(args) Registry.ClearRegistryIfNeeded(args) + Registry.ClearUnsupportedPlayletLibUrls() scene = screen.CreateScene("BootstrapScene") screen.show() diff --git a/playlet-app/src/source/PlayletLibUrls.bs b/playlet-app/src/source/PlayletLibUrls.bs new file mode 100644 index 00000000..6c8f7666 --- /dev/null +++ b/playlet-app/src/source/PlayletLibUrls.bs @@ -0,0 +1,37 @@ +namespace PlayletLibUrls + + const RELEASE_URL_PATTERN = "^https://github\.com/iBicha/playlet/releases/download/v(\d+\.\d+\.\d+)/" + + ' v0.11.0 is the first release without HomeGridScreen, which still crashes on the devices + ' pinned to v0.7.0 - v0.10.3. + const MIN_VERSION = "0.11.0" + + function IsUnsupported(entry as object) as boolean + matches = CreateObject("roRegex", RELEASE_URL_PATTERN, "").Match(entry.link) + if matches.Count() <> 2 + return false + end if + + return CompareVersions(matches[1], MIN_VERSION) < 0 + end function + + function CompareVersions(left as string, right as string) as integer + leftParts = left.Tokenize(".") + rightParts = right.Tokenize(".") + + for i = 0 to leftParts.Count() - 1 + leftPart = leftParts[i].ToInt() + rightPart = rightParts[i].ToInt() + + if leftPart < rightPart + return -1 + end if + if leftPart > rightPart + return 1 + end if + end for + + return 0 + end function + +end namespace diff --git a/playlet-app/src/source/PlayletLibUrls.spec.bs b/playlet-app/src/source/PlayletLibUrls.spec.bs new file mode 100644 index 00000000..bcae54fe --- /dev/null +++ b/playlet-app/src/source/PlayletLibUrls.spec.bs @@ -0,0 +1,61 @@ +namespace Tests + + @suite + class PlayletLibUrlsTests extends Rooibos.BaseTestSuite + + @describe("PlayletLibUrls.IsUnsupported") + + @it("reports a tagged release below the minimum version") + @params("https://github.com/iBicha/playlet/releases/download/v0.7.0/playlet-lib.zip") + @params("https://github.com/iBicha/playlet/releases/download/v0.9.0/playlet-lib.zip") + @params("https://github.com/iBicha/playlet/releases/download/v0.10.3/playlet-lib.zip") + @params("https://github.com/iBicha/playlet/releases/download/v0.10.3/playlet-lib.squashfs.pkg") + function _(link as string) + m.assertTrue(PlayletLibUrls.IsUnsupported({ type: "custom", link: link })) + end function + + @it("reports nothing for a tagged release at or above the minimum version") + @params("https://github.com/iBicha/playlet/releases/download/v0.11.0/playlet-lib.zip") + @params("https://github.com/iBicha/playlet/releases/download/v0.11.1/playlet-lib.zip") + @params("https://github.com/iBicha/playlet/releases/download/v0.48.3/playlet-lib.squashfs.pkg") + @params("https://github.com/iBicha/playlet/releases/download/v1.0.0/playlet-lib.zip") + function _(link as string) + m.assertFalse(PlayletLibUrls.IsUnsupported({ type: "custom", link: link })) + end function + + @it("reports nothing for a url that carries no version") + @params("https://github.com/iBicha/playlet/releases/latest/download/playlet-lib.zip") + @params("https://github.com/iBicha/playlet/releases/download/canary/playlet-lib.zip") + @params("https://github.com/iBicha/playlet/releases/download/0.10.3/playlet-lib.zip") + @params("http://192.168.1.10:8888/playlet-lib.zip") + @params("pkg:/lib/playlet-lib.zip") + @params("") + function _(link as string) + m.assertFalse(PlayletLibUrls.IsUnsupported({ type: "custom", link: link })) + end function + + @describe("PlayletLibUrls.CompareVersions") + + @it("reports the same version as equal") + function _() + m.assertEqual(PlayletLibUrls.CompareVersions("0.11.0", "0.11.0"), 0) + end function + + @it("orders by the first part that differs") + @params("0.10.3", "0.11.0") + @params("0.11.0", "0.11.1") + @params("0.11.0", "1.0.0") + function _(older as string, newer as string) + m.assertEqual(PlayletLibUrls.CompareVersions(older, newer), -1) + m.assertEqual(PlayletLibUrls.CompareVersions(newer, older), 1) + end function + + @it("compares parts as numbers, not text") + function _() + m.assertEqual(PlayletLibUrls.CompareVersions("0.9.0", "0.11.0"), -1) + m.assertEqual(PlayletLibUrls.CompareVersions("0.11.0", "0.9.0"), 1) + end function + + end class + +end namespace diff --git a/playlet-app/src/source/Registry.bs b/playlet-app/src/source/Registry.bs index a3c4a886..052d8730 100644 --- a/playlet-app/src/source/Registry.bs +++ b/playlet-app/src/source/Registry.bs @@ -1,3 +1,5 @@ +import "pkg:/source/PlayletLibUrls.bs" + namespace Registry function ReadKey(key as string, section as string) as dynamic @@ -41,6 +43,23 @@ namespace Registry Logger.Log("Cleared key playlet_lib_urls from registry") end function + ' BootstrapScene's load-failure fallback never reaches a pinned lib that loads and then + ' crashes, so the device stays on it across every channel update. + function ClearUnsupportedPlayletLibUrls() as void + urls = GetPlayletLibUrlsFromRegistry() + if urls = invalid + return + end if + + for each entry in urls + if PlayletLibUrls.IsUnsupported(entry) + DeleteKey("playlet_lib_urls", "Playlet") + Logger.Log(`Cleared key playlet_lib_urls from registry: ${entry.link} is no longer supported`) + return + end if + end for + end function + function ClearRegistryIfNeeded(launchArgs as object) as void if launchArgs = invalid or launchArgs.clearRegistry = invalid return diff --git a/playlet-web/src/lib/Screens/Settings/SettingControls/PlayletLibVersionControl.svelte b/playlet-web/src/lib/Screens/Settings/SettingControls/PlayletLibVersionControl.svelte index 07c2d659..6cf84f8c 100644 --- a/playlet-web/src/lib/Screens/Settings/SettingControls/PlayletLibVersionControl.svelte +++ b/playlet-web/src/lib/Screens/Settings/SettingControls/PlayletLibVersionControl.svelte @@ -12,6 +12,17 @@ let libUrlType; let appId = "693751"; + // Kept in step with PlayletLibUrls.MIN_VERSION in playlet-app, which drops anything older at boot. + const MIN_LIB_VERSION = "0.11.0"; + + function isSupported(tag) { + const version = /^v(\d+\.\d+\.\d+)$/.exec(tag ?? "")?.[1]; + return ( + !version || + version.localeCompare(MIN_LIB_VERSION, undefined, { numeric: true }) >= 0 + ); + } + onMount(async () => { releases = await fetchReleaseTags(); setCurrentlyUsedRelease(); @@ -62,17 +73,19 @@ break; } } - return releases.map((release) => { - return { - name: release.tag_name, - enabled: - release.assets.filter( - (asset) => - asset.name === "playlet-lib.zip" || - asset.name === "playlet-lib.squashfs.pkg" - ).length > 0, - }; - }); + return releases + .filter((release) => isSupported(release.tag_name)) + .map((release) => { + return { + name: release.tag_name, + enabled: + release.assets.filter( + (asset) => + asset.name === "playlet-lib.zip" || + asset.name === "playlet-lib.squashfs.pkg" + ).length > 0, + }; + }); } async function apply() {