Preferences / Web App (#79)

* Add basic router

* Add a preferences file

* small changes

* Basic settings navigation menu

* Lint fix

* Add bunch of controls

* Lint fix

* StringControl

* Lint fix

* Add description to keyboard

* Settings saving and loading

* Lint fix

* Settings migration stuff

* GET web api

* Lint fix

* PUT and DELETE (I really fucking hate BrightScript)

* plug in sponsorblock settings

* autoplay, quality, and video proxying

* Remove unused stuff

* Lint fix

* Invidious instance stuff

* cache public instances on start

* Start loading home screen after fetching instances

* Move web app out of settings to its own screen

* picture in picture when in settings

* Web app (#80)

* Update instance stuff

* Update dependencies

* Add basic layout

* Info and settings page, missing styling

* Navbar fixes

* Settings page formatting

* Theme stuff

* Feedback link

* Fix username badge

* Fix svelte warnings

* A wip search page

* Add a couple of api functions

* Wip home screen

* user country code

* Expose token and proxy auth calls

* Use auth requests server side

* Some cleanup

* Add svelte vs code extension

* remove old web app

* More layout stuff

* Tweak for string control

* Filter out old search suggestions

* Search history stuff

* img size for lazy loading

* Basic modal to play video

* Lint fix

* Dependencies bump

* Add video duration and LIVE indicator to cell

* Delete legacy stuff

* Add dev menu

* Lint fix

* Video cell layout

* Cell stuff

* prefs visibility

* Modal layout

* Drag and drop functionality

* Clear search history

* Move web calls to main app

* changelog

* changelog

* Mostly comments

* Lint fix

---------

Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
Brahim Hadricheandgithub-action linter authored and GitHub committed 2023-06-24 15:33:09 -04:00
1 parent 9a631aab51
commit 8f8c7d38a8
91 files changed
+3979 -1787

No files matched your search

@@ -0,0 +1,43 @@
function Init()
m.radioButtonList = m.top.findNode("RadioButtonList")
m.top.observeField("value", "OnValueChanged")
m.radioButtonList.observeField("checkedItem", "OnCheckedItemChanged")
m.top.observeField("focusedChild", "OnFocusChanged")
m.top.observeField("settings", "OnSettingsScreen")
end function
function OnSettingsScreen()
m.top.value = m.top.settings@.GetPreferenceValue(m.top.key)
end function
function OnValueChanged()
value = m.top.value
if value = true
m.radioButtonList.checkedItem = 0
else if value = false
m.radioButtonList.checkedItem = 1
end if
m.top.settings@.SetPreferenceValue(m.top.key, value)
end function
function OnCheckedItemChanged()
checkedItem = m.radioButtonList.checkedItem
if checkedItem = 0
m.top.value = true
else if checkedItem = 1
m.top.value = false
end if
end function
function OnFocusChanged()
if m.top.hasFocus()
m.radioButtonList.setFocus(true)
end if
end function
function OnkeyEvent(key as string, press as boolean) as boolean
settingsScreen = m.top.getScene().findNode("SettingsScreen")
return settingsScreen@.OnkeyEvent(key, press)
end function
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<component name="BooleanControl" extends="Group">
<interface>
<field id="key" type="string" />
<field id="level" type="int" />
<field id="value" type="bool" alwaysNotify="true" />
<field id="settings" type="node" />
</interface>
<children>
<RadioButtonList id="RadioButtonList">
<ContentNode role="content">
<ContentNode title="Yes" />
<ContentNode title="No" />
</ContentNode>
</RadioButtonList>
</children>
</component>
@@ -0,0 +1,39 @@
import "pkg:/source/services/SearchHistory.bs"
function Init()
m.button = m.top.findNode("clearButton")
m.button.observeField("buttonSelected", "OnButtonSelected")
m.top.observeField("focusedChild", "OnFocusChanged")
end function
function OnFocusChanged()
focused = m.top.hasFocus()
if focused
m.button.SetFocus(true)
end if
end function
function OnButtonSelected()
SearchHistory.Clear()
SearchClearedDialog()
end function
function SearchClearedDialog()
dialog = CreateObject("roSGNode", "StandardMessageDialog")
dialog.title = "Success"
dialog.message = ["Search history cleared."]
dialog.buttons = ["OK"]
dialog.observeField("buttonSelected", "OnDialogButtonSelected")
m.top.getScene().dialog = dialog
end function
function OnDialogButtonSelected()
m.top.getScene().dialog.close = true
end function
function OnkeyEvent(key as string, press as boolean) as boolean
settingsScreen = m.top.getScene().findNode("SettingsScreen")
return settingsScreen@.OnkeyEvent(key, press)
end function
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<component name="ClearSearchHistoryControl" extends="Group">
<interface>
<field id="key" type="string" />
<field id="level" type="int" />
<field id="value" type="bool" alwaysNotify="true" />
<field id="settings" type="node" />
</interface>
<children>
<Button id="clearButton" text="Clear Search History">
</Button>
</children>
</component>
@@ -0,0 +1,64 @@
function Init()
m.radioButtonList = m.top.findNode("RadioButtonList")
m.radioButtonListContent = m.top.findNode("RadioButtonListContent")
m.top.observeField("value", "OnValueChanged")
m.top.observeField("options", "OnOptionsChanged")
m.radioButtonList.observeField("checkedItem", "OnCheckedItemChanged")
m.top.observeField("focusedChild", "OnFocusChanged")
m.top.observeField("settings", "OnSettingsScreen")
end function
function OnSettingsScreen()
m.top.value = m.top.settings@.GetPreferenceValue(m.top.key)
end function
function OnValueChanged()
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
m.top.settings@.SetPreferenceValue(m.top.key, value)
end function
function OnCheckedItemChanged()
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 OnFocusChanged()
if m.top.hasFocus()
m.radioButtonList.setFocus(true)
end if
end function
function OnkeyEvent(key as string, press as boolean) as boolean
settingsScreen = m.top.getScene().findNode("SettingsScreen")
return settingsScreen@.OnkeyEvent(key, press)
end function
function OnOptionsChanged()
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
end function
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<component name="RadioControl" extends="Group">
<interface>
<field id="key" type="string" />
<field id="level" type="int" />
<field id="value" type="string" alwaysNotify="true" />
<field id="options" type="array" alwaysNotify="true" />
<field id="settings" type="node" />
</interface>
<children>
<RadioButtonList id="RadioButtonList">
<ContentNode id="RadioButtonListContent" role="content">
</ContentNode>
</RadioButtonList>
</children>
</component>
@@ -0,0 +1,14 @@
' TODO: this is being called from many places, including possibly background threads
' It should be made better than this
function FindAndGetPreferenceValues(keys as object) as object
values = {}
settings = m.top.getScene().findNode("SettingsScreen")
if settings = invalid
return values
end if
for each key in keys
values[key] = settings@.GetPreferenceValue(key)
end for
return values
end function
@@ -1,17 +1,356 @@
import "pkg:/source/utils/General.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/asyncTask/asyncTask.bs"
import "pkg:/source/services/PreferencesService.bs"
import "pkg:/components/VideoPlayer/Video.bs"
function Init()
m.top.url = `http://${GetLocalIpAddress()}:8888`
m.service = new PreferencesService()
m.menu = m.top.findNode("PreferencesMenu")
m.hint = m.top.findNode("HintLabel")
LoadPreferencesTopLevel(m.service.prefs_model)
RefreshUI(0)
m.top.ObserveField("focus", "OnFocusChange")
m.top.ObserveField("visible", "OnVisibilityChange")
end function
function OnUrlSet()
url = m.top.url
function LoadPreferencesTopLevel(model as object)
m.uiElements = {}
LoadPreferencesAtLevel(model, 0, "")
end function
qrCode = m.top.findNode("SettingsQRPoster")
qrCode.text = url
function LoadPreferencesAtLevel(model as object, level as integer, key as string)
if m.menu.getChildCount() - 1 < level
container = m.menu.createChild("Group")
container.id = `Container${level}`
else
container = m.menu.getChild(level)
end if
urlLabel = m.top.findNode("urlLabel")
urlLabel.text = url
buttonGroup = CreateSubmenu(container, model, level, key)
buttons = []
for each item in model
if item.visibility = "web"
continue for
end if
buttons.push(item.displayText)
if item.children <> invalid
LoadPreferencesAtLevel(item.children, level + 1, item.key)
else if item.type <> invalid
CreateControl(item, level + 1, item.key)
else if item.rokuComponent <> invalid
CreateRokuComponent(item, level + 1, item.key)
end if
end for
buttonGroup.buttons = buttons
buttonGroup.observeField("buttonFocused", "OnButtonFocused")
end function
function CreateSubmenu(container as object, model as object, level as integer, key as string) as object
buttonGroup = container.createChild("ButtonGroup")
buttonGroup.minWidth = 300
buttonGroup.iconUri = ""
buttonGroup.id = `Control${level}`
buttonGroup.visible = false
m.uiElements[key] = buttonGroup
buttonGroup.addFields({
"level": level,
"key": key
})
return buttonGroup
end function
function CreateControl(model as object, level as integer, key as string) as object
menu = m.top.findNode("PreferencesMenu")
if menu.getChildCount() - 1 < level
container = menu.createChild("Group")
container.id = `Container${level}`
else
container = menu.getChild(level)
end if
if model.type = "string"
return CreateStringControl(container, model, level, key)
else if model.type = "boolean"
return CreateBooleanControl(container, model, level, key)
else if model.type = "radio"
return CreateRadioControl(container, model, level, key)
end if
return invalid
end function
function CreateBooleanControl(container as object, model as object, level as integer, key as string) as object
control = container.createChild("BooleanControl")
control.id = `Control${level}`
control.visible = false
control.key = key
control.level = level
m.uiElements[key] = control
control.settings = m.top
return control
end function
function CreateStringControl(container as object, model as object, level as integer, key as string) as object
control = container.createChild("StringControl")
control.id = `Control${level}`
control.visible = false
control.key = key
control.level = level
control.displayText = model.displayText
control.description = model.description
control.settings = m.top
m.uiElements[key] = control
return control
end function
function CreateRadioControl(container as object, model as object, level as integer, key as string) as object
control = container.createChild("RadioControl")
control.id = `Control${level}`
control.visible = false
control.key = key
control.level = level
control.options = model.options
control.settings = m.top
m.uiElements[key] = control
return control
end function
function CreateRokuComponent(model as object, level as integer, key as string) as object
menu = m.top.findNode("PreferencesMenu")
if menu.getChildCount() - 1 < level
container = menu.createChild("Group")
container.id = `Container${level}`
else
container = menu.getChild(level)
end if
component = container.createChild(model.rokuComponent)
component.id = `Control${level}`
component.settings = m.top
component.visible = false
component.key = key
component.level = level
m.uiElements[key] = component
return invalid
end function
function OnButtonFocused(event as object)
buttonGroup = event.getRoSGNode()
RefreshUI(buttonGroup.level + 1)
end function
function RefreshUI(maxLevel = 0 as integer)
for each key in m.uiElements
m.uiElements[key].visible = false
end for
topLevel = m.top.findNode("Control0")
topLevel.visible = true
ShowButtonGroup(m.service.prefs_model, topLevel.buttonFocused, maxLevel)
RefreshHint()
end function
function ShowButtonGroup(model as object, index as integer, maxLevel as integer) as void
item = model[index]
element = m.uiElements[item.key]
if element = invalid
return
end if
if element.level > maxLevel
return
end if
element.visible = true
if item.children <> invalid
ShowButtonGroup(item.children, element.buttonFocused, maxLevel)
end if
end function
function RefreshHint() as void
focusedButtonGroup = GetFocusedControl()
if focusedButtonGroup = invalid
return
end if
selectedIndex = focusedButtonGroup.buttonFocused
if selectedIndex = invalid
return
end if
children = FindModelChildrenByKey(focusedButtonGroup.key, m.service.prefs_model)
if children = invalid
return
end if
if children.Count() <= selectedIndex
return
end if
displayText = children[selectedIndex].displayText
description = children[selectedIndex].description
if description = invalid or description = invalid
return
end if
m.hint.text = `${displayText}: ${description}`
end function
function FindModelChildrenByKey(key as string, model as object) as object
if key = ""
return m.service.prefs_model
end if
for each item in model
if item.key = key
return item.children
end if
if item.children <> invalid
result = FindModelChildrenByKey(key, item.children)
if result <> invalid
return result
end if
end if
end for
return invalid
end function
function OnFocusChange() as void
if m.top.focus <> true
return
end if
topLevelButtonGroup = m.top.findNode("Control0")
if topLevelButtonGroup <> invalid
topLevelButtonGroup.setFocus(true)
RefreshUI(1)
end if
end function
function OnVisibilityChange() as void
if m.top.visible <> true
return
end if
topLevelButtonGroup = m.top.findNode("Control0")
if topLevelButtonGroup <> invalid
topLevelButtonGroup.visible = true
end if
end function
function OnkeyEvent(key as string, press as boolean) as boolean
if press = false
return false
end if
if key = "options"
if ToggleVideoPictureInPicture(m.top)
return true
end if
end if
if key = "back"
m.top.escape = key
return true
end if
if key = "left"
if not MenuGoLeft()
RefreshUI(0)
m.top.escape = key
end if
return true
end if
if key = "right"
if MenuGoRight()
return true
end if
end if
return false
end function
function GetFocusedControl() as object
focusedChild = m.top.focusedChild
if focusedChild = invalid
return invalid
end if
while not focusedChild.id.StartsWith("Control")
focusedChild = focusedChild.focusedChild
if focusedChild = invalid
return invalid
end if
end while
return focusedChild
end function
function MenuGoLeft() as boolean
return MenuNavigate(-1)
end function
function MenuGoRight() as boolean
return MenuNavigate(1)
end function
function MenuNavigate(direction as integer) as boolean
focusedControl = GetFocusedControl()
container = focusedControl.getParent()
containerParent = container.getParent()
containerCount = containerParent.getChildCount()
index = GetChildIndex(containerParent, container)
index += direction
if index >= containerCount or index < 0
return false
end if
newFocusedContainer = containerParent.getChild(index)
childCount = newFocusedContainer.getChildCount()
for i = 0 to childCount - 1
child = newFocusedContainer.getChild(i)
if child.visible
child.setFocus(true)
RefreshUI(index + 1)
return true
end if
end for
return false
end function
function GetChildIndex(node as object, child as object) as integer
childCount = node.getChildCount()
for i = 0 to childCount - 1
c = node.getChild(i)
if child.id = c.id
return i
end if
end for
return -1
end function
function GetPreferenceValue(key as string) as dynamic
return m.service.GetValue(key)
end function
function SetPreferenceValue(key as string, value as dynamic)
m.service.SetValue(key, value)
end function
function GetUserPreferences(unused as object) as object
return m.service.GetUserPreferences()
end function
function ApplyUserPreferences(preferences as object) as void
m.service.ApplyUserPreferences(preferences)
end function
function ClearUserPreferences(unused as object) as void
m.service.ClearUserPreferences()
end function
@@ -2,31 +2,31 @@
<component name="SettingsScreen" extends="Group">
<interface>
<field id="url" type="string" onChange="OnUrlSet" />
<field id="escape" type="string" alwaysNotify="true" />
<field id="focus" type="boolean" alwaysNotify="true" />
<function name="OnkeyEvent" />
<function name="MenuNavigate" />
<function name="GetPreferenceValue" />
<function name="SetPreferenceValue" />
<function name="GetUserPreferences" />
<function name="ApplyUserPreferences" />
<function name="ClearUserPreferences" />
</interface>
<children>
<LayoutGroup
id="PreferencesMenu"
layoutDirection="horiz"
translation="[130,100]"
itemSpacings="[20]"
>
</LayoutGroup>
<Label
height='60'
width='1280'
font='font:MediumBoldSystemFont'
horizAlign="center"
translation="[0,92]"
text="Open in a web browser to configure Playlet:"
/>
<QRPoster
id='SettingsQRPoster'
loadWidth='400'
loadHeight='400'
loadPadding='20'
translation='[440, 160]' />
<Label
id='UrlLabel'
height='50'
width='1280'
font='font:MediumBoldSystemFont'
horizAlign="center"
translation="[0,600]"
id="HintLabel"
height='100'
width='1020'
wrap='true'
font='font:SmallestBoldSystemFont'
translation="[130,600]"
/>
</children>
</component>
@@ -0,0 +1,54 @@
function Init()
m.textEditBox = m.top.findNode("TextEditBox")
m.top.observeField("focusedChild", "OnFocusChanged")
m.top.observeField("value", "OnValueChanged")
m.top.observeField("settings", "OnSettingsScreen")
end function
function OnSettingsScreen()
m.top.value = m.top.settings@.GetPreferenceValue(m.top.key)
end function
function OnFocusChanged()
focused = m.top.hasFocus()
if focused
ShowEditKeyboard()
end if
end function
function OnValueChanged()
value = m.top.value
m.top.editText = value
m.top.settings@.SetPreferenceValue(m.top.key, value)
end function
function OnkeyEvent(key as string, press as boolean) as boolean
settingsScreen = m.top.getScene().findNode("SettingsScreen")
return settingsScreen@.OnkeyEvent(key, press)
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("wasClosed", "OnKeyboardClosed")
keyboardDialog.observeField("buttonSelected", "OnButtonSelected")
m.top.getScene().dialog = keyboardDialog
end function
function OnButtonSelected(event as object)
keyboard = event.getRoSGNode()
buttonSelected = keyboard.buttonSelected
if buttonSelected = 0
m.top.value = keyboard.text
end if
keyboard.close = true
end function
function OnKeyboardClosed()
settingsScreen = m.top.getScene().findNode("SettingsScreen")
settingsScreen@.MenuNavigate(-1)
end function
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<component name="StringControl" extends="Group">
<interface>
<field id="key" type="string" />
<field id="level" type="int" />
<field id="editText" type="string" alias="TextEditBox.text" />
<field id="value" type="string" />
<field id="displayText" type="string" />
<field id="description" type="string" />
<field id="settings" type="node" />
</interface>
<children>
<TextEditBox id="TextEditBox" clearOnDownKey="false">
</TextEditBox>
</children>
</component>