Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] BrighterScript v1alpha #430

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/bsconfig.base.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"lintConfig": "./config/bslint.jsonc",
"plugins": [
"@rokucommunity/bslint",
"../tools/bs-plugins/roku-types-plugin.ts",
"../tools/bs-plugins/asynctask-plugin.ts",
"../tools/bs-plugins/manifest-edit-plugin.ts",
"../tools/bs-plugins/component-includes-plugin.ts",
Expand Down
1 change: 1 addition & 0 deletions config/bsconfig.tests.base.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"plugins": [
"@rokucommunity/bslint",
"rooibos-roku",
"../tools/bs-plugins/roku-types-plugin.ts",
"../tools/bs-plugins/asynctask-plugin.ts",
"../tools/bs-plugins/manifest-edit-plugin.ts",
"../tools/bs-plugins/component-includes-plugin.ts",
Expand Down
13 changes: 13 additions & 0 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [Type Gen](#type-gen)
- [Web Server](#web-server)
- [Locale validation](#locale-validation)
- [Roku types](#roku-types)

Playlet implements a few [Brighterscript Plugins](https://github.com/rokucommunity/brighterscript/blob/master/docs/plugins.md). The plugins inject themselves in the compilation process, allowing the modification of bs scripts, xml components, and even assets or the app manifest. Let's start with a simple one:

Expand Down Expand Up @@ -623,3 +624,15 @@ The plugin checks for the following:
- `en_US` must have matching source and translation values, so it can act as a fallback translation.
- All `source` translations from all languages must be present in the `@locale` enums. This is to prevent renaming the values in the code without updating translation files.
- Translation `source` keys can't be used except for certain fields such as `"text"` and `"title"`. This is to prevent the accidental localization of non-display fields, such as node ids.

## Roku types

**[Source](/tools/bs-plugins/roku-types-plugin.ts)**

### Why

BrighterScript compiler contains a list of Roku types scraped from the documentation website. Sometimes documentation is not perfect, which causes false positives in validaiton. This plugin allows to patch the data types.

### How

We check if components/interfaces are linked correctly, and if not, override them. This is possible because the Roku types used by bsc are exported, and we're able to patch them before the program starts in the `beforeProgramCreate` hook. This is important because Roku types are populated on program creation.
1,258 changes: 847 additions & 411 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"version": "0.25.0",
"description": "Unofficial YouTube client for Roku",
"devDependencies": {
"@rokucommunity/bslint": "^0.8.21",
"@rokucommunity/bslint": "1.0.0-alpha.33",
"@types/crypto-js": "^4.2.2",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.14.11",
"@types/xml2js": "^0.4.14",
"argparse": "^2.0.1",
"brighterscript": "0.67.3",
"brighterscript": "1.0.0-alpha.33",
"brighterscript-formatter": "^1.7.3",
"convert-svg-to-png": "^0.6.4",
"cross-fetch": "^4.0.0",
Expand Down
2 changes: 2 additions & 0 deletions playlet-app/src/components/BootstrapScene/BootstrapScene.bs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function Init() as void
LoadPlayletLib()
end function

' TODO:P0 remove after fix
' bs:disable-next-line LINT2004
function GetPlayletLibUrls() as object
#if DEBUG
debug = { type: "debug-zip", link: Manifest.ReadValue("playlet_lib_zip_debug_url") }
Expand Down
8 changes: 4 additions & 4 deletions playlet-lib/src/components/AppController/AppController.bs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ end function

function PushScreen(node as object)
m.stack.appendChild(node)
FocusTopScreen(invalid)
FocusTopScreen()
end function

function PopScreen(_unused as dynamic)
function PopScreen()
childCount = m.stack.getChildCount()
if childCount > 1
m.stack.removeChildIndex(childCount - 1)
FocusTopScreen(invalid)
FocusTopScreen()
end if
end function

function FocusTopScreen(_unused as dynamic)
function FocusTopScreen()
childCount = m.stack.getChildCount()
topScreen = m.stack.getChild(childCount - 1)
NodeSetFocus(topScreen, true)
Expand Down
12 changes: 12 additions & 0 deletions playlet-lib/src/components/ChannelView/ChannelView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,33 @@ end function

function InitializeTabs()
m.tabs = {
' TODO:P2 remove after fix
' bs:disable-next-line LINT1001
"videos": function(authorId as string, author as string) as object
return CreateChannelFeed("Videos", "channel_videos", authorId, author)
end function
' TODO:P2 remove after fix
' bs:disable-next-line LINT1001
"shorts": function(authorId as string, author as string) as object
return CreateChannelFeed("Shorts", "channel_shorts", authorId, author)
end function
' TODO:P2 remove after fix
' bs:disable-next-line LINT1001
"streams": function(authorId as string, author as string) as object
return CreateChannelFeed("Live", "channel_streams", authorId, author)
end function
' TODO:P2 remove after fix
' bs:disable-next-line LINT1001
"releases": function(authorId as string, author as string) as object
return CreateChannelFeed("Releases", "channel_releases", authorId, author)
end function
' TODO:P2 remove after fix
' bs:disable-next-line LINT1001
"podcasts": function(authorId as string, author as string) as object
return CreateChannelFeed("Podcasts", "channel_podcasts", authorId, author)
end function
' TODO:P2 remove after fix
' bs:disable-next-line LINT1001
"playlists": function(authorId as string, author as string) as object
return CreateChannelFeed("Playlists", "channel_playlists", authorId, author)
end function
Expand Down
2 changes: 1 addition & 1 deletion playlet-lib/src/components/ContextMenu/ContextMenu.bs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function Init()
m.showAnimation = m.top.findNode("showAnimation")
end function

function Show(_unused as dynamic)
function Show()
m.optionsList.ObserveField("itemSelected", FuncName(OnItemSelected))
m.showAnimation.control = "start"
end function
Expand Down
4 changes: 2 additions & 2 deletions playlet-lib/src/components/Logger/Logger.bs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ function Init()
#end if
end function

function StartLogger(logger as object, logLevel = LogLevel.Info as LogLevel) as void
function StartLogger(logger as object, level = LogLevel.Info as LogLevel) as void
if m.global.logger <> invalid
return
end if

logger.logLevel = logLevel
logger.logLevel = level
m.global.addFields({ logger: logger })
logger.control = "run"
end function
Expand Down
6 changes: 3 additions & 3 deletions playlet-lib/src/components/MainScene.transpiled.brs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ end function

function StartWebServer()
m.loungeService = m.top.findNode("LoungeService")
m.loungeService.callfunc("StartService", invalid)
m.loungeService.callfunc("StartService")
m.webServer = m.top.findNode("WebServer")
m.webServer.callfunc("StartServer", invalid)
m.webServer.callfunc("StartServer")
m.dialServer = m.top.findNode("DialServer")
m.dialServer.callfunc("StartServer", invalid)
m.dialServer.callfunc("StartServer")
end function
'//# sourceMappingURL=./MainScene.brs.map
36 changes: 18 additions & 18 deletions playlet-lib/src/components/MainScene.transpiled.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
<component name="MainScene" extends="Group">
<interface>
<field id="bindings" type="assocarray" onChange="OnBindingSetRegisterAutoBind" />
<field id="binding_done" type="boolean" onChange="OnNodeReady" />
<function name="BindNodeFieldsAndProps" />
<function name="BindScopeFields" />
<function name="BindNode" />
</interface>
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/AutoBind.part.brs" />
<script type="text/brightscript" uri="pkg:/components/MainScene_bindings.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/NodePathUtils.brs" />
<script type="text/brightscript" uri="pkg:/components/MainScene.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/LoadingScreen.brs" />
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/OnNodeReadyNoOp.brs" />
<script type="text/brightscript" uri="pkg:/components/EcpArgs.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/Types.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/StringUtils.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/Logging.brs" />
<script type="text/brightscript" uri="pkg:/source/bslib.brs" />
<children>
<Logger id="Logger" />
<AppController id="AppController">
Expand Down Expand Up @@ -51,5 +33,23 @@
<LoungeService id="LoungeService" />
</AppController>
</children>
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/AutoBind.part.brs" />
<interface>
<field id="bindings" type="assocarray" onChange="OnBindingSetRegisterAutoBind" />
<field id="binding_done" type="boolean" onChange="OnNodeReady" />
<function name="BindNodeFieldsAndProps" />
<function name="BindScopeFields" />
<function name="BindNode" />
</interface>
<script type="text/brightscript" uri="pkg:/components/MainScene_bindings.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/NodePathUtils.brs" />
<script type="text/brightscript" uri="pkg:/components/MainScene.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/LoadingScreen.brs" />
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/OnNodeReadyNoOp.brs" />
<script type="text/brightscript" uri="pkg:/components/EcpArgs.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/Types.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/StringUtils.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/Logging.brs" />
<script type="text/brightscript" uri="pkg:/source/bslib.brs" />
</component>
<!--//# sourceMappingURL=./MainScene.xml.map -->
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
' This method is auto-generated!
function InitializeBindings()
m.top.bindings = {
fields: {
Expand Down
7 changes: 6 additions & 1 deletion playlet-lib/src/components/NavBar/NavBar.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/Types.bs"

interface NavBarComponent extends roSGNode
itemContent as roSGNodeNavBarItemContent
end interface

function Init()
m.lastIsInFocusChain = false
m.top.focusable = true
Expand Down Expand Up @@ -30,7 +34,8 @@ function ResizeNavBar() as void
return
end if

component = CreateObject("roSGNode", m.itemsList.itemComponentName)
' bs:disable-next-line LINT1001
component = CreateObject("roSGNode", m.itemsList.itemComponentName) as NavBarComponent
itemSize = m.itemsList.itemSize
minWidth = itemSize[0]
items = content.getChildren(-1, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function OnVisibleChange()
end if
end function

function Refresh(_unused as dynamic)
function Refresh()
m.isDirty = true
OnBookmarksChange()
end function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import "pkg:/source/utils/ErrorUtils.bs"
import "pkg:/source/utils/Locale.bs"
import "pkg:/source/utils/StringUtils.bs"

interface ifTestNode extends roSGNodeContentNode
func as function
state as string
details as string
duration as integer
end interface

@asynctask
function InvidiousInstanceTestingTask(input as object) as object
instance = input.instance
Expand Down Expand Up @@ -37,7 +44,8 @@ function PrepareTests() as object
end function

function CreateTestNode(title as string, func as function) as object
testNode = CreateObject("roSGNode", "ContentNode")
' bs:disable-next-line LINT1001
testNode = CreateObject("roSGNode", "ContentNode") as ifTestNode
testNode.title = title
testNode.AddFields({
func: FuncName(func)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,35 @@ import "pkg:/source/AsyncTask/AsyncTask.bs"
import "pkg:/source/AsyncTask/Tasks.bs"
import "pkg:/source/services/ApplicationInfo.bs"

typecast m as ApplicationInfoRoSGNode

interface ApplicationInfoRoSGNode
top as roSgNodeApplicationInfo
service as ApplicationInfo
latestLibVersionTask as AsyncTask.AsyncTaskComponent
end interface

function Init()
m.service = new ApplicationInfo(m.top)
end function

function GetAppInfo(_unused as dynamic) as object
function GetAppInfo() as roAssociativeArray
return m.service.GetAppInfo()
end function

function GetDeviceInfo(_unused as dynamic) as object
function GetDeviceInfo() as roAssociativeArray
return m.service.GetDeviceInfo()
end function

function GetUserCountryCode(_unused as dynamic) as string
function GetUserCountryCode() as string
return m.service.GetUserCountryCode()
end function

function GetLocalIpAddress(_unused as dynamic) as dynamic
function GetLocalIpAddress() as dynamic
return m.service.GetLocalIpAddress()
end function

function GetLatestPlayletLibVersion(_unused as dynamic) as dynamic
function GetLatestPlayletLibVersion() as dynamic
if not StringUtils.IsNullOrEmpty(m.top.lib_version_latest)
return m.top.lib_version_latest
end if
Expand All @@ -31,6 +39,8 @@ function GetLatestPlayletLibVersion(_unused as dynamic) as dynamic
return invalid
end if

' TODO:P2 remove after fix
' bs:disable-next-line LINT1001
m.latestLibVersionTask = AsyncTask.Start(Tasks.LatestLibVersionTask, {}, function(output as object) as void
m.latestLibVersionTask = invalid
if output.success and output.result.latest <> invalid
Expand Down
4 changes: 4 additions & 0 deletions playlet-lib/src/components/Services/Dash/DashManifest.bs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class DashManifest

public invidiousInstance as dynamic

private utils as Http.Utils
private urlRegex as roRegex
private colorInfo as object

function new(invidiousInstance as string)
m.invidiousInstance = invidiousInstance

Expand Down
4 changes: 2 additions & 2 deletions playlet-lib/src/components/Services/Invidious/Invidious.bs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ function Init()
m.service = new Invidious.InvidiousService(m.top)
end function

function GetCurrentInstance(_unused as dynamic) as string
function GetCurrentInstance() as string
return m.service.GetInstance()
end function

function GetAuthorizeTokenLink(_unused as dynamic) as dynamic
function GetAuthorizeTokenLink() as dynamic
return m.service.GetAuthorizeTokenLink()
end function

Expand Down
15 changes: 11 additions & 4 deletions playlet-lib/src/components/Services/Invidious/InvidiousService.bs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ namespace Invidious
const ERROR_NOT_AUTHENTICATED = "Not authenticated"

class InvidiousService
public invidiousNode as object
public invidiousNode as roSGNodeInvidious

function new(invidiousNode as object)
private _userCountryCode as dynamic
private preferences as roSGNodePreferences
private endpoints as object

function new(invidiousNode as roSGNodeInvidious)
m.invidiousNode = invidiousNode
end function

Expand All @@ -64,7 +68,8 @@ namespace Invidious

function GetInstance() as string
if m.preferences = invalid
m.preferences = m.invidiousNode.preferences
' bs:disable-next-line LINT1001
m.preferences = m.invidiousNode.preferences as roSGNodePreferences
end if
instance = m.preferences["invidious.instance"]
if not StringUtils.IsNullOrEmpty(instance)
Expand Down Expand Up @@ -136,6 +141,7 @@ namespace Invidious

if tryCount > 1
request.TryCount(tryCount)
' bs:disable-next-line LINT1001
request.RetryCallback(function(context as object) as boolean
response = context.response
' In some cases, video info requests return "HTTP/0.9 when not allowed" errors.
Expand Down Expand Up @@ -314,7 +320,8 @@ namespace Invidious
response = request.Await()

responseHandler = invalid
if IsString(endpoint.responseHandler) and m.DoesExist(endpoint.responseHandler)
' bs:disable-next-line LINT1001
if IsString(endpoint.responseHandler) and (m as ifAssociativeArray).DoesExist(endpoint.responseHandler)
responseHandler = endpoint.responseHandler
else
responseHandler = "DefaultHandler"
Expand Down
Loading
Loading