Files
playlet-piped/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousInstanceTesting/InvidiousInstanceTesting.bs
T
Brahim Hadriche ebc5d81180 Fix video selection bug (#419)
* Fix video selection bug

* Refactor key handling

* comment
2024-07-04 11:16:09 -04:00

91 lines
2.7 KiB
Plaintext

import "pkg:/components/Dialog/DialogUtils.bs"
import "pkg:/components/Navigation/Navigation.bs"
import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs"
import "pkg:/source/AsyncTask/AsyncTask.bs"
import "pkg:/source/AsyncTask/Tasks.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.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, RemoteKeys.Up, m.testList)
SetNavigation(m.testList, RemoteKeys.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 = RemoteKeys.Options or key = RemoteKeys.Play or key = RemoteKeys.Pause or key = RemoteKeys.PlayOnly
' A pass-through to the app controller, so it can toggle picture-in-picture and pause/play
return false
end if
if key = RemoteKeys.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()
end function
function RunTestsTask()
instance = m.top.instance
m.titleLabel.text = Tr(Locale.InvidiousTesting.TestingInstance).Replace("%1", instance)
if m.testingTask <> invalid
m.testingTask.cancel = true
end if
m.testingTask = AsyncTask.Start(Tasks.InvidiousInstanceTestingTask, {
instance: instance
listNode: m.testList
})
end function
function ShowTestDetails() as void
selected = m.testList.itemSelected
itemContent = m.testList.content.GetChild(selected)
details = itemContent.details
if StringUtils.IsNullOrEmpty(details)
return
end if
state = itemContent.state
displayStates = {
"passed": Locale.InvidiousTesting.Passed
"failed": Locale.InvidiousTesting.Failed
}
message = Tr(Locale.InvidiousTesting.Status) + ": " + Tr(ValidString(displayStates[state])) + `\n`
message += Tr(Locale.InvidiousTesting.TestDuration) + ": " + `${itemContent.duration}ms\n`
message += Tr(Locale.InvidiousTesting.Details) + ": " + details
title = Tr(Locale.InvidiousTesting.Test) + ": " + itemContent.title
DialogUtils.ShowDialog(message, title)
end function