Fresh start (#110)
* Fresh start * Create an xml include plugin (#111) * Restructure and add testing (#114) * rooibos setup * Restructure and add testing * docs * Restore manifestpipi * Description in tools * A bit of docs * Auto bind feature (#115) * Auto bind feature * Fix children merge * bs plugin fix * Feature/app controller (#120) * Initial layout * Restructuring and plugin work * A couple of tweaks in binding stuff * tweaks * basic stack * Add basic app controller * Support json5/yaml in playlet config files (#123) * Support json5 in playlet config files * Add yaml to the mix * Delete old lib project * plugin fix * plugin tweak * verbose logging * Revert "verbose logging" This reverts commit 25867f4226703d83102519a0d48d1cc46a9876de. * One idea to fix the include plugin * Fix instability in plugins * Feature/navbar (#126) * Navbar * typo * comment * Single content node, and tests * Remove unused field * tweaks * update dependencies command * tweak formatting * Add web app screen * Set id in created screens * Search screen * Tests * Show playlists and channels in search results * Move screen stuff to app controller * Home screen (wip) * Add preferences node * README.md copyedits (#130) * README.md: Fix typos * README.md: Standardize capitalization and punctuation * Update docs/README.md --------- Co-authored-by: Brahim Hadriche <brahim.hadriche@gmail.com> * Web server: round 1 (#131) * web server object * Logging * Web server round 1 * Lint fix * Small tweaks --------- Co-authored-by: github-action linter <githubaction@githubaction.com> * Logging to file * Leftover * Add logs file to web server * Fix for timeout * Disable keepalive connection * add openapi spec file * Lint fix * add prefs version in api * Add ecp api definition * Lint fix * Settings rework (#135) * Settings rework * Standard OnFocusChange event * Video player stuff (#136) * Video player stuff * Restructure things so that focus is better handled * Lint fix --------- Co-authored-by: github-action linter <githubaction@githubaction.com> * Exit dialog * A bunch of changes * New http client * Set TODO priorities * picture in picture * mark video watched * Video player stuff mostly there * update spec file * Sponsorblock * FuncName * SponsorBlock notifications * Lint fix * misc * remove basic auth feature flag (until we start using it) * Play queue part 1 * type fix * handle unicode in request body * SponsorBlock chapter label * modal base * remove a hack * Invidious settings * web server reduce timeout * Test for captions * Lint fix * remove rpc stuff * small change * Solve focus management * a couple of fixes * Remove a bunch of todos * feed error handling wip * Lint fix * navigation in instance settings * home screen pagination support * Refactor feed to support pagination on search page * cell loading animation * Tweak caching * delete test screen * playlist support part 1 * Basic playlist view * Restore playlist/channel handler * Refactor some content node stuff, and add an auth popup dialog * A bad implementation of a playqueue * Lint fix * playlist cast fix * Feature/web app catch up (#139) * playlist cast fix * Move things around * support playlists in web app * update api * Bump deps * Downgrade todo --------- Co-authored-by: Bryce Harrington <bryce@bryceharrington.org> Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
349 files changed
+12784
-7660
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
|
||||
function Init()
|
||||
m.displayNames = {
|
||||
"version": "Playlet Version",
|
||||
"lib_version": "Playlet Library Version",
|
||||
"lib_version_latest": "Playlet Library Latest Version",
|
||||
"lib_url": "Playlet Library URL",
|
||||
"lib_url_type": "Playlet Library URL Type",
|
||||
"git_commit_hash": "Playlet Git Commit Hash",
|
||||
"lib_git_commit_hash": "Playlet Library Git Commit Hash",
|
||||
"id": "App ID"
|
||||
}
|
||||
|
||||
m.keyValueList = m.top.findNode("KeyValueListContent")
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
m.appInfo = m.applicationInfo@.GetAppInfo(invalid)
|
||||
|
||||
UpdateKeyValueList()
|
||||
|
||||
if m.appInfo.lib_version_latest = "N/A"
|
||||
m.applicationInfo.ObserveFieldScoped("lib_version_latest", FuncName(OnAppInfoChanged))
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnAppInfoChanged()
|
||||
m.appInfo["lib_version_latest"] = m.applicationInfo.lib_version_latest
|
||||
UpdateKeyValueList()
|
||||
end function
|
||||
|
||||
function UpdateKeyValueList()
|
||||
while m.keyValueList.getChildCount() > 0
|
||||
m.keyValueList.removeChildIndex(0)
|
||||
end while
|
||||
|
||||
for each item in m.appInfo
|
||||
value = `${m.displayNames[item]}: ${m.appInfo[item]}`
|
||||
contentNode = m.keyValueList.createChild("ContentNode")
|
||||
contentNode.title = value
|
||||
end for
|
||||
end function
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="AppInfoScreen" extends="Group" includes="AutoBind">
|
||||
<interface>
|
||||
<field id="applicationInfo" type="node" bind="/ApplicationInfo" />
|
||||
</interface>
|
||||
<children>
|
||||
<LabelList
|
||||
translation="[170,92]"
|
||||
itemSize="[1020,48]"
|
||||
font="font:SmallestBoldSystemFont"
|
||||
drawFocusFeedback="false">
|
||||
<ContentNode id="KeyValueListContent" role="content">
|
||||
</ContentNode>
|
||||
</LabelList>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,29 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
|
||||
function Init()
|
||||
m.rowList = m.top.FindNode("rowList")
|
||||
m.pendingLoadTasks = {}
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
SetNavigation(invalid, "back", m.navBar)
|
||||
SetNavigation(invalid, "left", m.navBar)
|
||||
|
||||
m.rowList@.BindNode(invalid)
|
||||
m.rowList.contentData = ParseJson(ReadAsciiFile(m.top.feedFile))
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
NodeSetFocus(m.rowList, true)
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
if NavigationKeyHandler(key, press).handled
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="HomeScreen" extends="Group" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="navBar" type="node" bind="/NavBar" />
|
||||
<field id="invidious" type="node" bind="/Invidious" />
|
||||
<field id="feedFile" type="string" value="libpkg:/config/default_home_layout.json5" />
|
||||
</interface>
|
||||
<children>
|
||||
<VideoRowList
|
||||
itemComponentName="RowCell"
|
||||
id="rowList"
|
||||
translation="[0,50]"
|
||||
numRows="2"
|
||||
rowitemSize="[[350,196]]"
|
||||
rowItemSpacing="[[25,0]]"
|
||||
itemSize="[1280,326]"
|
||||
itemSpacing="[0,65]"
|
||||
rowLabelOffset="[[115,20]]"
|
||||
focusXOffset="[115]"
|
||||
showRowLabel="[true]"
|
||||
rowFocusAnimationStyle="floatingfocus"
|
||||
focusBitmapUri="pkg:/images/focus_grid.9.png"
|
||||
/>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,232 @@
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/components/Screens/SearchScreen/SearchSuggestionsTask.bs"
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/source/services/SearchHistory.bs"
|
||||
import "pkg:/source/utils/LoadingScreen.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.container = m.top.FindNode("container")
|
||||
m.keyboard = m.top.FindNode("keyboard")
|
||||
m.rowList = m.top.FindNode("rowList")
|
||||
m.scrollAnimation = m.top.FindNode("scrollAnimation")
|
||||
m.scrollAnimationInterpolator = m.top.FindNode("scrollAnimationInterpolator")
|
||||
m.suggestions = m.top.FindNode("suggestions")
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
m.log = new log.Logger("SearchScreen")
|
||||
|
||||
m.rowlist@.BindNode(invalid)
|
||||
m.keyboard.ObserveField("text", FuncName(OnTextChange))
|
||||
m.suggestions.ObserveField("buttonFocused", FuncName(OnSearchButtonFocused))
|
||||
m.suggestions.ObserveField("buttonSelected", FuncName(OnSearchButtonSelected))
|
||||
m.top.ObserveField("visible", FuncName(OnVisibilityChange))
|
||||
m.rowlist.ObserveFieldScoped("onError", FuncName(OnSearchError))
|
||||
|
||||
SetNavigation(invalid, "back", m.navBar, function()
|
||||
ScrollUp()
|
||||
end function)
|
||||
SetNavigation(m.suggestions, "right", m.keyboard)
|
||||
SetNavigation(m.keyboard, "left", m.suggestions)
|
||||
SetNavigation(m.suggestions, "left", m.navBar)
|
||||
SetNavigation(m.keyboard, "left", m.navBar)
|
||||
SetNavigation(m.rowList, "left", m.navBar, function()
|
||||
ScrollUp()
|
||||
end function)
|
||||
SetNavigation(invalid, "down", m.rowList, function()
|
||||
ScrollDown()
|
||||
end function)
|
||||
SetNavigation(m.rowList, "up", m.suggestions, function()
|
||||
ScrollUp()
|
||||
end function)
|
||||
|
||||
m.currentNavigtionNode = m.suggestions
|
||||
' Trigger suggestions
|
||||
OnTextChange()
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
if m.currentNavigtionNode.isSameNode(m.suggestions) and not m.suggestions.focusable
|
||||
m.currentNavigtionNode = m.keyboard
|
||||
end if
|
||||
NodeSetFocus(m.currentNavigtionNode, true)
|
||||
if m.currentNavigtionNode.isSameNode(m.suggestions)
|
||||
OnSearchButtonFocused()
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnTextChange() as void
|
||||
if m.suggestions.isInFocusChain()
|
||||
return
|
||||
end if
|
||||
|
||||
if m.searchSuggestionsTask <> invalid
|
||||
m.searchSuggestionsTask.cancel = true
|
||||
end if
|
||||
|
||||
m.searchSuggestionsTask = StartAsyncTask(SearchSuggestionsTask, {
|
||||
q: m.keyboard.text,
|
||||
invidious: m.invidious
|
||||
}, OnSearchSuggestionsTaskResults)
|
||||
end function
|
||||
|
||||
function OnSearchSuggestionsTaskResults(output as object) as void
|
||||
if m.searchSuggestionsTask <> invalid and m.searchSuggestionsTask.id = output.task.id
|
||||
m.searchSuggestionsTask = invalid
|
||||
end if
|
||||
|
||||
if output.cancelled
|
||||
return
|
||||
end if
|
||||
|
||||
if not output.success
|
||||
m.log.error(ErrorUtils.Format(output.error))
|
||||
return
|
||||
end if
|
||||
' In case this is an old request, discard suggestions
|
||||
q = output.result.q
|
||||
if q <> m.keyboard.text
|
||||
return
|
||||
end if
|
||||
suggestions = output.result.response
|
||||
if suggestions = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
if q.len() > 0 and ArrayUtils.IndexOfString(suggestions, q) = -1
|
||||
suggestions.Unshift(q)
|
||||
end if
|
||||
|
||||
' Capture current focused button and restore it after resetting the buttons
|
||||
buttonFocused = -1
|
||||
if m.suggestions.isInFocusChain()
|
||||
buttonFocused = m.suggestions.buttonFocused
|
||||
end if
|
||||
if buttonFocused >= m.suggestions.buttons.Count()
|
||||
buttonFocused = m.suggestions.buttons.Count() - 1
|
||||
end if
|
||||
m.suggestions.buttons = suggestions
|
||||
if buttonFocused <> -1
|
||||
m.suggestions.focusButton = buttonFocused
|
||||
end if
|
||||
m.suggestions.focusable = m.suggestions.buttons.Count() > 0
|
||||
end function
|
||||
|
||||
function OnSearchButtonSelected()
|
||||
selected = m.suggestions.buttonSelected
|
||||
text = m.suggestions.buttons[selected]
|
||||
SearchHistory.Save(text)
|
||||
Search(text)
|
||||
end function
|
||||
|
||||
function OnSearchButtonFocused() as void
|
||||
if not m.suggestions.isInFocusChain()
|
||||
return
|
||||
end if
|
||||
|
||||
buttonCount = m.suggestions.buttons.Count()
|
||||
selected = m.suggestions.buttonFocused
|
||||
if selected >= buttonCount
|
||||
m.suggestions.focusButton = 0
|
||||
end if
|
||||
|
||||
selected = m.suggestions.buttonFocused
|
||||
if selected >= m.suggestions.buttons.Count() or selected < 0
|
||||
return
|
||||
end if
|
||||
text = m.suggestions.buttons[selected]
|
||||
m.keyboard.text = text
|
||||
end function
|
||||
|
||||
function Search(text as string)
|
||||
m.rowlist.UnobserveFieldScoped("someContentReady")
|
||||
m.rowlist.ObserveFieldScoped("someContentReady", FuncName(OnSearchContentReady))
|
||||
ShowLoadingScreen()
|
||||
|
||||
m.rowList.contentData = [{
|
||||
title: `Search - ${text}`,
|
||||
apiType: "Invidious",
|
||||
endpoint: "search",
|
||||
queryParams: {
|
||||
q: text
|
||||
}
|
||||
}]
|
||||
end function
|
||||
|
||||
function OnSearchContentReady() as void
|
||||
if not m.rowlist.someContentReady
|
||||
return
|
||||
end if
|
||||
m.rowlist.UnobserveFieldScoped("someContentReady")
|
||||
m.rowlist.focusable = true
|
||||
m.currentNavigtionNode = m.rowList
|
||||
NodeSetFocus(m.rowlist, true)
|
||||
' There's a bug with the floating focus indicator. If the rowList receives focus after the
|
||||
' content is set, the focus indicator will be "off". This is why we set the content again.
|
||||
m.rowlist.content = m.rowlist.content
|
||||
ScrollDown()
|
||||
HideLoadingScreen()
|
||||
end function
|
||||
|
||||
function OnSearchError()
|
||||
m.rowlist.contentData = invalid
|
||||
m.rowlist.focusable = false
|
||||
HideLoadingScreen()
|
||||
end function
|
||||
|
||||
function OnVisibilityChange()
|
||||
if m.top.visible = false
|
||||
ClearSearch()
|
||||
else
|
||||
OnTextChange()
|
||||
end if
|
||||
end function
|
||||
|
||||
function ClearSearch()
|
||||
m.keyboard.text = ""
|
||||
m.rowlist.contentData = invalid
|
||||
m.rowlist.focusable = false
|
||||
ScrollUp()
|
||||
end function
|
||||
|
||||
function ScrollUp() as void
|
||||
destination = m.scrollAnimationInterpolator.keyValue[0][1]
|
||||
current = m.container.translation[1]
|
||||
if current = destination
|
||||
return
|
||||
end if
|
||||
m.scrollAnimationInterpolator.reverse = true
|
||||
m.scrollAnimation.control = "start"
|
||||
end function
|
||||
|
||||
function ScrollDown() as void
|
||||
destination = m.scrollAnimationInterpolator.keyValue[2][1]
|
||||
current = m.container.translation[1]
|
||||
if current = destination
|
||||
return
|
||||
end if
|
||||
m.scrollAnimationInterpolator.reverse = false
|
||||
m.scrollAnimation.control = "start"
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
navigation = NavigationKeyHandler(key, press)
|
||||
if navigation.handled
|
||||
m.currentNavigtionNode = navigation.node
|
||||
if m.currentNavigtionNode.isSameNode(m.navBar)
|
||||
m.currentNavigtionNode = m.suggestions
|
||||
end if
|
||||
if m.currentNavigtionNode.isSameNode(m.suggestions)
|
||||
OnSearchButtonFocused()
|
||||
end if
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="SearchScreen" extends="Group" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="navBar" type="node" bind="/NavBar" />
|
||||
<field id="invidious" type="node" bind="/Invidious" />
|
||||
</interface>
|
||||
<children>
|
||||
<Group id="container">
|
||||
<MiniKeyboard
|
||||
id="keyboard"
|
||||
translation="[730,110]"
|
||||
/>
|
||||
<ButtonGroup
|
||||
id="suggestions"
|
||||
focusable="false"
|
||||
minWidth="400"
|
||||
maxWidth="480"
|
||||
buttonHeight="50"
|
||||
translation="[160,100]"
|
||||
/>
|
||||
<VideoRowList
|
||||
itemComponentName="RowCell"
|
||||
id="rowList"
|
||||
focusable="false"
|
||||
translation="[0,620]"
|
||||
numRows="1"
|
||||
rowitemSize="[[350,196]]"
|
||||
rowItemSpacing="[[25,0]]"
|
||||
itemSize="[1280,326]"
|
||||
itemSpacing="[0,65]"
|
||||
rowLabelOffset="[[115,20]]"
|
||||
focusXOffset="[115]"
|
||||
showRowLabel="[true]"
|
||||
rowFocusAnimationStyle="floatingfocus"
|
||||
variableWidthItems="true"
|
||||
focusBitmapUri="pkg:/images/focus_grid.9.png"
|
||||
/>
|
||||
<Animation
|
||||
id="scrollAnimation"
|
||||
duration="0.3">
|
||||
<Vector2DFieldInterpolator
|
||||
id="scrollAnimationInterpolator"
|
||||
key="[ 0.0, 0.5, 1.0 ]"
|
||||
keyValue="[ [0.0,0.0], [0.0,-160.0], [0.0,-320.0]]"
|
||||
fieldToInterp="container.translation" />
|
||||
</Animation>
|
||||
</Group>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,41 @@
|
||||
import "pkg:/source/services/SearchHistory.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
|
||||
@asynctask
|
||||
function SearchSuggestionsTask(input as object) as object
|
||||
q = input.q
|
||||
invidiousNode = input.invidious
|
||||
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
searchSuggestsions = StringUtils.IsNullOrEmpty(q) ? invalid : service.SearchSuggestions(q, m.top.cancellation)
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
history = SearchHistory.GetSaved(q)
|
||||
|
||||
if searchSuggestsions <> invalid
|
||||
history = MergeSearchSuggestions(history, searchSuggestsions.suggestions)
|
||||
end if
|
||||
|
||||
return {
|
||||
q: q,
|
||||
response: history
|
||||
}
|
||||
end function
|
||||
|
||||
function MergeSearchSuggestions(history as object, queryResults as object, maxItems = 10 as integer) as object
|
||||
if queryResults = invalid
|
||||
return history
|
||||
end if
|
||||
while history.Count() < maxItems and queryResults.Count() > 0
|
||||
history.push(queryResults.shift())
|
||||
end while
|
||||
return history
|
||||
end function
|
||||
@@ -0,0 +1,42 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.top.focusable = true
|
||||
m.checkbox = m.top.findNode("Checkbox")
|
||||
m.top.itemSpacings = [10]
|
||||
end function
|
||||
|
||||
function BindPreference(preferences as object, key as string)
|
||||
if m.preferences <> invalid and m.key <> invalid
|
||||
m.preferences.unobserveFieldScoped(m.key)
|
||||
end if
|
||||
|
||||
m.preferences = preferences
|
||||
m.key = key
|
||||
|
||||
if preferences <> invalid and key <> invalid
|
||||
preferences.observeFieldScoped(key, FuncName(OnPreferenceChange))
|
||||
OnPreferenceChange()
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnPreferenceChange()
|
||||
m.top.value = m.preferences[m.key]
|
||||
end function
|
||||
|
||||
function OnValueChange() as void
|
||||
if m.preferences = invalid or m.key = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.preferences[m.key] = m.top.value
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.checkbox, true)
|
||||
end function
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="BooleanControl" extends="LayoutGroup" includes="Focus">
|
||||
<interface>
|
||||
<field id="displayText" type="string" alias="Checkbox.title" />
|
||||
<field id="description" type="string" alias="Description.text" />
|
||||
<field id="value" type="boolean" alias="Checkbox.value" onChange="OnValueChange" />
|
||||
<function name="BindPreference" />
|
||||
</interface>
|
||||
<children>
|
||||
<Checkbox id="Checkbox" wrapDividerHeight="0" wrapDividerBitmapUri="" />
|
||||
<Label id="Description"
|
||||
width="450"
|
||||
color="0xb4b4b4ff"
|
||||
wrap="true">
|
||||
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||
</Label>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,17 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.top.observeField("checkedState", FuncName(OnCheckedStateChange))
|
||||
end function
|
||||
|
||||
function OnValueChange()
|
||||
m.top.checkedState = [m.top.value]
|
||||
end function
|
||||
|
||||
function OnCheckedStateChange() as void
|
||||
checkedState = m.top.checkedState
|
||||
if checkedState = invalid or checkedState.Count() = 0
|
||||
return
|
||||
end if
|
||||
m.top.value = checkedState[0]
|
||||
end function
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="Checkbox" extends="CheckList">
|
||||
<interface>
|
||||
<field id="title" type="string" alias="checkboxNode.title" />
|
||||
<field id="value" type="boolean" onChange="OnValueChange" />
|
||||
</interface>
|
||||
<children>
|
||||
<ContentNode role="content">
|
||||
<ContentNode id="checkboxNode" title="" />
|
||||
</ContentNode>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,26 @@
|
||||
import "pkg:/source/services/SearchHistory.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.top.focusable = true
|
||||
m.top.itemSpacings = [8]
|
||||
m.button = m.top.findNode("Button")
|
||||
m.button.observeField("buttonSelected", FuncName(OnButtonSelected))
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
NodeSetFocus(m.button, true)
|
||||
end function
|
||||
|
||||
function BindPreference(preferences as object, key as string)
|
||||
' Do nothing
|
||||
end function
|
||||
|
||||
function OnButtonSelected()
|
||||
SearchHistory.Clear()
|
||||
DialogUtils.ShowDialog("Search history cleared.", "Success")
|
||||
end function
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="ClearSearchHistoryControl" extends="LayoutGroup" includes="Focus">
|
||||
<interface>
|
||||
<field id="displayText" type="string" alias="Button.text" />
|
||||
<field id="description" type="string" alias="DescriptionLabel.text" />
|
||||
<function name="BindPreference" />
|
||||
</interface>
|
||||
<children>
|
||||
<Button
|
||||
id="Button"
|
||||
showFocusFootprint="true" />
|
||||
<Label id="DescriptionLabel"
|
||||
width="450"
|
||||
color="0xb4b4b4ff"
|
||||
wrap="true">
|
||||
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||
</Label>
|
||||
</children>
|
||||
</component>
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
|
||||
function Init()
|
||||
m.top.focusable = true
|
||||
m.top.itemSpacings = [8]
|
||||
|
||||
m.button = m.top.findNode("button")
|
||||
AdjustButtonLabel(m.button)
|
||||
|
||||
m.button.observeField("buttonSelected", FuncName(OpenInvidiousInstanceSettings))
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.button, true)
|
||||
end function
|
||||
|
||||
function AdjustButtonLabel(button as object) as void
|
||||
children = button.getChildren(-1, 0)
|
||||
for each child in children
|
||||
if child.isSubtype("Label") and child.hasField("horizAlign")
|
||||
child.observeField("horizAlign", FuncName(OnButtonLabelHorizAlignChanged))
|
||||
child.horizAlign = "left"
|
||||
return
|
||||
end if
|
||||
end for
|
||||
end function
|
||||
|
||||
function OnButtonLabelHorizAlignChanged(event as object)
|
||||
label = event.getRoSGNode()
|
||||
if label.horizAlign <> "left"
|
||||
label.horizAlign = "left"
|
||||
end if
|
||||
end function
|
||||
|
||||
function BindPreference(preferences as object, key as string)
|
||||
if m.preferences <> invalid and m.key <> invalid
|
||||
m.preferences.unobserveFieldScoped(m.key)
|
||||
end if
|
||||
|
||||
m.preferences = preferences
|
||||
m.key = key
|
||||
|
||||
if preferences <> invalid and key <> invalid
|
||||
preferences.observeFieldScoped(key, FuncName(OnPreferenceChange))
|
||||
OnPreferenceChange()
|
||||
end if
|
||||
end function
|
||||
|
||||
function OpenInvidiousInstanceSettings()
|
||||
settings = CreateObject("roSGNode", "InvidiousInstanceSettings")
|
||||
m.appController@.PushScreen(settings)
|
||||
settings@.BindNode(invalid)
|
||||
settings.text = m.top.value
|
||||
settings.observeField("save", FuncName(OnSaveInvidiousInstance))
|
||||
end function
|
||||
|
||||
function OnSaveInvidiousInstance(event as object)
|
||||
settings = event.GetRoSGNode()
|
||||
m.top.value = settings.text
|
||||
end function
|
||||
|
||||
function OnPreferenceChange()
|
||||
m.top.value = m.preferences[m.key]
|
||||
end function
|
||||
|
||||
function OnValueChange() as void
|
||||
if m.preferences = invalid or m.key = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.preferences[m.key] = m.top.value
|
||||
end function
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousInstanceControl" extends="LayoutGroup" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="displayText" type="string" alias="DisplayTextLabel.text" />
|
||||
<field id="description" type="string" alias="DescriptionLabel.text" />
|
||||
<field id="value" type="string" alias="Button.text" onChange="OnValueChange" />
|
||||
<field id="appController" type="node" bind="/AppController" />
|
||||
<function name="BindPreference" />
|
||||
</interface>
|
||||
<children>
|
||||
<Label id="DisplayTextLabel" width="450" />
|
||||
<Label id="DescriptionLabel"
|
||||
width="450"
|
||||
color="0xb4b4b4ff"
|
||||
wrap="true">
|
||||
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||
</Label>
|
||||
<Button id="Button"
|
||||
iconUri=""
|
||||
focusedIconUri=""
|
||||
showFocusFootprint="true"
|
||||
minWidth="420" />
|
||||
</children>
|
||||
</component>
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.textEditBox = m.top.findNode("textEditBox")
|
||||
m.editButton = m.top.findNode("editButton")
|
||||
m.testButton = m.top.findNode("testButton")
|
||||
m.saveButton = m.top.findNode("saveButton")
|
||||
|
||||
m.publicInstances = m.top.findNode("instances")
|
||||
|
||||
m.editButton.observeField("buttonSelected", FuncName(OnEditButtonSelected))
|
||||
m.saveButton.observeField("buttonSelected", FuncName(OnSaveButtonSelected))
|
||||
m.testButton.observeField("buttonSelected", FuncName(OnTestButtonSelected))
|
||||
m.publicInstances.observeField("instance", FuncName(OnPublicInstanceSelected))
|
||||
|
||||
SetNavigation(m.editButton, "down", m.publicInstances)
|
||||
SetNavigation(m.editButton, "down", m.testButton)
|
||||
SetNavigation(m.publicInstances, "up", m.editButton)
|
||||
|
||||
SetNavigation(m.publicInstances, "down", m.testButton)
|
||||
|
||||
SetNavigation(m.testButton, "up", m.publicInstances)
|
||||
SetNavigation(m.testButton, "up", m.editButton)
|
||||
SetNavigation(m.saveButton, "up", m.publicInstances)
|
||||
SetNavigation(m.saveButton, "up", m.editButton)
|
||||
|
||||
SetNavigation(m.saveButton, "left", m.testButton)
|
||||
SetNavigation(m.testButton, "right", m.saveButton)
|
||||
|
||||
m.currentNavigtionNode = m.editButton
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.currentNavigtionNode, true)
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
navigation = NavigationKeyHandler(key, press)
|
||||
if navigation.handled
|
||||
m.currentNavigtionNode = navigation.node
|
||||
return true
|
||||
end if
|
||||
|
||||
if key = "options" and press
|
||||
' A pass-through to the app controller, so it can toggle picture-in-picture
|
||||
return false
|
||||
end if
|
||||
|
||||
if key = "back" and press
|
||||
Close()
|
||||
return true
|
||||
end if
|
||||
|
||||
return true
|
||||
end function
|
||||
|
||||
function OnPublicInstanceSelected()
|
||||
m.top.text = m.publicInstances.instance
|
||||
m.currentNavigtionNode = m.testButton
|
||||
NodeSetFocus(m.testButton, true)
|
||||
end function
|
||||
|
||||
function OnTestButtonSelected()
|
||||
testing = CreateObject("roSGNode", "InvidiousInstanceTesting")
|
||||
m.appController@.PushScreen(testing)
|
||||
testing@.BindNode(invalid)
|
||||
testing.instance = m.top.text
|
||||
testing.run = true
|
||||
end function
|
||||
|
||||
function OnEditButtonSelected()
|
||||
keyboardDialog = createObject("roSGNode", "StandardKeyboardDialog")
|
||||
keyboardDialog.title = "Edit Instance"
|
||||
keyboardDialog.message = ["Enter the instance url (e.g. https://vid.puffyan.us)"]
|
||||
keyboardDialog.text = m.top.text
|
||||
keyboardDialog.buttons = ["OK", "Cancel"]
|
||||
keyboardDialog.observeField("buttonSelected", FuncName(OnKeyboardButton))
|
||||
|
||||
m.top.getScene().dialog = keyboardDialog
|
||||
end function
|
||||
|
||||
function OnKeyboardButton(event as object)
|
||||
keyboard = event.getRoSGNode()
|
||||
buttonSelected = keyboard.buttonSelected
|
||||
if buttonSelected = 0
|
||||
m.top.text = keyboard.text
|
||||
m.currentNavigtionNode = m.testButton
|
||||
NodeSetFocus(m.testButton, true)
|
||||
end if
|
||||
keyboard.close = true
|
||||
end function
|
||||
|
||||
function OnSaveButtonSelected()
|
||||
m.top.save = true
|
||||
Close()
|
||||
end function
|
||||
|
||||
function Close()
|
||||
m.appController@.PopScreen(invalid)
|
||||
end function
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousInstanceSettings" extends="Group" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="text" type="string" alias="textEditBox.text" />
|
||||
<field id="save" type="boolean" alwaysNotify="true" />
|
||||
<field id="appController" type="node" bind="/AppController" />
|
||||
</interface>
|
||||
<children>
|
||||
<Rectangle
|
||||
width="1280"
|
||||
height="720"
|
||||
color="#000000"
|
||||
opacity="0.5">
|
||||
</Rectangle>
|
||||
<Rectangle
|
||||
width="960"
|
||||
height="600"
|
||||
translation="[160,60]"
|
||||
color="#242424">
|
||||
<Label
|
||||
text="Invidious custom instance"
|
||||
translation="[326,13]" />
|
||||
<TextEditBox
|
||||
id="textEditBox"
|
||||
hintText="e.g. https://https://vid.puffyan.us"
|
||||
width="480"
|
||||
height="50"
|
||||
translation="[200,50]" />
|
||||
<Button
|
||||
id="editButton"
|
||||
text=""
|
||||
minWidth="64"
|
||||
maxWidth="80"
|
||||
height="48"
|
||||
iconUri="pkg:/images/icons/edit-48-white.png"
|
||||
focusedIconUri="pkg:/images/icons/edit-48-black.png"
|
||||
showFocusFootprint="true"
|
||||
translation="[692,50]" />
|
||||
<Label
|
||||
text="OR"
|
||||
translation="[460,110]">
|
||||
<Rectangle
|
||||
width="250"
|
||||
height="1"
|
||||
translation="[-282,10]" />
|
||||
|
||||
<Rectangle
|
||||
width="250"
|
||||
height="1"
|
||||
translation="[71,10]" />
|
||||
|
||||
</Label>
|
||||
|
||||
<Label
|
||||
text="Invidious public instances"
|
||||
translation="[328,145]" />
|
||||
|
||||
<InvidiousPublicInstances
|
||||
id="instances"
|
||||
translation="[50,190]">
|
||||
|
||||
</InvidiousPublicInstances>
|
||||
|
||||
<Button
|
||||
id="testButton"
|
||||
text="Test instance"
|
||||
showFocusFootprint="true"
|
||||
translation="[495,507]" />
|
||||
<Button
|
||||
id="saveButton"
|
||||
text="Save"
|
||||
showFocusFootprint="true"
|
||||
minWidth="150"
|
||||
translation="[768,507]" />
|
||||
</Rectangle>
|
||||
</children>
|
||||
</component>
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/Screens/SettingsScreen/InvidiousInstance/InvidiousInstanceTesting/InvidiousInstanceTestingTask.bs"
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.titleLabel = m.top.findNode("titleLabel")
|
||||
m.closeButton = m.top.findNode("closeButton")
|
||||
m.testList = m.top.findNode("testList")
|
||||
m.closeButton.observeField("buttonSelected", FuncName(Close))
|
||||
m.testList.observeField("itemSelected", FuncName(ShowTestDetails))
|
||||
|
||||
SetNavigation(m.closeButton, "up", m.testList)
|
||||
SetNavigation(m.testList, "down", m.closeButton)
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.closeButton, true)
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
if NavigationKeyHandler(key, press).handled
|
||||
return true
|
||||
end if
|
||||
|
||||
if key = "options" and press
|
||||
' A pass-through to the app controller, so it can toggle picture-in-picture
|
||||
return false
|
||||
end if
|
||||
|
||||
if key = "back" and press
|
||||
Close()
|
||||
return true
|
||||
end if
|
||||
|
||||
return true
|
||||
end function
|
||||
|
||||
function Close()
|
||||
if m.testingTask <> invalid
|
||||
m.testingTask.cancel = true
|
||||
end if
|
||||
|
||||
m.appController@.PopScreen(invalid)
|
||||
end function
|
||||
|
||||
function RunTestsTask()
|
||||
m.titleLabel.text = `Testing ${m.top.instance}`
|
||||
|
||||
if m.testingTask <> invalid
|
||||
m.testingTask.cancel = true
|
||||
end if
|
||||
|
||||
m.testingTask = StartAsyncTask(InvidiousInstanceTestingTask, {
|
||||
instance: m.top.instance,
|
||||
listNode: m.testList
|
||||
})
|
||||
end function
|
||||
|
||||
function ShowTestDetails(event as object) as void
|
||||
selected = m.testList.itemSelected
|
||||
itemContent = m.testList.content.GetChild(selected)
|
||||
if StringUtils.IsNullOrEmpty(itemContent.details)
|
||||
return
|
||||
end if
|
||||
|
||||
message = `Status: ${itemContent.state}\nTest duration: ${itemContent.duration}ms\nDetails: ${itemContent.details}`
|
||||
DialogUtils.ShowDialog(message, `Test: ${itemContent.title}`)
|
||||
end function
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousInstanceTesting" extends="Group" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="instance" type="string" />
|
||||
<field id="run" type="boolean" alwaysNotify="true" onChange="RunTestsTask" />
|
||||
<field id="appController" type="node" bind="/AppController" />
|
||||
</interface>
|
||||
<children>
|
||||
<Rectangle
|
||||
width="1280"
|
||||
height="720"
|
||||
color="#000000"
|
||||
opacity="0.5">
|
||||
</Rectangle>
|
||||
<Rectangle
|
||||
width="960"
|
||||
height="600"
|
||||
translation="[160,60]"
|
||||
color="#242424">
|
||||
<Label
|
||||
id="titleLabel"
|
||||
width="960"
|
||||
horizAlign="center"
|
||||
text=""
|
||||
translation="[0,20]" />
|
||||
|
||||
<MarkupGrid
|
||||
id="testList"
|
||||
itemSize="[860,40]"
|
||||
itemSpacing="[0,20]"
|
||||
numColumns="1"
|
||||
numRows="7"
|
||||
vertFocusAnimationStyle="floatingFocus"
|
||||
translation="[50,80]"
|
||||
itemComponentName="InvidiousInstanceTestingItem" />
|
||||
<Button
|
||||
id="closeButton"
|
||||
text="Close"
|
||||
minWidth="0"
|
||||
showFocusFootprint="true"
|
||||
translation="[404,506]" />
|
||||
</Rectangle>
|
||||
</children>
|
||||
</component>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.busySpinner = m.top.findNode("busySpinner")
|
||||
m.busyspinner.poster.width = 40
|
||||
m.busyspinner.poster.height = 40
|
||||
|
||||
m.nameLabel = m.top.findNode("nameLabel")
|
||||
m.detailsLabel = m.top.findNode("detailsLabel")
|
||||
end function
|
||||
|
||||
function OnContentSet() as void
|
||||
content = m.top.itemContent
|
||||
|
||||
m.nameLabel.text = content.title
|
||||
m.top.state = content.state
|
||||
end function
|
||||
|
||||
function OnStateChange()
|
||||
if m.top.state = "loading"
|
||||
m.busySpinner.poster.uri = "pkg:/images/spinner.png"
|
||||
m.busySpinner.control = "start"
|
||||
else if m.top.state = "failed"
|
||||
m.busySpinner.poster.uri = "pkg:/images/icons/test-failed.png"
|
||||
m.busySpinner.control = "stop"
|
||||
m.busySpinner.poster.rotation = 0
|
||||
else if m.top.state = "passed"
|
||||
m.busySpinner.poster.uri = "pkg:/images/icons/test-passed.png"
|
||||
m.busySpinner.control = "stop"
|
||||
m.busySpinner.poster.rotation = 0
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnItemHasFocusChange() as void
|
||||
if m.top.itemContent = invalid
|
||||
m.detailsLabel.visible = false
|
||||
return
|
||||
end if
|
||||
m.detailsLabel.visible = m.top.itemHasFocus and not StringUtils.IsNullOrEmpty(m.top.itemContent.details)
|
||||
end function
|
||||
|
||||
function OnFocusPercentChange() as void
|
||||
if m.top.itemContent = invalid or not m.top.gridHasFocus
|
||||
m.detailsLabel.visible = false
|
||||
return
|
||||
end if
|
||||
m.detailsLabel.visible = m.top.focusPercent > 0.5 and not StringUtils.IsNullOrEmpty(m.top.itemContent.details)
|
||||
end function
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousInstanceTestingItem" extends="Group">
|
||||
<interface>
|
||||
<field id="itemContent" type="node" onChange="OnContentSet" />
|
||||
<field id="state" type="string" onChange="OnStateChange" />
|
||||
<field id="gridHasFocus" type="boolean" />
|
||||
<field id="itemHasFocus" type="boolean" onChange="OnItemHasFocusChange" />
|
||||
<field id="focusPercent" type="float" onChange="OnFocusPercentChange" />
|
||||
</interface>
|
||||
<children>
|
||||
<BusySpinner
|
||||
id="busySpinner"
|
||||
translation="[5,0]" />
|
||||
<Label
|
||||
id="nameLabel"
|
||||
width="450"
|
||||
translation="[60,10]" />
|
||||
<Label
|
||||
id="detailsLabel"
|
||||
visible="false"
|
||||
horizAlign="right"
|
||||
width="300"
|
||||
text="Press 'OK' for details"
|
||||
translation="[560,10]" />
|
||||
</children>
|
||||
</component>
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
@asynctask
|
||||
function InvidiousInstanceTestingTask(input as object) as object
|
||||
instance = input.instance
|
||||
listNode = input.listNode
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
content = PrepareTests()
|
||||
listNode.content = content
|
||||
|
||||
RunTests(instance, content)
|
||||
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function PrepareTests() as object
|
||||
content = CreateObject("roSGNode", "ContentNode")
|
||||
content.AppendChild(CreateTestNode("Valid url", IsValidUrl))
|
||||
content.AppendChild(CreateTestNode("Instance reachable", IsReachable))
|
||||
content.AppendChild(CreateTestNode("Fetch video details", CanFetchVideoDetails))
|
||||
content.AppendChild(CreateTestNode("Fetch video comments", CanFetchVideoComments))
|
||||
content.AppendChild(CreateTestNode("Fetch video captions", CanFetchVideoCaptions))
|
||||
return content
|
||||
end function
|
||||
|
||||
function CreateTestNode(title as string, func as function) as object
|
||||
testNode = CreateObject("roSGNode", "ContentNode")
|
||||
testNode.title = title
|
||||
testNode.AddFields({
|
||||
func: FuncName(func),
|
||||
state: "loading",
|
||||
details: "",
|
||||
duration: 0
|
||||
})
|
||||
m[testNode.func] = func
|
||||
return testNode
|
||||
end function
|
||||
|
||||
function RunTests(instance as string, content as object) as void
|
||||
testNodes = content.getChildren(-1, 0)
|
||||
|
||||
timer = CreateObject("roTimespan")
|
||||
|
||||
for each testNode in testNodes
|
||||
timer.Mark()
|
||||
m[testNode.func](instance, testNode)
|
||||
testNode.duration = timer.TotalMilliseconds()
|
||||
|
||||
if m.top.cancel
|
||||
return
|
||||
end if
|
||||
end for
|
||||
end function
|
||||
|
||||
function IsValidUrl(instance as string, testNode as object) as void
|
||||
try
|
||||
if not instance.StartsWith("http://") and not instance.StartsWith("https://")
|
||||
testNode.state = "failed"
|
||||
testNode.details = "Url must start with http:// or https://"
|
||||
return
|
||||
end if
|
||||
if instance.EndsWith("/")
|
||||
testNode.state = "failed"
|
||||
testNode.details = "Url must not end with /"
|
||||
return
|
||||
end if
|
||||
|
||||
testNode.state = "passed"
|
||||
testNode.details = "The url seems to be of a valid format"
|
||||
catch e
|
||||
testNode.state = "failed"
|
||||
testNode.details = ErrorUtils.Format(e)
|
||||
end try
|
||||
end function
|
||||
|
||||
function IsReachable(instance as string, testNode as object) as void
|
||||
try
|
||||
url = `${instance}${Invidious.STATS_ENDPOINT}`
|
||||
response = HttpClient.Get(url).NoCache().Await()
|
||||
if not response.IsSuccess()
|
||||
testNode.state = "failed"
|
||||
testNode.details = response.ErrorMessage()
|
||||
return
|
||||
end if
|
||||
|
||||
json = response.Json()
|
||||
if json = invalid
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url}`
|
||||
return
|
||||
end if
|
||||
|
||||
name = json.software?.name
|
||||
if not IsString(name)
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url} (couldn't read software.name)`
|
||||
return
|
||||
end if
|
||||
|
||||
version = json.software?.version
|
||||
if not IsString(version)
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url} (couldn't read software.version)`
|
||||
return
|
||||
end if
|
||||
|
||||
testNode.state = "passed"
|
||||
testNode.details = `The instance is reachable and running ${name} version ${version}`
|
||||
catch e
|
||||
testNode.state = "failed"
|
||||
testNode.details = ErrorUtils.Format(e)
|
||||
end try
|
||||
|
||||
end function
|
||||
|
||||
function CanFetchVideoDetails(instance as string, testNode as object) as void
|
||||
try
|
||||
videoId = "jNQXAC9IVRw"
|
||||
url = `${instance}${Invidious.VIDEOS_ENDPOINT}/${videoId}`
|
||||
response = HttpClient.Get(url).NoCache().Await()
|
||||
|
||||
if not response.IsSuccess()
|
||||
testNode.state = "failed"
|
||||
testNode.details = response.ErrorMessage()
|
||||
return
|
||||
end if
|
||||
|
||||
json = response.Json()
|
||||
if json = invalid
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url}`
|
||||
return
|
||||
end if
|
||||
|
||||
title = json.title
|
||||
if not IsString(title)
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url} (couldn't read title)`
|
||||
return
|
||||
end if
|
||||
|
||||
testNode.state = "passed"
|
||||
testNode.details = `The instance can fetch video details for id "${videoId}" (${title})`
|
||||
catch e
|
||||
testNode.state = "failed"
|
||||
testNode.details = ErrorUtils.Format(e)
|
||||
end try
|
||||
end function
|
||||
|
||||
function CanFetchVideoComments(instance as string, testNode as object) as void
|
||||
try
|
||||
videoId = "jNQXAC9IVRw"
|
||||
url = `${instance}/api/v1/comments/${videoId}`
|
||||
response = HttpClient.Get(url).NoCache().Await()
|
||||
|
||||
if not response.IsSuccess()
|
||||
testNode.state = "failed"
|
||||
testNode.details = response.ErrorMessage()
|
||||
return
|
||||
end if
|
||||
|
||||
json = response.Json()
|
||||
if json = invalid
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url}`
|
||||
return
|
||||
end if
|
||||
|
||||
commentCount = json.commentCount
|
||||
if not IsInt(commentCount)
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url} (couldn't read commentCount)`
|
||||
return
|
||||
end if
|
||||
|
||||
comments = json.comments
|
||||
if not IsArray(comments)
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url} (couldn't read comments)`
|
||||
return
|
||||
end if
|
||||
|
||||
testNode.state = "passed"
|
||||
testNode.details = `The instance can fetch video comments for id "${videoId}" (${commentCount} comments)`
|
||||
catch e
|
||||
testNode.state = "failed"
|
||||
testNode.details = ErrorUtils.Format(e)
|
||||
end try
|
||||
end function
|
||||
|
||||
function CanFetchVideoCaptions(instance as string, testNode as object) as void
|
||||
try
|
||||
videoId = "jNQXAC9IVRw"
|
||||
label = "English"
|
||||
url = `${instance}/api/v1/captions/${videoId}?label=${label}`
|
||||
response = HttpClient.Get(url).NoCache().Await()
|
||||
|
||||
if not response.IsSuccess()
|
||||
testNode.state = "failed"
|
||||
testNode.details = response.ErrorMessage()
|
||||
return
|
||||
end if
|
||||
|
||||
headers = response.Headers()
|
||||
contentType = headers["Content-Type"]
|
||||
if StringUtils.IsNullOrEmpty(contentType) or not contentType.StartsWith("text/vtt")
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid caption data ${url} (Content-Type is not text/vtt)`
|
||||
return
|
||||
end if
|
||||
|
||||
text = response.Text()
|
||||
if StringUtils.IsNullOrEmpty(text) or not text.StartsWith("WEBVTT")
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid caption data from ${url} (response is not a valid vtt file)`
|
||||
return
|
||||
end if
|
||||
|
||||
if text.InStr(`All right, so here we are, in front of the\nelephants`) = -1
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Did not find expected text in caption data from ${url}`
|
||||
return
|
||||
end if
|
||||
|
||||
testNode.state = "passed"
|
||||
testNode.details = `The instance can fetch video ${label} captions for id "${videoId}"`
|
||||
catch e
|
||||
testNode.state = "failed"
|
||||
testNode.details = ErrorUtils.Format(e)
|
||||
end try
|
||||
end function
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/Screens/SettingsScreen/InvidiousInstance/InvidiousPublicInstances/InvidiousPublicInstancesTask.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.log = new log.Logger("InvidiousPublicInstances")
|
||||
|
||||
m.failedLabel = m.top.findNode("failedLabel")
|
||||
m.refreshButton = m.top.findNode("refreshButton")
|
||||
m.instances = m.top.findNode("instances")
|
||||
m.instancesHeader = m.top.findNode("instancesHeader")
|
||||
|
||||
m.busySpinner = m.top.findNode("busySpinner")
|
||||
m.busyspinner.poster.width = 100
|
||||
m.busyspinner.poster.height = 100
|
||||
m.busySpinner.poster.uri = "pkg:/images/spinner.png"
|
||||
|
||||
m.instances.ObserveField("itemSelected", FuncName(OnInstanceSelected))
|
||||
m.refreshButton.ObserveField("buttonSelected", FuncName(Refresh))
|
||||
Refresh()
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
if m.refreshButton.visible
|
||||
NodeSetFocus(m.refreshButton, true)
|
||||
else
|
||||
NodeSetFocus(m.instances, true)
|
||||
end if
|
||||
end function
|
||||
|
||||
function Refresh()
|
||||
m.top.focusable = false
|
||||
m.instances.visible = false
|
||||
m.instancesHeader.visible = false
|
||||
m.failedLabel.visible = false
|
||||
m.refreshButton.visible = false
|
||||
if m.invidiousPublicInstancesTask <> invalid
|
||||
m.invidiousPublicInstancesTask.cancel = true
|
||||
end if
|
||||
|
||||
m.invidiousPublicInstancesTask = StartAsyncTask(InvidiousPublicInstancesTask, {
|
||||
listNode: m.instances
|
||||
}, OnInvidiousPublicInstancesTaskResults)
|
||||
|
||||
m.busySpinner.visible = true
|
||||
m.busySpinner.control = "start"
|
||||
end function
|
||||
|
||||
function OnInvidiousPublicInstancesTaskResults(output as object) as void
|
||||
m.top.focusable = true
|
||||
m.busySpinner.visible = false
|
||||
m.busySpinner.control = "stop"
|
||||
|
||||
m.invidiousPublicInstancesTask = invalid
|
||||
if output.cancelled
|
||||
return
|
||||
end if
|
||||
|
||||
if not output.success or not output.result.success
|
||||
' output.error for unhandled exception
|
||||
error = output.error
|
||||
if error = invalid
|
||||
' output.result.error for network errors
|
||||
error = output.result.error
|
||||
end if
|
||||
error = ErrorUtils.Format(error)
|
||||
m.log.error(output.error)
|
||||
|
||||
message = `Failed to load Invidious public instances\n${error}`
|
||||
DialogUtils.ShowDialog(message, "Invidious public instances load error", true)
|
||||
|
||||
m.failedLabel.visible = true
|
||||
m.refreshButton.visible = true
|
||||
if m.top.IsInFocusChain()
|
||||
NodeSetFocus(m.top, true)
|
||||
end if
|
||||
return
|
||||
end if
|
||||
|
||||
m.instances.visible = true
|
||||
m.instancesHeader.visible = true
|
||||
|
||||
if m.top.IsInFocusChain()
|
||||
NodeSetFocus(m.top, true)
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnInstanceSelected(event as object) as void
|
||||
selected = m.instances.itemSelected
|
||||
itemContent = m.instances.content.GetChild(selected)
|
||||
m.top.instance = itemContent.uri
|
||||
end function
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousPublicInstances" extends="Group" includes="Focus">
|
||||
<interface>
|
||||
<field id="instance" type="string" />
|
||||
</interface>
|
||||
<children>
|
||||
<BusySpinner
|
||||
id="busySpinner"
|
||||
translation="[380,96]" />
|
||||
<Label
|
||||
id="failedLabel"
|
||||
text="Failed to load Invidious public instances."
|
||||
translation="[190,60]" />
|
||||
<Button
|
||||
id="refreshButton"
|
||||
minWidth="0"
|
||||
text="Refresh"
|
||||
translation="[340,130]" />
|
||||
|
||||
<InvidiousPublicInstancesListItem id="instancesHeader">
|
||||
<InvidiousPublicInstancesListItemContent
|
||||
role="itemContent"
|
||||
name="name"
|
||||
version="version"
|
||||
users="users"
|
||||
signup="signup"
|
||||
location="location"
|
||||
health="health" />
|
||||
</InvidiousPublicInstancesListItem>
|
||||
|
||||
<MarkupGrid
|
||||
id="instances"
|
||||
itemComponentName="InvidiousPublicInstancesListItem"
|
||||
itemSize="[860,16]"
|
||||
itemSpacing="[0,20]"
|
||||
numColumns="1"
|
||||
numRows="7"
|
||||
vertFocusAnimationStyle="floatingFocus"
|
||||
translation="[0,46]" />
|
||||
|
||||
</children>
|
||||
</component>
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
function Init()
|
||||
m.nameLabel = m.top.findNode("nameLabel")
|
||||
m.versionLabel = m.top.findNode("versionLabel")
|
||||
m.usersLabel = m.top.findNode("usersLabel")
|
||||
m.signupLabel = m.top.findNode("signupLabel")
|
||||
m.locationLabel = m.top.findNode("locationLabel")
|
||||
m.flagEmoji = m.top.findNode("flagEmoji")
|
||||
m.healthLabel = m.top.findNode("healthLabel")
|
||||
|
||||
end function
|
||||
|
||||
function OnContentSet() as void
|
||||
content = m.top.itemContent
|
||||
|
||||
m.nameLabel.text = content.name
|
||||
m.versionLabel.text = content.version
|
||||
m.usersLabel.text = content.users
|
||||
m.signupLabel.text = content.signup
|
||||
m.locationLabel.text = content.location
|
||||
m.flagEmoji.uri = content.flag
|
||||
m.healthLabel.text = content.health
|
||||
end function
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousPublicInstancesListItem" extends="Group">
|
||||
<interface>
|
||||
<field id="itemContent" type="node" onChange="OnContentSet" />
|
||||
</interface>
|
||||
<children>
|
||||
<Label
|
||||
id="nameLabel"
|
||||
font="font:SmallestSystemFont"
|
||||
width="240" />
|
||||
<Label
|
||||
id="versionLabel"
|
||||
font="font:SmallestSystemFont"
|
||||
width="220"
|
||||
translation="[240,0]" />
|
||||
<Label
|
||||
id="usersLabel"
|
||||
font="font:SmallestSystemFont"
|
||||
width="100"
|
||||
translation="[460,0]" />
|
||||
<Label
|
||||
id="signupLabel"
|
||||
font="font:SmallestSystemFont"
|
||||
width="90"
|
||||
translation="[550,0]" />
|
||||
<Label
|
||||
id="locationLabel"
|
||||
font="font:SmallestSystemFont"
|
||||
width="100"
|
||||
translation="[650,0]" />
|
||||
<Poster
|
||||
id="flagEmoji"
|
||||
width="16"
|
||||
height="16"
|
||||
translation="[650,0]" />
|
||||
<Label
|
||||
id="healthLabel"
|
||||
font="font:SmallestSystemFont"
|
||||
width="100"
|
||||
translation="[750,0]" />
|
||||
</children>
|
||||
</component>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousPublicInstancesListItemContent" extends="ContentNode">
|
||||
<interface>
|
||||
<field id="name" type="string" />
|
||||
<field id="version" type="string" />
|
||||
<field id="users" type="string" />
|
||||
<field id="signup" type="string" />
|
||||
<field id="location" type="string" />
|
||||
<field id="flag" type="string" />
|
||||
<field id="health" type="string" />
|
||||
<field id="uri" type="string" />
|
||||
</interface>
|
||||
</component>
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
|
||||
@asynctask
|
||||
function InvidiousPublicInstancesTask(input as object) as object
|
||||
listNode = input.listNode
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
response = HttpClient.Get(Invidious.INSTANCES_API).Await()
|
||||
instances = response.Json()
|
||||
|
||||
if not response.IsSuccess() or instances = invalid
|
||||
return {
|
||||
success: false,
|
||||
error: response.ErrorMessage()
|
||||
}
|
||||
end if
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
instances = FilterInstances(instances)
|
||||
|
||||
content = CreateObject("roSGNode", "ContentNode")
|
||||
|
||||
for each instance in instances
|
||||
item = CreateObject("roSGNode", "InvidiousPublicInstancesListItemContent")
|
||||
item.setFields({
|
||||
name: instance[0],
|
||||
version: instance[1].stats.software.version,
|
||||
users: instance[1].stats.usage.users.total,
|
||||
signup: instance[1].stats.openRegistrations ? "Yes" : "No",
|
||||
' Leave 5 spaces for the flag, just to simplify the layout
|
||||
location: ` ${instance[1].region}`,
|
||||
flag: GetFlagUrl(instance[1].flag),
|
||||
health: instance[1].monitor["30dRatio"].ratio,
|
||||
uri: instance[1].uri
|
||||
})
|
||||
content.AppendChild(item)
|
||||
end for
|
||||
|
||||
listNode.content = content
|
||||
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
end function
|
||||
|
||||
function FilterInstances(instances as object) as object
|
||||
filtered = []
|
||||
|
||||
for each instance in instances
|
||||
flags = instance[1]
|
||||
if flags.type = "https" and flags.api = true and flags.cors = true
|
||||
filtered.Push(instance)
|
||||
end if
|
||||
end for
|
||||
|
||||
return filtered
|
||||
end function
|
||||
|
||||
function GetFlagUrl(flag as string) as string
|
||||
codePoint = emojiToCodePoint(flag)
|
||||
return `https://github.githubassets.com/images/icons/emoji/unicode/${codePoint}.png?v8`
|
||||
end function
|
||||
|
||||
function emojiToCodePoint(emoji as string) as string
|
||||
codes = []
|
||||
chars = emoji.Split("")
|
||||
for i = 0 to chars.count() - 1
|
||||
c = Asc(chars[i])
|
||||
codes.push(StrI(c, 16))
|
||||
end for
|
||||
return codes.join("-")
|
||||
end function
|
||||
@@ -0,0 +1,82 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.top.focusable = true
|
||||
m.radioButtonList = m.top.findNode("RadioButtonList")
|
||||
m.radioButtonListContent = m.top.findNode("RadioButtonListContent")
|
||||
|
||||
m.top.itemSpacings = [8]
|
||||
m.radioButtonList.observeField("checkedItem", FuncName(OnCheckedItemChange))
|
||||
end function
|
||||
|
||||
function BindPreference(preferences as object, key as string)
|
||||
if m.preferences <> invalid and m.key <> invalid
|
||||
m.preferences.unobserveFieldScoped(m.key)
|
||||
end if
|
||||
|
||||
m.preferences = preferences
|
||||
m.key = key
|
||||
|
||||
if preferences <> invalid and key <> invalid
|
||||
preferences.observeFieldScoped(key, FuncName(OnPreferenceChange))
|
||||
OnPreferenceChange()
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnPreferenceChange()
|
||||
m.top.value = m.preferences[m.key]
|
||||
end function
|
||||
|
||||
function OnValueChange() as void
|
||||
value = m.top.value
|
||||
options = m.top.options
|
||||
|
||||
checkedItem = -1
|
||||
for i = 0 to options.Count() - 1
|
||||
option = options[i].value
|
||||
if value = option
|
||||
checkedItem = i
|
||||
exit for
|
||||
end if
|
||||
end for
|
||||
|
||||
m.radioButtonList.checkedItem = checkedItem
|
||||
|
||||
if m.preferences = invalid or m.key = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.preferences[m.key] = m.top.value
|
||||
end function
|
||||
|
||||
function OnOptionsChange()
|
||||
options = m.top.options
|
||||
|
||||
m.radioButtonListContent.removeChildrenIndex(m.radioButtonListContent.getChildCount(), 0)
|
||||
for i = 0 to options.Count() - 1
|
||||
option = options[i].displayText
|
||||
node = CreateObject("roSGNode", "ContentNode")
|
||||
node.title = option
|
||||
m.radioButtonListContent.appendChild(node)
|
||||
end for
|
||||
|
||||
OnValueChange()
|
||||
end function
|
||||
|
||||
function OnCheckedItemChange()
|
||||
checkedItem = m.radioButtonList.checkedItem
|
||||
options = m.top.options
|
||||
|
||||
if checkedItem >= 0 and checkedItem < options.Count()
|
||||
m.top.value = options[checkedItem].value
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.radioButtonList, true)
|
||||
end function
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="RadioControl" extends="LayoutGroup" includes="Focus">
|
||||
<interface>
|
||||
<field id="displayText" type="string" alias="DisplayTextLabel.text" />
|
||||
<field id="description" type="string" alias="DescriptionLabel.text" />
|
||||
<field id="value" type="string" onChange="OnValueChange" />
|
||||
<field id="options" type="array" onChange="OnOptionsChange" />
|
||||
<function name="BindPreference" />
|
||||
</interface>
|
||||
<children>
|
||||
<Label id="DisplayTextLabel" width="450" />
|
||||
<Label id="DescriptionLabel"
|
||||
width="450"
|
||||
color="0xb4b4b4ff"
|
||||
wrap="true">
|
||||
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||
</Label>
|
||||
<RadioButtonList id="RadioButtonList" vertFocusAnimationStyle="floatingFocus">
|
||||
<ContentNode id="RadioButtonListContent" role="content" />
|
||||
</RadioButtonList>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,36 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.container = m.top.findNode("Container")
|
||||
m.displayTextLabel = m.top.findNode("DisplayTextLabel")
|
||||
m.descriptionLabel = m.top.findNode("DescriptionLabel")
|
||||
|
||||
m.displayTextLabel.color = m.top.textColor
|
||||
m.descriptionLabel.color = m.top.textColor2
|
||||
|
||||
m.top.iconUri = ""
|
||||
m.top.focusedIconUri = ""
|
||||
m.top.focusFootprintBitmapUri = "pkg:/images/white.9.png"
|
||||
m.top.observeField("focusedChild", FuncName(OnFocusedChildChange))
|
||||
end function
|
||||
|
||||
function Resize()
|
||||
rect = m.container.boundingRect()
|
||||
width = rect.width + m.top.padding * 2
|
||||
height = rect.height + m.top.padding * 2
|
||||
|
||||
m.top.minWidth = width < m.top.minimumWidth ? m.top.minimumWidth : width
|
||||
m.top.height = height
|
||||
|
||||
m.container.translation = [m.top.padding, m.top.padding]
|
||||
end function
|
||||
|
||||
function OnFocusedChildChange()
|
||||
if m.top.hasFocus()
|
||||
m.displayTextLabel.color = m.top.focusedTextColor
|
||||
m.descriptionLabel.color = m.top.focusedTextColor2
|
||||
else
|
||||
m.displayTextLabel.color = m.top.textColor
|
||||
m.descriptionLabel.color = m.top.textColor2
|
||||
end if
|
||||
end function
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="SettingCategory" extends="Button">
|
||||
<interface>
|
||||
<field id="padding" type="integer" value="10" onChange="Resize" />
|
||||
<field id="minimumWidth" type="integer" value="280" onChange="Resize" />
|
||||
<field id="displayText" type="string" alias="DisplayTextLabel.text" onChange="Resize" />
|
||||
<field id="description" type="string" alias="DescriptionLabel.text" onChange="Resize" />
|
||||
<field id="textColor2" type="Color" value="0xb4b4b4ff" />
|
||||
<field id="focusedTextColor2" type="Color" value="0x262626ff" />
|
||||
</interface>
|
||||
<children>
|
||||
<LayoutGroup id="Container" itemSpacings="[5]">
|
||||
<SimpleLabel
|
||||
id="DisplayTextLabel"
|
||||
fontUri="font:SystemFontFile"
|
||||
fontSize="34" />
|
||||
<SimpleLabel id="DescriptionLabel"
|
||||
fontUri="font:SystemFontFile"
|
||||
fontSize="18"
|
||||
translation="[0,42]" />
|
||||
</LayoutGroup>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,202 @@
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/components/Navigation/ScrollTo.bs"
|
||||
|
||||
function Init()
|
||||
m.container = m.top.findNode("Container")
|
||||
m.scrollAnimation = m.top.findNode("scrollAnimation")
|
||||
m.scrollAnimationInterpolator = m.scrollAnimation.findNode("scrollAnimationInterpolator")
|
||||
m.viewport = {
|
||||
x: 150,
|
||||
y: 96,
|
||||
width: 1920,
|
||||
height: 550
|
||||
}
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
startX = 150
|
||||
startY = 100
|
||||
|
||||
controlsX = 400
|
||||
|
||||
categorySpacing = 80
|
||||
controlSpacing = 30
|
||||
|
||||
model = m.preferences.prefsModel
|
||||
previousCategory = invalid
|
||||
previousControl = invalid
|
||||
for each item in model
|
||||
container = m.container.createChild("Group")
|
||||
category = CreateCategoryNode(item, container, startX, startY)
|
||||
if m.firstCategory = invalid
|
||||
m.firstCategory = category.node
|
||||
m.currentNavigtionNode = m.firstCategory
|
||||
end if
|
||||
if previousCategory <> invalid
|
||||
SetNavigation(previousCategory.node, "down", category.node)
|
||||
SetNavigation(category.node, "up", previousCategory.node)
|
||||
end if
|
||||
controls = CreateControls(item, container, startX + controlsX, startY, controlSpacing)
|
||||
|
||||
if controls <> invalid
|
||||
if controls.nodes.Count() > 0
|
||||
SetNavigation(category.node, "right", controls.nodes[0])
|
||||
end if
|
||||
|
||||
for each control in controls.nodes
|
||||
SetNavigation(control, "left", category.node)
|
||||
|
||||
if previousControl <> invalid
|
||||
SetNavigation(previousControl, "down", control)
|
||||
SetNavigation(control, "up", previousControl)
|
||||
end if
|
||||
|
||||
previousControl = control
|
||||
end for
|
||||
end if
|
||||
|
||||
categoryRect = category.rect
|
||||
controlsRect = controls.rect
|
||||
|
||||
maxHeight = categoryRect.height > controlsRect.height ? categoryRect.height : controlsRect.height
|
||||
startY += maxHeight + categorySpacing
|
||||
previousCategory = category
|
||||
end for
|
||||
|
||||
SetNavigation(invalid, "back", m.navBar)
|
||||
SetNavigation(invalid, "left", m.navBar)
|
||||
end function
|
||||
|
||||
function CreateCategoryNode(item as object, container as object, startX as integer, startY as integer) as object
|
||||
node = container.createChild("SettingCategory")
|
||||
node.translation = [startX, startY]
|
||||
node.displayText = item.displayText
|
||||
node.description = item.description
|
||||
return {
|
||||
node: node,
|
||||
rect: node.boundingRect()
|
||||
}
|
||||
end function
|
||||
|
||||
function CreateControls(item as object, container as object, startX as integer, startY as integer, controlSpacing as integer) as object
|
||||
if item.children = invalid
|
||||
return invalid
|
||||
end if
|
||||
x = startX
|
||||
y = startY
|
||||
width = 0
|
||||
height = 0
|
||||
|
||||
nodes = []
|
||||
for each child in item.children
|
||||
if child.visibility = "web"
|
||||
continue for
|
||||
end if
|
||||
control = CreateControl(child, container, startX, startY)
|
||||
if control <> invalid
|
||||
nodes.push(control.node)
|
||||
controlRect = control.rect
|
||||
startY += controlRect.height + controlSpacing
|
||||
if controlRect.width > width
|
||||
width = controlRect.width
|
||||
end if
|
||||
height += controlRect.height + controlSpacing
|
||||
end if
|
||||
end for
|
||||
|
||||
return {
|
||||
nodes: nodes,
|
||||
rect: {
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height
|
||||
}
|
||||
}
|
||||
end function
|
||||
|
||||
function CreateControl(item as object, container as object, startX as integer, startY as integer) as object
|
||||
control = invalid
|
||||
|
||||
if item.type = "boolean"
|
||||
control = CreateBooleanControl(item, container)
|
||||
else if item.type = "radio"
|
||||
control = CreateRadioControl(item, container)
|
||||
else if item.type = "string"
|
||||
control = CreateStringControl(item, container)
|
||||
else if item.rokuComponent <> invalid
|
||||
control = CreateRokuComponent(item, container)
|
||||
end if
|
||||
|
||||
if control = invalid
|
||||
return invalid
|
||||
end if
|
||||
|
||||
control.id = `preference.${item.key}`
|
||||
control.translation = [startX, startY]
|
||||
if control.hasField("binding_done")
|
||||
control@.BindNode(invalid)
|
||||
end if
|
||||
control@.BindPreference(m.preferences, item.key)
|
||||
|
||||
return {
|
||||
node: control,
|
||||
rect: control.boundingRect()
|
||||
}
|
||||
end function
|
||||
|
||||
function CreateBooleanControl(item as object, container as object) as object
|
||||
node = container.createChild("BooleanControl")
|
||||
node.displayText = item.displayText
|
||||
node.description = item.description
|
||||
return node
|
||||
end function
|
||||
|
||||
function CreateRadioControl(item as object, container as object) as object
|
||||
node = container.createChild("RadioControl")
|
||||
node.displayText = item.displayText
|
||||
node.description = item.description
|
||||
node.options = item.options
|
||||
return node
|
||||
end function
|
||||
|
||||
function CreateStringControl(item as object, container as object) as object
|
||||
node = container.createChild("StringControl")
|
||||
node.displayText = item.displayText
|
||||
node.description = item.description
|
||||
return node
|
||||
end function
|
||||
|
||||
function CreateRokuComponent(item as object, container as object) as object
|
||||
node = container.createChild(item.rokuComponent)
|
||||
if node.hasField("displayText")
|
||||
node.displayText = item.displayText
|
||||
end if
|
||||
if node.hasField("description")
|
||||
node.description = item.description
|
||||
end if
|
||||
return node
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
navigation = NavigationKeyHandler(key, press)
|
||||
if navigation.handled
|
||||
m.currentNavigtionNode = navigation.node
|
||||
if m.currentNavigtionNode.isSameNode(m.navBar)
|
||||
m.currentNavigtionNode = m.firstCategory
|
||||
end if
|
||||
ScrollTo(m.viewport, m.container, m.currentNavigtionNode.getParent(), m.scrollAnimation, m.scrollAnimationInterpolator)
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.currentNavigtionNode, true)
|
||||
ScrollTo(m.viewport, m.container, m.currentNavigtionNode.getParent(), m.scrollAnimation, m.scrollAnimationInterpolator)
|
||||
end function
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="SettingsScreen" extends="Group" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="navBar" type="node" bind="/NavBar" />
|
||||
<field id="preferences" type="node" bind="/Preferences" />
|
||||
</interface>
|
||||
<children>
|
||||
<Group id="container">
|
||||
<Animation
|
||||
id="scrollAnimation"
|
||||
duration="0.3">
|
||||
<Vector2DFieldInterpolator
|
||||
id="scrollAnimationInterpolator"
|
||||
key="[ 0.0, 0.5, 1.0 ]"
|
||||
keyValue="[ [0.0,0.0], [0.0,-160.0], [0.0,-320.0]]"
|
||||
fieldToInterp="container.translation" />
|
||||
</Animation>
|
||||
|
||||
</Group>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,84 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.top.focusable = true
|
||||
m.top.itemSpacings = [8]
|
||||
|
||||
m.button = m.top.findNode("button")
|
||||
AdjustButtonLabel(m.button)
|
||||
|
||||
m.button.observeField("buttonSelected", FuncName(ShowEditKeyboard))
|
||||
end function
|
||||
|
||||
function AdjustButtonLabel(button as object) as void
|
||||
children = button.getChildren(-1, 0)
|
||||
for each child in children
|
||||
if child.isSubtype("Label") and child.hasField("horizAlign")
|
||||
child.observeField("horizAlign", FuncName(OnButtonLabelHorizAlignChanged))
|
||||
child.horizAlign = "left"
|
||||
return
|
||||
end if
|
||||
end for
|
||||
end function
|
||||
|
||||
function OnButtonLabelHorizAlignChanged(event as object)
|
||||
label = event.getRoSGNode()
|
||||
if label.horizAlign <> "left"
|
||||
label.horizAlign = "left"
|
||||
end if
|
||||
end function
|
||||
|
||||
function BindPreference(preferences as object, key as string)
|
||||
if m.preferences <> invalid and m.key <> invalid
|
||||
m.preferences.unobserveFieldScoped(m.key)
|
||||
end if
|
||||
|
||||
m.preferences = preferences
|
||||
m.key = key
|
||||
|
||||
if preferences <> invalid and key <> invalid
|
||||
preferences.observeFieldScoped(key, FuncName(OnPreferenceChange))
|
||||
OnPreferenceChange()
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnPreferenceChange()
|
||||
m.top.value = m.preferences[m.key]
|
||||
end function
|
||||
|
||||
function OnValueChange() as void
|
||||
if m.preferences = invalid or m.key = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.preferences[m.key] = m.top.value
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.button, true)
|
||||
end function
|
||||
|
||||
function ShowEditKeyboard()
|
||||
keyboardDialog = createObject("roSGNode", "StandardKeyboardDialog")
|
||||
keyboardDialog.title = m.top.displayText
|
||||
keyboardDialog.message = [m.top.description]
|
||||
keyboardDialog.text = m.top.value
|
||||
keyboardDialog.buttons = ["OK", "Cancel"]
|
||||
keyboardDialog.observeField("buttonSelected", FuncName(OnKeyboardButton))
|
||||
|
||||
m.top.getScene().dialog = keyboardDialog
|
||||
end function
|
||||
|
||||
function OnKeyboardButton(event as object)
|
||||
keyboard = event.getRoSGNode()
|
||||
buttonSelected = keyboard.buttonSelected
|
||||
if buttonSelected = 0
|
||||
m.top.value = keyboard.text
|
||||
end if
|
||||
keyboard.close = true
|
||||
end function
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="StringControl" extends="LayoutGroup" includes="Focus">
|
||||
<interface>
|
||||
<field id="displayText" type="string" alias="DisplayTextLabel.text" />
|
||||
<field id="description" type="string" alias="DescriptionLabel.text" />
|
||||
<field id="value" type="string" alias="Button.text" onChange="OnValueChange" />
|
||||
<function name="BindPreference" />
|
||||
</interface>
|
||||
<children>
|
||||
<Label id="DisplayTextLabel" width="450" />
|
||||
<Label id="DescriptionLabel"
|
||||
width="450"
|
||||
color="0xb4b4b4ff"
|
||||
wrap="true">
|
||||
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||
</Label>
|
||||
<Button id="Button"
|
||||
iconUri=""
|
||||
focusedIconUri=""
|
||||
showFocusFootprint="true"
|
||||
minWidth="420" />
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,8 @@
|
||||
@asynctask
|
||||
function GenerateQrCodeTask(input as object)
|
||||
' TODO:P1 QR Code generation is happening on UI thread and is hanging for a second
|
||||
' Needs to be properly decoupled from Node logic
|
||||
qrPoster = input.qrPoster
|
||||
text = input.text
|
||||
qrPoster.text = text
|
||||
end function
|
||||
@@ -0,0 +1,26 @@
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/Screens/WebAppScreen/GenerateQrCodeTask.bs"
|
||||
|
||||
function Init()
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
address = m.webserver@.GetServerAddress(invalid)
|
||||
isValidIp = not StringUtils.IsNullOrEmpty(address)
|
||||
if isValidIp
|
||||
m.top.url = address
|
||||
end if
|
||||
m.top.findNode("noInternet").visible = not isValidIp
|
||||
m.top.findNode("yesInternet").visible = isValidIp
|
||||
end function
|
||||
|
||||
function OnUrlSet()
|
||||
url = m.top.url
|
||||
|
||||
urlLabel = m.top.findNode("urlLabel")
|
||||
urlLabel.text = url
|
||||
|
||||
qrCode = m.top.findNode("QrCodePoster")
|
||||
StartAsyncTask(GenerateQrCodeTask, { qrPoster: qrCode, text: url })
|
||||
end function
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="WebAppScreen" extends="Group" includes="AutoBind">
|
||||
<interface>
|
||||
<field id="webServer" type="node" bind="/WebServer" />
|
||||
<field id="url" type="string" onChange="OnUrlSet" />
|
||||
<field id="qrCodeUrl" type="string" onChange="OnUrlSet" />
|
||||
</interface>
|
||||
<children>
|
||||
<Group id="noInternet" visible="false">
|
||||
<Label
|
||||
height='720'
|
||||
width='1280'
|
||||
font='font:MediumBoldSystemFont'
|
||||
horizAlign="center"
|
||||
vertAlign="center"
|
||||
text="Could not get IP address: are we connected to the internet?"
|
||||
/>
|
||||
</Group>
|
||||
<Group id="yesInternet" visible="false">
|
||||
<Label
|
||||
height='60'
|
||||
width='1280'
|
||||
font='font:MediumBoldSystemFont'
|
||||
horizAlign="center"
|
||||
translation="[0,92]"
|
||||
text="Scan the QR code with your phone camera, or open the URL in a web browser:"
|
||||
/>
|
||||
<QRPoster
|
||||
id='QrCodePoster'
|
||||
loadWidth='400'
|
||||
loadHeight='400'
|
||||
loadPadding='20'
|
||||
translation='[440, 160]' />
|
||||
|
||||
<Label
|
||||
id='UrlLabel'
|
||||
height='50'
|
||||
width='1280'
|
||||
font='font:MediumBoldSystemFont'
|
||||
horizAlign="center"
|
||||
translation="[0,600]"
|
||||
/>
|
||||
</Group>
|
||||
</children>
|
||||
</component>
|
||||
Reference in new issue
Block a user