Skip to content

Commit

Permalink
Feature/yt oauth (#550)
Browse files Browse the repository at this point in the history
* feature flag

* Move view

* Service selection UI

* tweak

* tweak
  • Loading branch information
iBicha authored Jan 26, 2025
1 parent 4acc1bd commit 3cb3c4b
Show file tree
Hide file tree
Showing 19 changed files with 250 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<component name="BackendTypeContentNode" extends="ContentNode">
<interface>
<field id="backendLogoUri" type="uri" />
</interface>
</component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function OnContentSet() as void
content = m.top.itemContent
if content = invalid
return
end if

m.top.backendName = content.title
m.top.backendLogoUri = content.backendLogoUri
end function
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<component name="BackendTypeRowListCell" extends="Group">
<interface>
<field id="itemContent" type="node" onChange="OnContentSet" />
<field id="backendName" type="string" alias="BackendNameLabel.text" />
<field id="backendLogoUri" type="uri" alias="BackendLogoPoster.uri" />
</interface>

<children>
<Group translation="[20,20]">
<Poster
id="BackendLogoPoster"
width="160"
height="160"
translation="[20,20]">
</Poster>
<Label
id="BackendNameLabel"
width="200"
horizAlign="center"
translation="[0,240]">
</Label>
</Group>
</children>
</component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import "pkg:/components/Navigation/Navigation.bs"
import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/Types.bs"

function Init()
m.rowList = m.top.FindNode("BackendRowList")
m.rowList.ObserveField("rowItemSelected", FuncName(OnRowItemSelected))
end function

function OnFocusChange() as void
if not m.top.focus
return
end if

NodeSetFocus(m.rowList, true)
end function

function OnKeyEvent(key as string, press as boolean) as boolean
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()
m.top.appController@.PopScreen()
end function

function OnRowItemSelected(event as object) as void
index = event.GetData()
if index = invalid or index.count() <> 2
LogWarn("Invalid index:", index)
return
end if

Close()

content = m.rowList.content

rowIndex = index[0]
rowItemIndex = index[1]

row = content.GetChild(rowIndex)
rowItem = row.GetChild(rowItemIndex)

m.top.selectedBackendType = rowItem.id
end function
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<component name="BackendTypeSelectionView" extends="Group" includes="AutoBind,Focus">
<interface>
<field id="selectedBackendType" type="string" />
<field id="appController" type="node" bind="/AppController" />
</interface>
<children>
<Rectangle
width="1280"
height="720"
color="#000000"
opacity="0.5">
</Rectangle>

<Rectangle
width="720"
height="420"
translation="[280,150]"
color="#242424">
<Label
width="720"
horizAlign="center"
translation="[0,38]"
text="Select a service to login">
<Font role="font" uri="font:SystemFontFile" size="24" />
</Label>

<RowList
id="BackendRowList"
translation="[120,100]"
numRows="2"
rowitemSize="[[240,240]]"
rowItemSpacing="[[0,0]]"
itemSize="[500,500]"
itemComponentName="BackendTypeRowListCell"
rowFocusAnimationStyle="floatingfocus"
focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png">
<ContentNode role="content">
<ContentNode>
<BackendTypeContentNode id="BackendTypeYouTube" title="YouTube" backendLogoUri="pkg:/images/youtube-logo.png" />
<BackendTypeContentNode id="BackendTypeInvidious" title="Invidious" backendLogoUri="pkg:/images/invidious-logo.png" />
</ContentNode>
</ContentNode>
</RowList>
</Rectangle>
</children>
</component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace BackendTypeSelectionViewUtils

function Open(appController as object) as object
backendTypeSelectionView = CreateObject("roSGNode", "BackendTypeSelectionView")

appController@.PushScreen(backendTypeSelectionView)
backendTypeSelectionView@.BindNode()
return backendTypeSelectionView
end function

end namespace

This file was deleted.

64 changes: 49 additions & 15 deletions playlet-lib/src/components/Screens/ProfileScreen/ProfileScreen.bs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import "pkg:/components/Dialog/DialogUtils.bs"
import "pkg:/components/Navigation/Navigation.bs"
import "pkg:/components/ProfileView/ProfileViewUtils.bs"
import "pkg:/components/Screens/ProfileScreen/BackendTypeSelectionView/BackendTypeSelectionViewUtils.bs"
import "pkg:/components/Screens/ProfileScreen/ProfileView/ProfileViewUtils.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/Types.bs"

Expand Down Expand Up @@ -38,26 +40,58 @@ function OnRowItemSelected() as void
row = m.profileRowList.content.GetChild(0)
selectedProfile = row.GetChild(index)
if selectedProfile.type = "login"
invidiousInstance = m.preferences["invidious.instance"]
if StringUtils.IsNullOrEmpty(invidiousInstance)
DialogUtils.ShowDialogEx({
title: "No Invidious Instance"
message: [
"Playlet built-in backend does not support login yet.",
"Can only login if an Invidious instance is set in the settings."
]
})
#if YT_OAUTH_SUPPORT
backendTypeSelectionView = BackendTypeSelectionViewUtils.Open(m.appController)
backendTypeSelectionView.observeFieldScoped("selectedBackendType", FuncName(OnBackEndSelected))
return
end if
dialog = CreateObject("roSGNode", "LoginDialog")
dialog@.BindNode()
m.top.getScene().dialog = dialog
return
#else
LoginWithInvidious()
return
#end if
end if

ProfileViewUtils.Open(selectedProfile, m.appController)
end function

function OnBackEndSelected(event as object) as void
backendTypeSelectionView = event.GetRoSGNode()
backendTypeSelectionView.unobserveFieldScoped("selectedBackendType")

selectedBackendType = event.getData()
if selectedBackendType = "BackendTypeInvidious"
LoginWithInvidious()
else if selectedBackendType = "BackendTypeYouTube"
LoginWithYouTube()
else
LogError("Unknown backend type:", selectedBackendType)
end if
end function

function LoginWithInvidious() as void
invidiousInstance = m.preferences["invidious.instance"]
if StringUtils.IsNullOrEmpty(invidiousInstance)
DialogUtils.ShowDialogEx({
title: "No Invidious Instance"
message: [
"Playlet built-in backend does not support login yet.",
"Can only login if an Invidious instance is set in the settings."
]
})
return
end if

dialog = CreateObject("roSGNode", "LoginDialog")
dialog@.BindNode()
m.top.getScene().dialog = dialog
end function

function LoginWithYouTube() as void
DialogUtils.ShowDialogEx({
title: "YouTube"
message: ["Not implemented yet."]
})
end function

function OnCurrentProfileChanged() as void
currentProfile = m.profilesService.currentProfile
if currentProfile = invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</interface>

<children>
<ProfileRowList
<RowList
id="ProfileRowList"
translation="[0,160]"
numRows="2"
Expand Down
Binary file added playlet-lib/src/images/invidious-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions playlet-lib/src/images/invidious-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions playlet-lib/src/images/invidious-logo.svg.meta.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
inputHash: '339be7a03116276ba83ce7b1bb905e40',
outputs: [
{
outputFilePath: 'images/invidious-logo.png',
outputHash: '31fcb0fb5d7506ba6e742a31497ca052',
width: 256,
height: 256,
},
],
}
Binary file added playlet-lib/src/images/youtube-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions playlet-lib/src/images/youtube-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions playlet-lib/src/images/youtube-logo.svg.meta.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
inputHash: '38d7d7e95f79456ccb7a29aef004dd73',
outputs: [
{
outputFilePath: 'images/youtube-logo.png',
outputHash: 'a015e471b97c7ffbbd012b4c9b9e0624',
width: 256,
height: 256,
},
],
}
2 changes: 1 addition & 1 deletion playlet-lib/src/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ hidden=1

git_commit_sha=unknown

bs_const=DEBUG=false
bs_const=DEBUG=false;YT_OAUTH_SUPPORT=false

0 comments on commit 3cb3c4b

Please sign in to comment.