Files
playlet-piped/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousInstanceTesting/InvidiousInstanceTesting.bs
T

90 lines
2.6 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/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, "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"
' 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()
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