* TODO * TODO * Add some translations * Remote screen and settings * Video player and http client
230 lines
7.5 KiB
Plaintext
230 lines
7.5 KiB
Plaintext
import "pkg:/components/Dialog/DialogUtils.bs"
|
|
import "pkg:/components/Navigation/Navigation.bs"
|
|
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
|
import "pkg:/source/AsyncTask/Tasks.bs"
|
|
import "pkg:/source/utils/ErrorUtils.bs"
|
|
import "pkg:/source/utils/FocusManagement.bs"
|
|
import "pkg:/source/utils/Locale.bs"
|
|
import "pkg:/source/utils/Logging.bs"
|
|
import "pkg:/source/utils/MathUtils.bs"
|
|
import "pkg:/source/utils/StringUtils.bs"
|
|
|
|
function Init()
|
|
m.webAppButton = m.top.findNode("WebAppButton")
|
|
m.linkWithWifiButton = m.top.findNode("LinkWithWiFiButton")
|
|
m.linkWithTvButton = m.top.findNode("LinkWithTvButton")
|
|
|
|
m.webAppPanel = m.top.findNode("WebAppPanel")
|
|
m.linkWithWifiPanel = m.top.findNode("LinkWithWiFiPanel")
|
|
m.linkWithTvPanel = m.top.findNode("LinkWithTvPanel")
|
|
|
|
m.webAppUrlLabel = m.top.findNode("WebAppUrlLabel")
|
|
m.webAppQrCodePoster = m.top.findNode("WebAppQrCodePoster")
|
|
m.wifiNameLabel = m.top.findNode("WifiNameLabel")
|
|
m.wifiInstructionWithDeviceNameLabel = m.top.findNode("WifiInstructionWithDeviceNameLabel")
|
|
m.linkCodeLabel = m.top.findNode("LinkCodeLabel")
|
|
|
|
m.wifiInstructionWithDeviceNameLabel.drawingStyles = {
|
|
"Bold": {
|
|
"fontSize": 22
|
|
"fontUri": "font:SmallBoldSystemFont"
|
|
' TODO:P2 DDDDDDFF is the default for labels, but the linter is not happy about it
|
|
' We need to figure out if the linter has wrong values or not
|
|
' bs:disable-next-line LINT3023
|
|
"color": "#DDDDDDFF"
|
|
}
|
|
"default": {
|
|
"fontSize": 22
|
|
"fontUri": "font:SmallSystemFont"
|
|
' bs:disable-next-line LINT3023
|
|
"color": "#DDDDDDFF"
|
|
}
|
|
}
|
|
end function
|
|
|
|
function OnNodeReady()
|
|
SetNavigation(m.webAppButton, "down", m.linkWithWifiButton)
|
|
SetNavigation(m.linkWithWifiButton, "down", m.linkWithTvButton)
|
|
SetNavigation(m.linkWithTvButton, "up", m.linkWithWifiButton)
|
|
SetNavigation(m.linkWithWifiButton, "up", m.webAppButton)
|
|
|
|
SetNavigation(invalid, "back", m.navBar)
|
|
SetNavigation(invalid, "left", m.navBar)
|
|
|
|
address = m.webserver@.GetServerAddress()
|
|
isValidAddress = not StringUtils.IsNullOrEmpty(address)
|
|
if isValidAddress
|
|
m.top.url = address
|
|
end if
|
|
m.top.findNode("noInternet").visible = not isValidAddress
|
|
m.top.findNode("yesInternet").visible = isValidAddress
|
|
m.top.focusable = isValidAddress
|
|
|
|
m.top.observeField("visible", FuncName(OnVisibleChanged))
|
|
|
|
m.linkWithWifiPanel.observeField("visible", FuncName(OnLinkWithWifiPanelVisibleChanged))
|
|
m.linkWithWifiPanel.visible = false
|
|
m.linkWithTvPanel.observeField("visible", FuncName(OnLinkWithTvPanelVisibleChanged))
|
|
m.linkWithTvPanel.visible = false
|
|
|
|
m.webAppButton.observeField("contentWidth", FuncName(OnButtonSizeChange))
|
|
m.linkWithWifiButton.observeField("contentWidth", FuncName(OnButtonSizeChange))
|
|
m.linkWithTvButton.observeField("contentWidth", FuncName(OnButtonSizeChange))
|
|
OnButtonSizeChange()
|
|
end function
|
|
|
|
function OnFocusChange() as void
|
|
if not m.top.focus
|
|
return
|
|
end if
|
|
|
|
if m.currentNavigtionNode = invalid
|
|
m.currentNavigtionNode = m.webAppButton
|
|
end if
|
|
|
|
NodeSetFocus(m.currentNavigtionNode, true)
|
|
ShowTab(m.currentNavigtionNode)
|
|
end function
|
|
|
|
function OnUrlSet()
|
|
url = m.top.url
|
|
|
|
m.webAppUrlLabel.text = url
|
|
m.webAppQrCodePoster.text = url
|
|
end function
|
|
|
|
function OnButtonSizeChange()
|
|
width1 = m.webAppButton.contentWidth
|
|
width2 = m.linkWithWifiButton.contentWidth
|
|
width3 = m.linkWithTvButton.contentWidth
|
|
|
|
width = MathUtils.Max(width1, MathUtils.Max(width2, width3))
|
|
|
|
m.webAppButton.minimumWidth = width
|
|
m.linkWithWifiButton.minimumWidth = width
|
|
m.linkWithTvButton.minimumWidth = width
|
|
end function
|
|
|
|
function OnkeyEvent(key as string, press as boolean) as boolean
|
|
navigation = NavigationKeyHandler(key, press)
|
|
if navigation.handled
|
|
ShowTab(navigation.node)
|
|
return true
|
|
end if
|
|
return false
|
|
end function
|
|
|
|
function ShowTab(button as object)
|
|
if button.isSameNode(m.webAppButton)
|
|
m.webAppPanel.visible = true
|
|
m.linkWithWifiPanel.visible = false
|
|
m.linkWithTvPanel.visible = false
|
|
m.currentNavigtionNode = button
|
|
else if button.isSameNode(m.linkWithWifiButton)
|
|
m.linkWithWifiPanel.visible = true
|
|
m.webAppPanel.visible = false
|
|
m.linkWithTvPanel.visible = false
|
|
m.currentNavigtionNode = button
|
|
else if button.isSameNode(m.linkWithTvButton)
|
|
m.linkWithTvPanel.visible = true
|
|
m.webAppPanel.visible = false
|
|
m.linkWithWifiPanel.visible = false
|
|
m.currentNavigtionNode = button
|
|
end if
|
|
end function
|
|
|
|
function OnVisibleChanged()
|
|
if not m.top.visible
|
|
m.currentNavigtionNode = invalid
|
|
m.webAppPanel.visible = true
|
|
m.linkWithWifiPanel.visible = false
|
|
m.linkWithTvPanel.visible = false
|
|
end if
|
|
end function
|
|
|
|
function OnLinkWithWifiPanelVisibleChanged() as void
|
|
if not m.linkWithWifiPanel.visible
|
|
return
|
|
end if
|
|
|
|
deviceInfo = CreateObject("roDeviceInfo")
|
|
connectionInfo = deviceInfo.GetConnectionInfo()
|
|
|
|
if connectionInfo.type = "WiFiConnection"
|
|
m.wifiNameLabel.text = connectionInfo.ssid
|
|
else if connectionInfo.type = "WiredConnection"
|
|
m.wifiNameLabel.text = Tr(Locale.RemoteScreen.WiredConnection)
|
|
else
|
|
m.wifiNameLabel.text = "N/A"
|
|
end if
|
|
|
|
deviceName = `<Bold>"${m.loungeService.deviceName}"</Bold>`
|
|
m.wifiInstructionWithDeviceNameLabel.text = Tr(Locale.RemoteScreen.WifiInstruction3).Replace("%1", deviceName)
|
|
end function
|
|
|
|
function OnLinkWithTvPanelVisibleChanged()
|
|
if m.linkWithTvPanel.visible
|
|
GeneratePairingCode()
|
|
else
|
|
if m.linkCodeTask <> invalid
|
|
m.linkCodeTask.cancel = true
|
|
m.linkCodeTask = invalid
|
|
end if
|
|
m.linkCodeLabel.text = ""
|
|
end if
|
|
end function
|
|
|
|
function GeneratePairingCode()
|
|
if m.linkCodeTask <> invalid
|
|
m.linkCodeTask.cancel = true
|
|
end if
|
|
|
|
m.linkCodeLabel.text = Tr(Locale.RemoteScreen.Loading)
|
|
m.linkCodeTask = AsyncTask.Start(Tasks.LoungeGenerateManualPairingCodeTask, {
|
|
loungeService: m.loungeService
|
|
loungeToken: m.loungeService.loungeToken
|
|
screenId: m.loungeService.screenId
|
|
' Use deviceName as screenName
|
|
screenName: m.loungeService.deviceName
|
|
deviceId: m.loungeService.deviceId
|
|
}, OnLoungeGenerateManualPairingCodeTaskResult)
|
|
end function
|
|
|
|
function OnLoungeGenerateManualPairingCodeTaskResult(output as object) as void
|
|
m.linkCodeTask = 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)
|
|
LogError(error)
|
|
|
|
message = Tr(Locale.RemoteScreen.FailedToGeneratePairingCode) + `\n${error}`
|
|
DialogUtils.ShowDialog(message, Tr(Locale.RemoteScreen.TvCodeError), true)
|
|
return
|
|
end if
|
|
|
|
manualLinkCode = output.result.code
|
|
if StringUtils.IsNullOrEmpty(manualLinkCode)
|
|
m.linkCodeLabel.text = ""
|
|
return
|
|
end if
|
|
|
|
' insert a space every 3 characters.
|
|
parts = []
|
|
for i = 0 to manualLinkCode.Len() - 1 step 3
|
|
parts.Push(manualLinkCode.Mid(i, 3))
|
|
end for
|
|
linkCode = parts.Join(" ")
|
|
|
|
m.linkCodeLabel.text = linkCode
|
|
end function
|