Skip to content

Commit

Permalink
Refactor some content node stuff, and add an auth popup dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Sep 6, 2023
1 parent f328fa2 commit ace9e2c
Show file tree
Hide file tree
Showing 25 changed files with 203 additions and 77 deletions.
6 changes: 6 additions & 0 deletions playlet-lib/src/components/ContentNode/ActionContentNode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<component name="ActionContentNode" extends="ContentNode">
<interface>
<field id="type" type="string" value="action" />
<field id="action" type="string" />
</interface>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<interface>
<field id="type" type="string" value="channel" />

<field id="HDItemWidth" type="float" />
<field id="HDItemWidth" type="float" value="200" />
</interface>
</component>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="LoadingContentNode" extends="ContentNode">
<interface>
<field id="isPlaceHolder" type="boolean" value="true" />
<field id="type" type="string" value="loading" />
</interface>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,5 @@
<field id="videoCountText" type="string" />
<field id="viewCount" type="integer" />
<field id="viewCountText" type="string" />

<field id="HDItemWidth" type="float" />
</interface>
</component>
3 changes: 1 addition & 2 deletions playlet-lib/src/components/ContentNode/VideoContentNode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
<field id="premiereTimestampText" type="string" />
<field id="publishedText" type="string" />
<field id="thumbnail" type="uri" />
<field id="timestamp" type="integer" />
<field id="title" type="string" />
<field id="videoId" type="string" />
<field id="viewCountText" type="string" />

<field id="HDItemWidth" type="float" />
</interface>
</component>
39 changes: 39 additions & 0 deletions playlet-lib/src/components/Dialog/LoginDialog.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import "pkg:/source/utils/Types.bs"
import "pkg:/source/asyncTask/asyncTask.bs"
import "pkg:/components/Screens/WebAppScreen/GenerateQrCodeTask.bs"
import "pkg:/source/utils/StringUtils.bs"

function Init()
m.urlLabel = m.top.findNode("urlLabel")
m.qrCode = m.top.findNode("QrCodePoster")

m.top.width = "920"
m.top.observeFieldScoped("buttonSelected", FuncName(Close))
end function

function OnNodeReady()
address = m.webserver@.GetServerAddress(invalid)
isValidIp = not StringUtils.IsNullOrEmpty(address)
if isValidIp
m.top.url = `${address}/invidious/login`
else
m.urlLabel.text = "No IP address found"
end if

m.invidious.observeFieldScoped("authToken", FuncName(OnAuthTokenChange))
end function

function Close()
m.top.close = true
end function

function OnUrlSet()
url = m.top.url

m.urlLabel.text = url
StartAsyncTask(GenerateQrCodeTask, { qrPoster: m.qrCode, text: url })
end function

function OnAuthTokenChange()
Close()
end function
43 changes: 43 additions & 0 deletions playlet-lib/src/components/Dialog/LoginDialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<component name="LoginDialog" extends="StandardDialog" initialFocus="buttonArea" includes="AutoBind">
<interface>
<field id="webServer" type="node" bind="/WebServer" />
<field id="invidious" type="node" bind="/Invidious" />
<field id="url" type="string" onChange="OnUrlSet" />
</interface>
<children>
<StdDlgTitleArea primaryTitle="Login to Invidious" />
<StdDlgContentArea>
<StdDlgTextItem
text="Login to Invidious in order to view Subscriptions, Playlists, and use the Watch history." />
</StdDlgContentArea>
<StdDlgButtonArea id="buttonArea">
<StdDlgButton text="OK" />
</StdDlgButtonArea>
<StdDlgSideCardArea
id="sideCarArea"
horizAlign="right"
width="400"
extendToDialogEdge="false"
showDivider="true">
<Label
text="Scan the QR Code"
horizAlign="center"
wrap="true" width="400">
<Font role="font" uri="font:SystemFontFile" size="24" />
</Label>
<QRPoster
id='QrCodePoster'
loadWidth='300'
loadHeight='300'
loadPadding='10'
translation="[50, 50]" />
<Label
id="urlLabel"
horizAlign="center"
width="400"
translation="[0, 380]">
<Font role="font" uri="font:BoldSystemFontFile" size="18" />
</Label>
</StdDlgSideCardArea>
</children>
</component>
7 changes: 6 additions & 1 deletion playlet-lib/src/components/EcpArgs.bs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ function ProcessArguments(args as object) as void
end if

if not StringUtils.IsNullOrEmpty(args.videoId)
VideoUtils.PlayVideo(args)
node = CreateObject("roSGNode", "VideoContentNode")
node.videoId = args.videoId
if args.timestamp <> invalid
node.timestamp = args.timestamp
end if
VideoUtils.PlayVideo(node)
end if
end function
2 changes: 1 addition & 1 deletion playlet-lib/src/components/PlaylistView/PlaylistView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function OnItemSelected(event as object)
if not VideoUtils.IsVideoPlayerOpen()
Close()
end if
VideoUtils.PlayVideo({ content: video })
VideoUtils.PlayVideo(video)
end if
end function

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace Invidious

const TOKEN_TIMESPAN = 60 * 60 * 24 * 365 * 2 '2 years

const ERROR_NOT_AUTHENTICATED = "Not authenticated"

class InvidiousService
public node as object

Expand Down Expand Up @@ -176,7 +178,7 @@ namespace Invidious
if authToken = invalid
return {
success: false,
error: "Not authenticated"
error: ERROR_NOT_AUTHENTICATED
}
end if
request.Url(authToken.instance + endpoint.url)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import "pkg:/source/utils/TimeUtils.bs"
import "pkg:/components/VideoFeed/FeedLoadState.bs"

namespace InvidiousContent

function ToRowCellContentNode(item as object, instance as string) as object
Expand Down Expand Up @@ -29,7 +32,7 @@ namespace InvidiousContent
end if
end function

function ToVideoContentNode(node as object, item as object, instance as string) as object
function ToVideoContentNode(node as object, item as object, instance as dynamic) as object
if node = invalid
node = CreateObject("roSGNode", "VideoContentNode")
end if
Expand All @@ -43,13 +46,15 @@ namespace InvidiousContent
node.liveNow = VideoIsLive(item)
VideoSetPremiereTimestampText(node, item)
SetIfExists(node, "publishedText", item, "publishedText")
node.thumbnail = VideoGetThumbnail(item, instance) ?? "pkg:/images/thumbnail-missing.jpg"
if not StringUtils.IsNullOrEmpty(instance)
node.thumbnail = VideoGetThumbnail(item, instance) ?? "pkg:/images/thumbnail-missing.jpg"
end if
SetIfExists(node, "title", item, "title")
SetIfExists(node, "timestamp", item, "timestamp")
SetIfExists(node, "videoId", item, "videoId")
node.viewCountText = VideoGetViewCountText(item)
SetIfExists(node, "index", item, "index")

node.HDItemWidth = "350"
return node
end function

Expand Down Expand Up @@ -93,15 +98,13 @@ namespace InvidiousContent
PlaylistSetThumbnail(node, "thumbnail", item, instance)
PlaylistSetThumbnail(node, "thumbnailBackground", item, instance, "maxres")

node.HDItemWidth = "350"
return node
end function

function ToChannelContentNode(item as object, instance as string) as object
node = CreateObject("roSGNode", "ChannelContentNode")
node.type = "channel"

node.HDItemWidth = "200"
return node
end function

Expand Down
13 changes: 13 additions & 0 deletions playlet-lib/src/components/VideoFeed/VideoRowCell/ActionRowCell.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Init()
m.label = m.top.findNode("label")
end function

function OnContentSet() as void
content = m.top.itemContent

if content = invalid
return
end if

m.label.text = content.title
end function
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<component name="ActionRowCell" extends="Group">
<interface>
<field id="itemContent" type="node" onChange="OnContentSet" />
<field id="type" type="string" value="action" />
</interface>
<children>
<Label
id="label"
width="310"
height="196"
horizAlign="center"
vertAlign="center"
translation="[20,0]"
wrap="true"
font="font:LargeBoldSystemFont" />
</children>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<component name="ChannelRowCell" extends="Group">
<interface>
<field id="itemContent" type="node" onChange="OnContentSet" />
<field id="type" type="string" value="channel" />
</interface>
<children>
<LayoutGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

<component name="LoadingRowCell" extends="Group">
<interface>
<field id="itemContent" type="node" onChange="OnContentSet" />
<field id="index" type="integer" onChange="OnIndexSet" />
<field id="type" type="string" value="loading" />
</interface>
<children>
<Rectangle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<component name="PlaylistRowCell" extends="Group">
<interface>
<field id="itemContent" type="node" onChange="OnContentSet" />
<field id="type" type="string" value="playlist" />
</interface>
<children>
<LayoutGroup
Expand Down
44 changes: 19 additions & 25 deletions playlet-lib/src/components/VideoFeed/VideoRowCell/RowCell.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,38 @@ function Init()
m.playlistRowCell = m.top.findNode("PlaylistRowCell")
m.channelRowCell = m.top.findNode("ChannelRowCell")
m.loadingRowCell = m.top.findNode("LoadingRowCell")
m.actionRowCell = m.top.findNode("ActionRowCell")
m.cells = [m.videoRowCell, m.playlistRowCell, m.channelRowCell, m.loadingRowCell, m.actionRowCell]
end function

function OnContentSet() as void
content = m.top.itemContent

if content = invalid
m.videoRowCell.visible = false
m.playlistRowCell.visible = false
m.channelRowCell.visible = false
for each cell in m.cells
cell.visible = false
end for
m.loadingRowCell.visible = true
return
end if

m.top.type = content.type

if content.type = "video"
m.videoRowCell.itemContent = content
m.videoRowCell.visible = true
m.playlistRowCell.visible = false
m.channelRowCell.visible = false
m.loadingRowCell.visible = false
else if content.type = "playlist"
m.playlistRowCell.itemContent = content
m.videoRowCell.visible = false
m.playlistRowCell.visible = true
m.channelRowCell.visible = false
m.loadingRowCell.visible = false
else if content.type = "channel"
m.channelRowCell.itemContent = content
m.videoRowCell.visible = false
m.playlistRowCell.visible = false
m.channelRowCell.visible = true
m.loadingRowCell.visible = false
else
m.videoRowCell.visible = false
m.playlistRowCell.visible = false
m.channelRowCell.visible = false
visibleSet = false
for each cell in m.cells
shouldBeVisible = content.type = cell.type
cell.visible = shouldBeVisible
if shouldBeVisible
cell.itemContent = content
visibleSet = true
end if
end for

if not visibleSet
m.loadingRowCell.visible = true
end if

if m.loadingRowCell.visible
m.loadingRowCell.index = m.top.index
end if
end function
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<PlaylistRowCell id="PlaylistRowCell" />
<ChannelRowCell id="ChannelRowCell" />
<LoadingRowCell id="LoadingRowCell" />
<ActionRowCell id="ActionRowCell" />
</children>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<component name="VideoRowCell" extends="Group">
<interface>
<field id="itemContent" type="node" onChange="OnContentSet" />
<field id="type" type="string" value="video" />
</interface>
<children>
<LayoutGroup
Expand Down
8 changes: 7 additions & 1 deletion playlet-lib/src/components/VideoFeed/VideoRowList.bs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,20 @@ function OnRowItemSelected(event as object)
if rowItem.type = "video"
videoId = rowItem.videoId
m.log.info("Play video: " + videoId)
VideoUtils.PlayVideo({ content: rowItem })
VideoUtils.PlayVideo(rowItem)
else if rowItem.type = "playlist"
playlistId = rowItem.playlistId
m.log.info("Open playlist: " + playlistId)
PlaylistUtils.Open(rowItem)
else if rowItem.type = "channel"
authorId = rowItem.authorId
m.log.info("Open channel: " + authorId)
else if rowItem.type = "action"
if rowItem.action = "LoginDialog"
dialog = CreateObject("roSGNode", "LoginDialog")
dialog@.BindNode(invalid)
m.top.getScene().dialog = dialog
end if
end if
end function

Expand Down
Loading

0 comments on commit ace9e2c

Please sign in to comment.