From 27d915c027f3aa00b6154dd0fe05be1810d4205d Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 23 Dec 2024 09:42:15 -0500 Subject: [PATCH] App version --- .../src/components/NavBar/AppVersionLabel.bs | 83 +++++++++++++++++++ .../src/components/NavBar/AppVersionLabel.xml | 2 + playlet-lib/src/components/NavBar/NavBar.xml | 10 ++- playlet-web/src/lib/NavBar.svelte | 5 ++ 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 playlet-lib/src/components/NavBar/AppVersionLabel.bs create mode 100644 playlet-lib/src/components/NavBar/AppVersionLabel.xml diff --git a/playlet-lib/src/components/NavBar/AppVersionLabel.bs b/playlet-lib/src/components/NavBar/AppVersionLabel.bs new file mode 100644 index 00000000..6634a53f --- /dev/null +++ b/playlet-lib/src/components/NavBar/AppVersionLabel.bs @@ -0,0 +1,83 @@ +import "pkg:/source/utils/Types.bs" + +const LIB_CANARY_ZIP_URL = "https://github.com/iBicha/playlet/releases/download/canary/playlet-lib.zip" +const LIB_CANARY_SQUASHFS_URL = "https://github.com/iBicha/playlet/releases/download/canary/playlet-lib.squashfs.pkg" + +function Init() + m.top.text = GetAppVersion() +end function + +' TODO:P2: refactor and move to appropriate place, reuse with web app +function GetAppVersion() as string + version = "v" + GetLibVersion() + + roAppInfo = CreateObject("roAppInfo") + appId = roAppInfo.GetID() + if appId = "dev" + version += "-dev" + end if + + scene = m.top.getScene() + if scene.playletLibLoadedUrl <> invalid + libUrl = scene.playletLibLoadedUrl.link + libUrlType = scene.playletLibLoadedUrl.type + + if libUrlType = "custom" and (libUrl = LIB_CANARY_ZIP_URL or libUrl = LIB_CANARY_SQUASHFS_URL) + version += "-canary" + end if + end if + + return version +end function + +function GetLibVersion() as string + values = GetLibManifestValues() + if values = invalid + return "0.0.0" + end if + + major = 0 + minor = 0 + build = 0 + + if values.DoesExist("major_version") + value = values["major_version"] + if IsString(value) + major = value.toInt() + end if + end if + + if values.DoesExist("minor_version") + value = values["minor_version"] + if IsString(value) + minor = value.toInt() + end if + end if + + if values.DoesExist("build_version") + value = values["build_version"] + if IsString(value) + build = value.toInt() + end if + end if + + return `${major}.${minor}.${build}` +end function + +function GetLibManifestValues() as object + libManifest = ReadAsciiFile("libpkg:/manifest") + lines = libManifest.Tokenize(`\n`) + values = {} + for each line in lines + if line.left(1) = "#" + continue for + end if + keyValuePair = line.Tokenize("=") + if keyValuePair.Count() <> 2 + continue for + end if + + values[keyValuePair[0]] = keyValuePair[1] + end for + return values +end function diff --git a/playlet-lib/src/components/NavBar/AppVersionLabel.xml b/playlet-lib/src/components/NavBar/AppVersionLabel.xml new file mode 100644 index 00000000..207e7f8a --- /dev/null +++ b/playlet-lib/src/components/NavBar/AppVersionLabel.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/playlet-lib/src/components/NavBar/NavBar.xml b/playlet-lib/src/components/NavBar/NavBar.xml index a526c9dd..9720bcd9 100644 --- a/playlet-lib/src/components/NavBar/NavBar.xml +++ b/playlet-lib/src/components/NavBar/NavBar.xml @@ -38,7 +38,13 @@ height="42" translation="[20, 48]" opacity="0" - uri="pkg:/images/logo-dark.png" /> + uri="pkg:/images/logo-dark.png"> + + + translation="[15, 150]"> diff --git a/playlet-web/src/lib/NavBar.svelte b/playlet-web/src/lib/NavBar.svelte index bf592729..f3710ddc 100644 --- a/playlet-web/src/lib/NavBar.svelte +++ b/playlet-web/src/lib/NavBar.svelte @@ -43,6 +43,11 @@ ) { version += "-canary"; } + + if (version) { + version = `v${version}`; + } + return version; }