diff --git a/CHANGELOG.md b/CHANGELOG.md index e493aa58..82d5c9c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,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.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] +### Added +- Version check in settings page + ## [0.4.0] - 2022-11-24 ### Added - Play video API diff --git a/src/components/SettingsScreen/AppVersionTask.bs b/src/components/SettingsScreen/AppVersionTask.bs new file mode 100644 index 00000000..529f9531 --- /dev/null +++ b/src/components/SettingsScreen/AppVersionTask.bs @@ -0,0 +1,25 @@ +import "pkg:/source/utils/General.bs" +import "pkg:/source/roku_modules/rokurequests/Requests.brs" + +function Init() + m.top.functionName = "TaskMain" +end function + +function TaskMain() + latest = "N/A" + response = Requests().request("HEAD", "https://github.com/iBicha/playlet/releases/latest", invalid) + + if response.statusCode = 200 + if response.headers.location <> invalid + regex = CreateObject("roRegex", "/v?(\d+\.\d+\.\d+)", "") + match = regex.match(response.headers.location) + if match.Count() = 2 + latest = match[1] + end if + end if + end if + + m.top.setField("output", { + latest: latest + }) +end function diff --git a/src/components/SettingsScreen/AppVersionTask.xml b/src/components/SettingsScreen/AppVersionTask.xml new file mode 100644 index 00000000..1b3ffd70 --- /dev/null +++ b/src/components/SettingsScreen/AppVersionTask.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/components/SettingsScreen/SettingsScreen.bs b/src/components/SettingsScreen/SettingsScreen.bs index 37392459..e261ad03 100644 --- a/src/components/SettingsScreen/SettingsScreen.bs +++ b/src/components/SettingsScreen/SettingsScreen.bs @@ -1,7 +1,13 @@ import "pkg:/source/utils/General.bs" +import "pkg:/source/roku_modules/rokupromise/Promise.brs" function Init() + m.versionLabel = m.top.findNode("VersionLabel") m.top.url = `http:/${GetLocalIpAddress()}:8888` + appInfo = GetAppInfo() + m.currentVersion = appInfo.version + SetVersionLabel(m.currentVersion, "N/A") + GetLatestVersion() end function function OnUrlSet() @@ -13,3 +19,17 @@ function OnUrlSet() urlLabel = m.top.findNode("urlLabel") urlLabel.text = url end function + +function GetLatestVersion() + createTaskPromise("AppVersionTask", { + input: {} + }).then(function(task as object) as void + if task.output.latest <> invalid + SetVersionLabel(m.currentVersion, task.output.latest) + end if + end function) +end function + +function SetVersionLabel(current as string, latest as string) + m.versionLabel.text = `Version: ${current} | Latest: ${latest}` +end function diff --git a/src/components/SettingsScreen/SettingsScreen.xml b/src/components/SettingsScreen/SettingsScreen.xml index c1eb87b8..5b3754f7 100644 --- a/src/components/SettingsScreen/SettingsScreen.xml +++ b/src/components/SettingsScreen/SettingsScreen.xml @@ -5,12 +5,20 @@ +