Multiple profiles (#312)
* Navbar user profile * profiles stuff * fix profile * Lint fix * Some ui experiments * More ui work * progress * Lint fix * migration, web api, wip * profile view and web app * web app and apis * Invidious and profiles * Lint fix * bug fix * Remove ActionContentNode * Profile icon button, profile color * Lint fix * reset server url * href that doesn't work * remove activate button on active profile * TODO * Fin. * Final touches --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
No files matched your search
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- Support for multiple profiles. You can now use multiple Invidious accounts.
|
||||||
- When a video error dialog shows, a timer with 10 seconds starts to play the next video
|
- When a video error dialog shows, a timer with 10 seconds starts to play the next video
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -322,14 +322,63 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
format: uri
|
format: uri
|
||||||
/invidious/logout:
|
/api/profiles:
|
||||||
get:
|
get:
|
||||||
summary: Logout from Invidious
|
summary: Get profiles
|
||||||
description: Logout from Invidious, and invalidate the token if any.
|
description: Get the logged profiles, and the currently active profile.
|
||||||
operationId: invidiousLogout
|
operationId: getProfiles
|
||||||
responses:
|
responses:
|
||||||
"204":
|
"200":
|
||||||
description: No Content
|
description: OK
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
currentProfile:
|
||||||
|
type: string
|
||||||
|
profiles:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/components/schemas/ProfileObject"
|
||||||
|
delete:
|
||||||
|
summary: Logout from a profile
|
||||||
|
description: Logout from a profile. This will remove the profile from the list of logged profiles.
|
||||||
|
operationId: logoutProfile
|
||||||
|
parameters:
|
||||||
|
- name: id
|
||||||
|
in: query
|
||||||
|
description: The ID of the profile to logout
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
"404":
|
||||||
|
description: Not Found
|
||||||
|
/api/profiles/activate:
|
||||||
|
post:
|
||||||
|
summary: Activate a profile
|
||||||
|
description: Activate a profile. This will set the profile as the active profile.
|
||||||
|
operationId: activateProfile
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
"404":
|
||||||
|
description: Not Found
|
||||||
|
|
||||||
# Roku External Control Protocol (ECP)
|
# Roku External Control Protocol (ECP)
|
||||||
/input/{appId}:
|
/input/{appId}:
|
||||||
@@ -530,14 +579,17 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
auth_url:
|
auth_url:
|
||||||
type: string
|
type: string
|
||||||
logged_in:
|
|
||||||
type: boolean
|
|
||||||
logged_in_instance:
|
|
||||||
type: string
|
|
||||||
logged_in_username:
|
|
||||||
type: string
|
|
||||||
preferences:
|
preferences:
|
||||||
$ref: "#/components/schemas/PreferencesObject"
|
$ref: "#/components/schemas/PreferencesObject"
|
||||||
|
profiles:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
currentProfile:
|
||||||
|
type: string
|
||||||
|
profiles:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/components/schemas/ProfileObject"
|
||||||
PreferencesObject:
|
PreferencesObject:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@@ -560,6 +612,17 @@ components:
|
|||||||
type: boolean
|
type: boolean
|
||||||
sponsorblock.show_notifications:
|
sponsorblock.show_notifications:
|
||||||
type: boolean
|
type: boolean
|
||||||
|
ProfileObject:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
username:
|
||||||
|
type: string
|
||||||
|
serverUrl:
|
||||||
|
type: string
|
||||||
# TODO:P1 add the rest of properties
|
# TODO:P1 add the rest of properties
|
||||||
VideoQueueObject:
|
VideoQueueObject:
|
||||||
type: object
|
type: object
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<component name="ActionContentNode" extends="ContentNode">
|
|
||||||
<interface>
|
|
||||||
<field id="type" type="string" value="action" />
|
|
||||||
<field id="action" type="string" />
|
|
||||||
</interface>
|
|
||||||
</component>
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<component name="ProfileContentNode" extends="ContentNode">
|
||||||
|
<interface>
|
||||||
|
<field id="type" type="string" value="invidious" />
|
||||||
|
<field id="isSelected" type="boolean" alwaysNotify="true" />
|
||||||
|
|
||||||
|
<field id="username" type="string" />
|
||||||
|
<field id="serverUrl" type="string" />
|
||||||
|
<field id="accessToken" type="string" />
|
||||||
|
|
||||||
|
<field id="color" type="color" />
|
||||||
|
</interface>
|
||||||
|
</component>
|
||||||
@@ -42,5 +42,6 @@ function OnUrlSet()
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function OnAuthTokenChange()
|
function OnAuthTokenChange()
|
||||||
|
m.invidious.unobserveFieldScoped("authToken")
|
||||||
Close()
|
Close()
|
||||||
end function
|
end function
|
||||||
@@ -22,8 +22,9 @@
|
|||||||
<AppController id="AppController">
|
<AppController id="AppController">
|
||||||
<Group id="Stack">
|
<Group id="Stack">
|
||||||
<AppRoot id="AppRoot">
|
<AppRoot id="AppRoot">
|
||||||
<NavBar id="NavBar" focusIndex="1">
|
<NavBar id="NavBar" focusIndex="2">
|
||||||
<ContentNode role="items">
|
<ContentNode role="items">
|
||||||
|
<NavBarItem screen="ProfileScreen" text="Profile" icon="pkg:/images/icons/user.png" padding="10" componentName="ProfileIconButton" />
|
||||||
<NavBarItem screen="SearchScreen" text="Search" icon="pkg:/images/icons/search.png" />
|
<NavBarItem screen="SearchScreen" text="Search" icon="pkg:/images/icons/search.png" />
|
||||||
<NavBarItem screen="HomeScreen" text="Home" icon="pkg:/images/icons/home.png" />
|
<NavBarItem screen="HomeScreen" text="Home" icon="pkg:/images/icons/home.png" />
|
||||||
<NavBarItem screen="BookmarksScreen" text="Bookmarks" icon="pkg:/images/icons/star.png" />
|
<NavBarItem screen="BookmarksScreen" text="Bookmarks" icon="pkg:/images/icons/star.png" />
|
||||||
@@ -41,6 +42,7 @@
|
|||||||
<Preferences id="Preferences" />
|
<Preferences id="Preferences" />
|
||||||
<Bookmarks id="Bookmarks" />
|
<Bookmarks id="Bookmarks" />
|
||||||
<SearchHistory id="SearchHistory" />
|
<SearchHistory id="SearchHistory" />
|
||||||
|
<Profiles id="Profiles" />
|
||||||
<Invidious id="Invidious" />
|
<Invidious id="Invidious" />
|
||||||
<PlayletWebServer id="WebServer" port="8888" />
|
<PlayletWebServer id="WebServer" port="8888" />
|
||||||
<DialServer id="DialServer" />
|
<DialServer id="DialServer" />
|
||||||
|
|||||||
@@ -8,8 +8,15 @@
|
|||||||
videoQueue="bind:./VideoQueue">
|
videoQueue="bind:./VideoQueue">
|
||||||
<Group id="Stack">
|
<Group id="Stack">
|
||||||
<AppRoot id="AppRoot">
|
<AppRoot id="AppRoot">
|
||||||
<NavBar id="NavBar" focusIndex="1" appController="bind:/AppController">
|
<NavBar id="NavBar" focusIndex="2" appController="bind:/AppController">
|
||||||
<ContentNode role="items">
|
<ContentNode role="items">
|
||||||
|
<NavBarItem
|
||||||
|
screen="ProfileScreen"
|
||||||
|
text="Profile"
|
||||||
|
icon="pkg:/images/icons/user.png"
|
||||||
|
padding="10"
|
||||||
|
componentName="ProfileIconButton">
|
||||||
|
</NavBarItem>
|
||||||
<NavBarItem
|
<NavBarItem
|
||||||
screen="SearchScreen"
|
screen="SearchScreen"
|
||||||
text="Search"
|
text="Search"
|
||||||
@@ -63,10 +70,14 @@
|
|||||||
<SearchHistory id="SearchHistory"
|
<SearchHistory id="SearchHistory"
|
||||||
preferences="bind:../Preferences" />
|
preferences="bind:../Preferences" />
|
||||||
|
|
||||||
|
<Profiles id="Profiles"
|
||||||
|
invidious="bind:../Invidious" />
|
||||||
|
|
||||||
<Invidious id="Invidious"
|
<Invidious id="Invidious"
|
||||||
webServer="bind:../WebServer"
|
webServer="bind:../WebServer"
|
||||||
applicationInfo="bind:../ApplicationInfo"
|
applicationInfo="bind:../ApplicationInfo"
|
||||||
preferences="bind:../Preferences" />
|
preferences="bind:../Preferences"
|
||||||
|
profiles="bind:../Profiles" />
|
||||||
|
|
||||||
<!-- Tasks -->
|
<!-- Tasks -->
|
||||||
<PlayletWebServer id="WebServer"
|
<PlayletWebServer id="WebServer"
|
||||||
@@ -74,6 +85,7 @@
|
|||||||
appController="bind:/AppController"
|
appController="bind:/AppController"
|
||||||
applicationInfo="bind:../ApplicationInfo"
|
applicationInfo="bind:../ApplicationInfo"
|
||||||
invidious="bind:../Invidious"
|
invidious="bind:../Invidious"
|
||||||
|
profiles="bind:../Profiles"
|
||||||
preferences="bind:../Preferences"
|
preferences="bind:../Preferences"
|
||||||
videoQueue="bind:../VideoQueue"
|
videoQueue="bind:../VideoQueue"
|
||||||
bookmarks="bind:../Bookmarks"
|
bookmarks="bind:../Bookmarks"
|
||||||
|
|||||||
@@ -24,15 +24,20 @@ function InitializeBindings()
|
|||||||
"SearchHistory": {
|
"SearchHistory": {
|
||||||
"preferences": "../Preferences"
|
"preferences": "../Preferences"
|
||||||
},
|
},
|
||||||
|
"Profiles": {
|
||||||
|
"invidious": "../Invidious"
|
||||||
|
},
|
||||||
"Invidious": {
|
"Invidious": {
|
||||||
"webServer": "../WebServer",
|
"webServer": "../WebServer",
|
||||||
"applicationInfo": "../ApplicationInfo",
|
"applicationInfo": "../ApplicationInfo",
|
||||||
"preferences": "../Preferences"
|
"preferences": "../Preferences",
|
||||||
|
"profiles": "../Profiles"
|
||||||
},
|
},
|
||||||
"WebServer": {
|
"WebServer": {
|
||||||
"appController": "/AppController",
|
"appController": "/AppController",
|
||||||
"applicationInfo": "../ApplicationInfo",
|
"applicationInfo": "../ApplicationInfo",
|
||||||
"invidious": "../Invidious",
|
"invidious": "../Invidious",
|
||||||
|
"profiles": "../Profiles",
|
||||||
"preferences": "../Preferences",
|
"preferences": "../Preferences",
|
||||||
"videoQueue": "../VideoQueue",
|
"videoQueue": "../VideoQueue",
|
||||||
"bookmarks": "../Bookmarks",
|
"bookmarks": "../Bookmarks",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import "pkg:/source/utils/MathUtils.bs"
|
|||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
|
||||||
' Based on https://github.com/jellyfin/jellyfin-roku/blob/unstable/components/IconButton.brs
|
' Based on https://github.com/jellyfin/jellyfin-roku/blob/unstable/components/IconButton.brs
|
||||||
function init()
|
function Init()
|
||||||
m.buttonBackground = m.top.findNode("buttonBackground")
|
m.buttonBackground = m.top.findNode("buttonBackground")
|
||||||
m.buttonIcon = m.top.findNode("buttonIcon")
|
m.buttonIcon = m.top.findNode("buttonIcon")
|
||||||
m.buttonText = m.top.findNode("buttonText")
|
m.buttonText = m.top.findNode("buttonText")
|
||||||
@@ -46,7 +46,7 @@ function setIconSize()
|
|||||||
m.buttonIcon.width = iconSize
|
m.buttonIcon.width = iconSize
|
||||||
|
|
||||||
m.buttonIcon.translation = [((width - iconSize) / 2), ((height - iconSize) / 2)]
|
m.buttonIcon.translation = [((width - iconSize) / 2), ((height - iconSize) / 2)]
|
||||||
m.buttonText.translation = [-5, height]
|
m.buttonText.translation = [-5, height + 2]
|
||||||
m.buttonText.width = width + 10
|
m.buttonText.width = width + 10
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -29,15 +29,15 @@ function PopulateButtons() as void
|
|||||||
|
|
||||||
buttons = []
|
buttons = []
|
||||||
for each item in navBarItems
|
for each item in navBarItems
|
||||||
button = CreateObject("roSGNode", "IconButton")
|
button = CreateObject("roSGNode", item.componentName)
|
||||||
button.background = "#242424FF"
|
button.background = "#242424FF"
|
||||||
button.focusBackground = "#FF1C30FF"
|
button.focusBackground = "#FF1C30FF"
|
||||||
button.padding = 20
|
|
||||||
button.height = 50
|
button.height = 50
|
||||||
button.width = 90
|
button.width = 90
|
||||||
|
|
||||||
button.icon = item.icon
|
button.icon = item.icon
|
||||||
button.text = item.text
|
button.text = item.text
|
||||||
|
button.padding = item.padding
|
||||||
|
|
||||||
buttons.push(button)
|
buttons.push(button)
|
||||||
end for
|
end for
|
||||||
|
|||||||
@@ -3,5 +3,7 @@
|
|||||||
<field id="screen" type="string" />
|
<field id="screen" type="string" />
|
||||||
<field id="icon" type="string" />
|
<field id="icon" type="string" />
|
||||||
<field id="text" type="string" />
|
<field id="text" type="string" />
|
||||||
|
<field id="padding" type="integer" value="20" />
|
||||||
|
<field id="componentName" type="string" value="IconButton" />
|
||||||
</interface>
|
</interface>
|
||||||
</component>
|
</component>
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
import "pkg:/source/utils/Logging.bs"
|
||||||
|
import "pkg:/source/utils/MathUtils.bs"
|
||||||
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
|
||||||
|
' TODO:P1 this file is a copy paste of IconButton. It should be refactored.
|
||||||
|
function Init()
|
||||||
|
m.buttonBackground = m.top.findNode("buttonBackground")
|
||||||
|
m.buttonIcon = m.top.findNode("buttonIcon")
|
||||||
|
m.buttonText = m.top.findNode("buttonText")
|
||||||
|
|
||||||
|
m.circlePoster = m.top.findNode("circlePoster")
|
||||||
|
m.circlePosterInner = m.top.findNode("circlePosterInner")
|
||||||
|
m.letterLabel = m.top.findNode("LetterLabel")
|
||||||
|
|
||||||
|
m.top.observeField("background", FuncName(onBackgroundChanged))
|
||||||
|
m.top.observeField("icon", FuncName(onIconChanged))
|
||||||
|
m.top.observeField("text", FuncName(onTextChanged))
|
||||||
|
m.top.observeField("height", FuncName(onHeightChanged))
|
||||||
|
m.top.observeField("width", FuncName(onWidthChanged))
|
||||||
|
m.top.observeField("padding", FuncName(onPaddingChanged))
|
||||||
|
|
||||||
|
profiles = m.top.getScene().findNode("Profiles")
|
||||||
|
if profiles <> invalid
|
||||||
|
m.profiles = profiles
|
||||||
|
profiles.observeField("currentProfile", FuncName(OnCurrentProfile))
|
||||||
|
OnCurrentProfile()
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnFocusChange()
|
||||||
|
if m.top.focus
|
||||||
|
m.buttonBackground.blendColor = m.top.focusBackground
|
||||||
|
else
|
||||||
|
m.buttonBackground.blendColor = m.top.background
|
||||||
|
end if
|
||||||
|
m.buttonBackground.visible = m.top.focus
|
||||||
|
m.buttonText.visible = m.top.focus
|
||||||
|
end function
|
||||||
|
|
||||||
|
function onBackgroundChanged()
|
||||||
|
m.buttonBackground.blendColor = m.top.background
|
||||||
|
end function
|
||||||
|
|
||||||
|
function onIconChanged()
|
||||||
|
m.buttonIcon.uri = m.top.icon
|
||||||
|
end function
|
||||||
|
|
||||||
|
function onTextChanged()
|
||||||
|
m.buttonText.text = m.top.text
|
||||||
|
end function
|
||||||
|
|
||||||
|
function setIconSize()
|
||||||
|
height = m.top.height
|
||||||
|
width = m.top.width
|
||||||
|
if height > 0 and width > 0
|
||||||
|
iconSize = MathUtils.Min(height, width) - m.top.padding
|
||||||
|
m.buttonIcon.height = iconSize
|
||||||
|
m.buttonIcon.width = iconSize
|
||||||
|
|
||||||
|
iconTranslation = [((width - iconSize) / 2), ((height - iconSize) / 2)]
|
||||||
|
m.buttonIcon.translation = iconTranslation
|
||||||
|
m.buttonText.translation = [-5, height + 2]
|
||||||
|
m.buttonText.width = width + 10
|
||||||
|
|
||||||
|
m.circlePoster.width = iconSize
|
||||||
|
m.circlePoster.height = iconSize
|
||||||
|
m.circlePoster.translation = iconTranslation
|
||||||
|
|
||||||
|
m.circlePosterInner.width = iconSize - 4
|
||||||
|
m.circlePosterInner.height = iconSize - 4
|
||||||
|
|
||||||
|
m.letterLabel.width = iconSize - 4
|
||||||
|
m.letterLabel.height = iconSize - 4
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function onHeightChanged()
|
||||||
|
m.buttonBackground.height = m.top.height
|
||||||
|
setIconSize()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function onWidthChanged()
|
||||||
|
m.buttonBackground.width = m.top.width - 10
|
||||||
|
m.buttonBackground.translation = [5, 0]
|
||||||
|
setIconSize()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function onPaddingChanged()
|
||||||
|
setIconSize()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnCurrentProfile() as void
|
||||||
|
currentProfile = m.profiles.currentProfile
|
||||||
|
if currentProfile = invalid
|
||||||
|
m.circlePoster.visible = false
|
||||||
|
m.buttonIcon.visible = true
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
username = currentProfile.username
|
||||||
|
if not StringUtils.IsNullOrEmpty(username)
|
||||||
|
m.LetterLabel.text = UCase(username.Left(1))
|
||||||
|
else
|
||||||
|
m.LetterLabel.text = ""
|
||||||
|
end if
|
||||||
|
m.circlePosterInner.blendColor = currentProfile.color
|
||||||
|
|
||||||
|
m.circlePoster.visible = true
|
||||||
|
m.buttonIcon.visible = false
|
||||||
|
end function
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<component name="ProfileIconButton" extends="Group" includes="Focus">
|
||||||
|
<interface>
|
||||||
|
<field id="background" type="color" value="" />
|
||||||
|
<field id="focusBackground" type="color" value="" />
|
||||||
|
<field id="text" type="string" value="" />
|
||||||
|
<field id="padding" type="integer" value="-1" />
|
||||||
|
<field id="height" type="integer" value="" />
|
||||||
|
<field id="width" type="integer" value="" />
|
||||||
|
<field id="icon" type="string" value="" />
|
||||||
|
</interface>
|
||||||
|
<children>
|
||||||
|
<Poster id="buttonBackground" uri="pkg:/images/white.9.png" visible="false" />
|
||||||
|
<Poster id="buttonIcon" />
|
||||||
|
<Poster
|
||||||
|
id="circlePoster"
|
||||||
|
width="40"
|
||||||
|
height="40"
|
||||||
|
uri="pkg:/images/white-circle.png">
|
||||||
|
<Poster
|
||||||
|
id="circlePosterInner"
|
||||||
|
width="36"
|
||||||
|
height="36"
|
||||||
|
blendColor="#9696c8"
|
||||||
|
uri="pkg:/images/white-circle.png"
|
||||||
|
translation="[2,2]">
|
||||||
|
<Label
|
||||||
|
id="LetterLabel"
|
||||||
|
width="40"
|
||||||
|
height="40"
|
||||||
|
vertAlign="center"
|
||||||
|
horizAlign="center">
|
||||||
|
<Font role="font" uri="font:SystemFontFile" size="24" />
|
||||||
|
</Label>
|
||||||
|
</Poster>
|
||||||
|
</Poster>
|
||||||
|
|
||||||
|
<Label id="buttonText" color="#aaaaaa" font="font:SmallestSystemFont" vertAlign="center" horizAlign="center" visible="false" />
|
||||||
|
</children>
|
||||||
|
|
||||||
|
</component>
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
import "pkg:/components/Navigation/Navigation.bs"
|
||||||
|
import "pkg:/source/utils/DisposableObserve.bs"
|
||||||
|
import "pkg:/source/utils/FocusManagement.bs"
|
||||||
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
|
||||||
|
function Init()
|
||||||
|
m.activateButton = m.top.findNode("activateButton")
|
||||||
|
m.logoutButton = m.top.findNode("logoutButton")
|
||||||
|
m.closeButton = m.top.findNode("closeButton")
|
||||||
|
m.buttonGroup = m.top.findNode("buttonGroup")
|
||||||
|
|
||||||
|
DisposableObserveField(m.activateButton, "buttonSelected", FuncName(Activate))
|
||||||
|
DisposableObserveField(m.logoutButton, "buttonSelected", FuncName(Logout))
|
||||||
|
DisposableObserveField(m.closeButton, "buttonSelected", FuncName(Close))
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnNodeReady()
|
||||||
|
SetNavigation(m.activateButton, "down", m.logoutButton)
|
||||||
|
SetNavigation(m.logoutButton, "down", m.closeButton)
|
||||||
|
SetNavigation(m.closeButton, "up", m.logoutButton)
|
||||||
|
SetNavigation(m.logoutButton, "up", m.activateButton)
|
||||||
|
|
||||||
|
DisposableObserveFieldScoped(m.profiles, "currentProfile", FuncName(OnCunrrentProfileChanged))
|
||||||
|
DisposableObserveFieldScoped(m.profiles, "onProfileLogout", FuncName(OnProfileLogout))
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnContentSet() as void
|
||||||
|
content = m.top.content
|
||||||
|
if content = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.top.circlePosterInnerUri = "pkg:/images/white-circle.png"
|
||||||
|
m.top.circlePosterInnerBlendColor = content.color
|
||||||
|
username = content.username
|
||||||
|
m.top.username = username
|
||||||
|
if not StringUtils.IsNullOrEmpty(username)
|
||||||
|
m.top.letter = UCase(username.Left(1))
|
||||||
|
else
|
||||||
|
m.top.letter = ""
|
||||||
|
end if
|
||||||
|
m.top.serverUrl = content.serverUrl
|
||||||
|
m.top.crownVisible = content.isSelected
|
||||||
|
UpdateActivateButton()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnFocusChange() as void
|
||||||
|
if not m.top.focus
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
if m.activateButton.focusable
|
||||||
|
NodeSetFocus(m.activateButton, true)
|
||||||
|
else
|
||||||
|
NodeSetFocus(m.logoutButton, true)
|
||||||
|
end if
|
||||||
|
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 Activate() as void
|
||||||
|
content = m.top.content
|
||||||
|
if content = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
profile = m.profiles.content.getChild(0).findNode(content.id)
|
||||||
|
if profile = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.top.content = invalid
|
||||||
|
m.profiles@.SetCurrentProfile(profile)
|
||||||
|
Close()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function Logout() as void
|
||||||
|
content = m.top.content
|
||||||
|
if content = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.top.content = invalid
|
||||||
|
m.profiles@.LogoutWithProfile(content)
|
||||||
|
Close()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function Close()
|
||||||
|
m.top.appController@.PopScreen()
|
||||||
|
m.top.dispose = true
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnDispose()
|
||||||
|
DisposeObservers()
|
||||||
|
m.top.content = invalid
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnCunrrentProfileChanged() as void
|
||||||
|
content = m.top.content
|
||||||
|
if content = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
m.top.crownVisible = content.isSelected
|
||||||
|
UpdateActivateButton()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnProfileLogout() as void
|
||||||
|
content = m.top.content
|
||||||
|
if content = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
profile = m.profiles.content.getChild(0).findNode(content.id)
|
||||||
|
if profile = invalid
|
||||||
|
Close()
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function UpdateActivateButton() as void
|
||||||
|
content = m.top.content
|
||||||
|
if content = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
isSelected = content.isSelected
|
||||||
|
if isSelected
|
||||||
|
if m.activateButton.hasFocus()
|
||||||
|
NodeSetFocus(m.logoutButton, true)
|
||||||
|
end if
|
||||||
|
|
||||||
|
parent = m.activateButton.getParent()
|
||||||
|
if parent <> invalid
|
||||||
|
m.buttonGroup.removeChild(m.activateButton)
|
||||||
|
end if
|
||||||
|
m.activateButton.focusable = false
|
||||||
|
else
|
||||||
|
parent = m.activateButton.getParent()
|
||||||
|
if parent = invalid
|
||||||
|
m.buttonGroup.insertChild(m.activateButton, 0)
|
||||||
|
end if
|
||||||
|
m.activateButton.focusable = true
|
||||||
|
end if
|
||||||
|
end function
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
<component name="ProfileView" extends="Group" includes="AutoBind,Focus,Disposable">
|
||||||
|
<interface>
|
||||||
|
<field id="content" type="node" onChange="OnContentSet" />
|
||||||
|
<field id="letter" type="string" alias="LetterLabel.text" />
|
||||||
|
<field id="username" type="string" alias="UsernameLabel.text" />
|
||||||
|
<field id="serverUrl" type="string" alias="ServerLabel.text" />
|
||||||
|
<field id="circlePosterInnerUri" type="uri" alias="circlePosterInner.uri" />
|
||||||
|
<field id="circlePosterInnerBlendColor" type="uri" alias="circlePosterInner.blendColor" />
|
||||||
|
<field id="crownVisible" type="boolean" alias="CrownPoster.visible" />
|
||||||
|
|
||||||
|
<field id="appController" type="node" bind="/AppController" />
|
||||||
|
<field id="profiles" type="node" bind="/Profiles" />
|
||||||
|
</interface>
|
||||||
|
<children>
|
||||||
|
<Rectangle
|
||||||
|
width="1280"
|
||||||
|
height="720"
|
||||||
|
color="#000000"
|
||||||
|
opacity="0.5">
|
||||||
|
</Rectangle>
|
||||||
|
<Rectangle
|
||||||
|
width="720"
|
||||||
|
height="420"
|
||||||
|
translation="[280,150]"
|
||||||
|
color="#242424">
|
||||||
|
|
||||||
|
<Group translation="[100,90]">
|
||||||
|
<Poster
|
||||||
|
id="circlePoster"
|
||||||
|
width="160"
|
||||||
|
height="160"
|
||||||
|
translation="[20,20]"
|
||||||
|
uri="pkg:/images/white-circle.png">
|
||||||
|
<Poster
|
||||||
|
id="circlePosterInner"
|
||||||
|
width="152"
|
||||||
|
height="152"
|
||||||
|
blendColor="#9696c8"
|
||||||
|
uri="pkg:/images/white-circle.png"
|
||||||
|
translation="[4,4]">
|
||||||
|
<Label
|
||||||
|
id="LetterLabel"
|
||||||
|
width="152"
|
||||||
|
height="152"
|
||||||
|
vertAlign="center"
|
||||||
|
horizAlign="center">
|
||||||
|
<Font role="font" uri="font:SystemFontFile" size="120" />
|
||||||
|
</Label>
|
||||||
|
</Poster>
|
||||||
|
<Poster
|
||||||
|
id="CrownPoster"
|
||||||
|
width="60"
|
||||||
|
height="60"
|
||||||
|
translation="[50,-60]"
|
||||||
|
uri="pkg:/images/icons/crown.png"
|
||||||
|
visible="false">
|
||||||
|
</Poster>
|
||||||
|
</Poster>
|
||||||
|
<Label
|
||||||
|
id="UsernameLabel"
|
||||||
|
width="200"
|
||||||
|
horizAlign="center"
|
||||||
|
translation="[0,210]">
|
||||||
|
<Font role="font" uri="font:BoldSystemFontFile" size="26" />
|
||||||
|
</Label>
|
||||||
|
<Label
|
||||||
|
id="ServerLabel"
|
||||||
|
width="400"
|
||||||
|
horizAlign="center"
|
||||||
|
translation="[-100,250]">
|
||||||
|
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||||
|
</Label>
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
<LayoutGroup
|
||||||
|
id="buttonGroup"
|
||||||
|
translation="[420,94]"
|
||||||
|
itemSpacings="[20,20]">
|
||||||
|
<Button
|
||||||
|
id="activateButton"
|
||||||
|
text="Activate"
|
||||||
|
minWidth="200"
|
||||||
|
showFocusFootprint="true" />
|
||||||
|
<Button
|
||||||
|
id="logoutButton"
|
||||||
|
text="Logout"
|
||||||
|
minWidth="200"
|
||||||
|
showFocusFootprint="true" />
|
||||||
|
<Button
|
||||||
|
id="closeButton"
|
||||||
|
text="Close"
|
||||||
|
minWidth="200"
|
||||||
|
showFocusFootprint="true" />
|
||||||
|
</LayoutGroup>
|
||||||
|
</Rectangle>
|
||||||
|
</children>
|
||||||
|
</component>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace ProfileViewUtils
|
||||||
|
|
||||||
|
function Open(profile as object, appController as object)
|
||||||
|
profileView = CreateObject("roSGNode", "ProfileView")
|
||||||
|
|
||||||
|
appController@.PushScreen(profileView)
|
||||||
|
profileView@.BindNode()
|
||||||
|
profileView.content = profile
|
||||||
|
end function
|
||||||
|
|
||||||
|
end namespace
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<component name="ProfileRowList" extends="RowList">
|
||||||
|
</component>
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
|
|
||||||
|
function Init()
|
||||||
|
m.normalFont = m.top.findNode("normalFont")
|
||||||
|
m.boldFont = m.top.findNode("boldFont")
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnContentSet() as void
|
||||||
|
content = m.top.itemContent
|
||||||
|
if content = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
if content.type = "login"
|
||||||
|
m.top.circlePosterInnerUri = "pkg:/images/icons/user-200.png"
|
||||||
|
' bs:disable-next-line LINT3023
|
||||||
|
m.top.circlePosterInnerBlendColor = "#FFFFFFFF"
|
||||||
|
m.top.letter = ""
|
||||||
|
m.top.username = "Login"
|
||||||
|
m.top.serverUrl = ""
|
||||||
|
m.top.crownVisible = false
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.top.circlePosterInnerUri = "pkg:/images/white-circle.png"
|
||||||
|
m.top.circlePosterInnerBlendColor = content.color
|
||||||
|
username = content.username
|
||||||
|
m.top.username = username
|
||||||
|
if not StringUtils.IsNullOrEmpty(username)
|
||||||
|
m.top.letter = UCase(username.Left(1))
|
||||||
|
else
|
||||||
|
m.top.letter = ""
|
||||||
|
end if
|
||||||
|
m.top.serverUrl = content.serverUrl
|
||||||
|
m.top.crownVisible = content.isSelected
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnRowListHasFocus()
|
||||||
|
if not m.top.rowListHasFocus
|
||||||
|
m.top.animate = false
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnItemHasFocus()
|
||||||
|
m.top.animate = (m.top.itemHasFocus or m.top.focusPercent > 0.5) and m.top.rowListHasFocus
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnFocusPercent()
|
||||||
|
if m.top.focusPercent > 0.5 and m.top.rowListHasFocus
|
||||||
|
m.top.animate = true
|
||||||
|
else
|
||||||
|
m.top.animate = false
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnAnimate()
|
||||||
|
animate = m.top.animate
|
||||||
|
m.top.shadowVisible = animate
|
||||||
|
m.top.serverLabelVisible = animate
|
||||||
|
m.top.circlePosterTranslation = [20, 20]
|
||||||
|
if animate
|
||||||
|
m.top.UsernameLabelFont = m.boldFont
|
||||||
|
m.top.animationControl = "start"
|
||||||
|
else
|
||||||
|
m.top.UsernameLabelFont = m.normalFont
|
||||||
|
m.top.animationControl = "stop"
|
||||||
|
end if
|
||||||
|
end function
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
<component name="ProfileRowListCell" extends="Group">
|
||||||
|
<interface>
|
||||||
|
<field id="itemContent" type="node" onChange="OnContentSet" />
|
||||||
|
<field id="letter" type="string" alias="LetterLabel.text" />
|
||||||
|
<field id="username" type="string" alias="UsernameLabel.text" />
|
||||||
|
<field id="serverUrl" type="string" alias="ServerLabel.text" />
|
||||||
|
<field id="circlePosterInnerUri" type="uri" alias="circlePosterInner.uri" />
|
||||||
|
<field id="circlePosterInnerBlendColor" type="uri" alias="circlePosterInner.blendColor" />
|
||||||
|
<field id="UsernameLabelFont" type="boolean" alias="UsernameLabel.font" />
|
||||||
|
<field id="rowListHasFocus" type="boolean" onChange="OnRowListHasFocus" />
|
||||||
|
<field id="itemHasFocus" type="boolean" onChange="OnItemHasFocus" />
|
||||||
|
<field id="focusPercent" type="float" onChange="OnFocusPercent" />
|
||||||
|
<field id="circlePosterTranslation" type="vector2d" alias="circlePoster.translation" />
|
||||||
|
<field id="animate" type="boolean" onChange="OnAnimate" />
|
||||||
|
<field id="animationControl" type="string" alias="floatAnimation.control" />
|
||||||
|
<field id="shadowVisible" type="boolean" alias="shadowPoster.visible" />
|
||||||
|
<field id="crownVisible" type="boolean" alias="CrownPoster.visible" />
|
||||||
|
<field id="serverLabelVisible" type="boolean" alias="ServerLabel.visible" />
|
||||||
|
</interface>
|
||||||
|
<children>
|
||||||
|
<Font id="normalFont" uri="font:SystemFontFile" size="24" />
|
||||||
|
<Font id="boldFont" uri="font:BoldSystemFontFile" size="26" />
|
||||||
|
|
||||||
|
<Group translation="[20,50]">
|
||||||
|
<Group
|
||||||
|
id="shadowScaler"
|
||||||
|
translation="[100,20]">
|
||||||
|
<Group translation="[-100,-20]">
|
||||||
|
<Poster
|
||||||
|
id="shadowPoster"
|
||||||
|
uri="pkg:/images/white-circle.png"
|
||||||
|
blendColor="#000000"
|
||||||
|
width="200"
|
||||||
|
height="40"
|
||||||
|
translation="[0,200]"
|
||||||
|
visible="false">
|
||||||
|
</Poster>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
<Poster
|
||||||
|
id="circlePoster"
|
||||||
|
width="160"
|
||||||
|
height="160"
|
||||||
|
translation="[20,20]"
|
||||||
|
uri="pkg:/images/white-circle.png">
|
||||||
|
<Poster
|
||||||
|
id="circlePosterInner"
|
||||||
|
width="152"
|
||||||
|
height="152"
|
||||||
|
blendColor="#9696c8"
|
||||||
|
uri="pkg:/images/white-circle.png"
|
||||||
|
translation="[4,4]">
|
||||||
|
<Label
|
||||||
|
id="LetterLabel"
|
||||||
|
width="152"
|
||||||
|
height="152"
|
||||||
|
vertAlign="center"
|
||||||
|
horizAlign="center">
|
||||||
|
<Font role="font" uri="font:SystemFontFile" size="120" />
|
||||||
|
</Label>
|
||||||
|
</Poster>
|
||||||
|
<Poster
|
||||||
|
id="CrownPoster"
|
||||||
|
width="60"
|
||||||
|
height="60"
|
||||||
|
translation="[50,-60]"
|
||||||
|
uri="pkg:/images/icons/crown.png"
|
||||||
|
visible="false">
|
||||||
|
</Poster>
|
||||||
|
</Poster>
|
||||||
|
<Label
|
||||||
|
id="UsernameLabel"
|
||||||
|
width="200"
|
||||||
|
horizAlign="center"
|
||||||
|
translation="[0,250]">
|
||||||
|
</Label>
|
||||||
|
<Label
|
||||||
|
id="ServerLabel"
|
||||||
|
width="400"
|
||||||
|
horizAlign="center"
|
||||||
|
translation="[-100,310]"
|
||||||
|
visible="false">
|
||||||
|
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||||
|
</Label>
|
||||||
|
</Group>
|
||||||
|
<Animation
|
||||||
|
id="floatAnimation"
|
||||||
|
repeat="true"
|
||||||
|
duration="4"
|
||||||
|
easeFunction="inOutQuad">
|
||||||
|
<Vector2DFieldInterpolator
|
||||||
|
key="[ 0.0, 0.5, 0.55, 1.0 ]"
|
||||||
|
keyValue="[ [20,40], [20,10], [20,10], [20,40]]"
|
||||||
|
fieldToInterp="circlePoster.translation" />
|
||||||
|
<Vector2DFieldInterpolator
|
||||||
|
key="[ 0.0, 0.5, 0.55, 1.0 ]"
|
||||||
|
keyValue="[ [0.7,1], [1.05,1],[1.05,1] , [0.7,1] ]"
|
||||||
|
fieldToInterp="shadowScaler.scale" />
|
||||||
|
<FloatFieldInterpolator
|
||||||
|
key="[ 0.0, 0.5, 0.55, 1.0 ]"
|
||||||
|
keyValue="[0.3, 0.05 ,0.05, 0.3 ]"
|
||||||
|
fieldToInterp="shadowPoster.opacity" />
|
||||||
|
</Animation>
|
||||||
|
</children>
|
||||||
|
</component>
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||||
|
import "pkg:/components/Navigation/Navigation.bs"
|
||||||
|
import "pkg:/components/ProfileView/ProfileViewUtils.bs"
|
||||||
|
import "pkg:/source/utils/FocusManagement.bs"
|
||||||
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
|
||||||
|
function Init()
|
||||||
|
m.top.focusable = true
|
||||||
|
m.profileRowList = m.top.FindNode("ProfileRowList")
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnNodeReady()
|
||||||
|
SetNavigation(invalid, "back", m.navBar)
|
||||||
|
SetNavigation(invalid, "left", m.navBar)
|
||||||
|
|
||||||
|
m.profileRowList.content = m.profiles.content
|
||||||
|
m.profileRowList.observeFieldScoped("rowItemSelected", FuncName(OnRowItemSelected))
|
||||||
|
m.profiles.observeFieldScoped("currentProfile", FuncName(OnCurrentProfileChanged))
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnFocusChange() as void
|
||||||
|
if not m.top.focus
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
NodeSetFocus(m.profileRowList, true)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||||
|
if NavigationKeyHandler(key, press).handled
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
return false
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnRowItemSelected() as void
|
||||||
|
index = m.profileRowList.rowItemSelected[1]
|
||||||
|
row = m.profileRowList.content.GetChild(0)
|
||||||
|
selectedProfile = row.GetChild(index)
|
||||||
|
if selectedProfile.type = "login"
|
||||||
|
dialog = CreateObject("roSGNode", "LoginDialog")
|
||||||
|
dialog@.BindNode()
|
||||||
|
m.top.getScene().dialog = dialog
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
ProfileViewUtils.Open(selectedProfile, m.appController)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnCurrentProfileChanged() as void
|
||||||
|
currentProfile = m.profiles.currentProfile
|
||||||
|
if currentProfile = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
row = m.profileRowList.content.GetChild(0)
|
||||||
|
allProfiles = row.getChildren(-1, 0)
|
||||||
|
for i = 0 to allProfiles.Count() - 1
|
||||||
|
if currentProfile.id = allProfiles[i].id
|
||||||
|
m.profileRowList.jumpToRowItem = [0, i]
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
end function
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<component name="ProfileScreen" extends="Group" includes="AutoBind,Focus">
|
||||||
|
<interface>
|
||||||
|
<field id="navBar" type="node" bind="/NavBar" />
|
||||||
|
<field id="profiles" type="node" bind="/Profiles" />
|
||||||
|
<field id="appController" type="node" bind="/AppController" />
|
||||||
|
</interface>
|
||||||
|
|
||||||
|
<children>
|
||||||
|
<ProfileRowList
|
||||||
|
id="ProfileRowList"
|
||||||
|
translation="[0,160]"
|
||||||
|
numRows="2"
|
||||||
|
rowitemSize="[[240,340]]"
|
||||||
|
rowItemSpacing="[[0,0]]"
|
||||||
|
itemSize="[1280,500]"
|
||||||
|
focusXOffset="[200]"
|
||||||
|
itemComponentName="ProfileRowListCell"
|
||||||
|
rowFocusAnimationStyle="floatingfocus"
|
||||||
|
focusBitmapUri="pkg:/images/focus-glow-padding-19.9.png" />
|
||||||
|
</children>
|
||||||
|
</component>
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import "pkg:/source/QrCode/QrImage.bs"
|
import "pkg:/source/QrCode/QrImage.bs"
|
||||||
import "pkg:/source/utils/StringUtils.bs"
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
|
|
||||||
|
' TODO:P1 create a QRCode component that has a loading spinner while the QRCode is being generated
|
||||||
|
' It is slow and can take several seconds.
|
||||||
@asynctask
|
@asynctask
|
||||||
function GenerateQrCodeTask(input as object)
|
function GenerateQrCodeTask(input as object)
|
||||||
poster = input.poster
|
poster = input.poster
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import "pkg:/source/AsyncTask/Tasks.bs"
|
|||||||
function Init()
|
function Init()
|
||||||
m.top.apiDefinitions = ParseJson(ReadAsciiFile("libpkg:/config/invidious_video_api.yaml"))
|
m.top.apiDefinitions = ParseJson(ReadAsciiFile("libpkg:/config/invidious_video_api.yaml"))
|
||||||
m.service = new Invidious.InvidiousService(m.top)
|
m.service = new Invidious.InvidiousService(m.top)
|
||||||
m.top.authToken = m.service.GetAuthToken()
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetCurrentInstance(_unused as dynamic) as string
|
function GetCurrentInstance(_unused as dynamic) as string
|
||||||
@@ -16,10 +15,6 @@ function GetAuthorizeTokenLink(_unused as dynamic) as dynamic
|
|||||||
return m.service.GetAuthorizeTokenLink()
|
return m.service.GetAuthorizeTokenLink()
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function SetAuthToken(token as string, instance as string, username as dynamic)
|
|
||||||
m.service.SetAuthToken(token, instance, username)
|
|
||||||
end function
|
|
||||||
|
|
||||||
function OnAuthTokenChange() as void
|
function OnAuthTokenChange() as void
|
||||||
m.top.refreshSubscribtions = true
|
m.top.refreshSubscribtions = true
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
<field id="applicationInfo" type="node" />
|
<field id="applicationInfo" type="node" />
|
||||||
<field id="preferences" type="node" />
|
<field id="preferences" type="node" />
|
||||||
<field id="webServer" type="node" />
|
<field id="webServer" type="node" />
|
||||||
|
<field id="profiles" type="node" />
|
||||||
|
|
||||||
<field id="authToken" type="assocarray" onChange="OnAuthTokenChange" />
|
<field id="authToken" type="assocarray" onChange="OnAuthTokenChange" />
|
||||||
<field id="apiDefinitions" type="assocarray" />
|
<field id="apiDefinitions" type="assocarray" />
|
||||||
@@ -11,6 +12,5 @@
|
|||||||
|
|
||||||
<function name="GetCurrentInstance" />
|
<function name="GetCurrentInstance" />
|
||||||
<function name="GetAuthorizeTokenLink" />
|
<function name="GetAuthorizeTokenLink" />
|
||||||
<function name="SetAuthToken" />
|
|
||||||
</interface>
|
</interface>
|
||||||
</component>
|
</component>
|
||||||
@@ -37,15 +37,15 @@ namespace Invidious
|
|||||||
const ERROR_NOT_AUTHENTICATED = "Not authenticated"
|
const ERROR_NOT_AUTHENTICATED = "Not authenticated"
|
||||||
|
|
||||||
class InvidiousService
|
class InvidiousService
|
||||||
public node as object
|
public invidiousNode as object
|
||||||
|
|
||||||
function new(node as object)
|
function new(invidiousNode as object)
|
||||||
m.node = node
|
m.invidiousNode = invidiousNode
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetUserRegion() as string
|
function GetUserRegion() as string
|
||||||
if m._userRegion = invalid
|
if m._userRegion = invalid
|
||||||
m._userRegion = m.node.applicationInfo@.GetUserCountryCode()
|
m._userRegion = m.invidiousNode.applicationInfo@.GetUserCountryCode()
|
||||||
end if
|
end if
|
||||||
return m._userRegion
|
return m._userRegion
|
||||||
end function
|
end function
|
||||||
@@ -58,7 +58,7 @@ namespace Invidious
|
|||||||
|
|
||||||
function GetInstance() as string
|
function GetInstance() as string
|
||||||
if m.preferences = invalid
|
if m.preferences = invalid
|
||||||
m.preferences = m.node.preferences
|
m.preferences = m.invidiousNode.preferences
|
||||||
end if
|
end if
|
||||||
instance = m.preferences["invidious.instance"]
|
instance = m.preferences["invidious.instance"]
|
||||||
if not StringUtils.IsNullOrEmpty(instance)
|
if not StringUtils.IsNullOrEmpty(instance)
|
||||||
@@ -73,7 +73,7 @@ namespace Invidious
|
|||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
authToken = m.node.authToken
|
authToken = m.invidiousNode.authToken
|
||||||
if authToken = invalid
|
if authToken = invalid
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
@@ -149,7 +149,7 @@ namespace Invidious
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function GetPlaylist(playlistId as string, index = 0 as integer, cancellation = invalid as object) as object
|
function GetPlaylist(playlistId as string, index = 0 as integer, cancellation = invalid as object) as object
|
||||||
authToken = m.node.authToken
|
authToken = m.invidiousNode.authToken
|
||||||
if authToken = invalid
|
if authToken = invalid
|
||||||
instance = m.GetInstance()
|
instance = m.GetInstance()
|
||||||
url = `${instance}${Invidious.PLAYLISTS_ENDPOINT}/${playlistId}`
|
url = `${instance}${Invidious.PLAYLISTS_ENDPOINT}/${playlistId}`
|
||||||
@@ -194,7 +194,7 @@ namespace Invidious
|
|||||||
feedSource = feedSources[feedSourcesIndex]
|
feedSource = feedSources[feedSourcesIndex]
|
||||||
|
|
||||||
if m.endpoints = invalid
|
if m.endpoints = invalid
|
||||||
m.endpoints = m.node.apiDefinitions
|
m.endpoints = m.invidiousNode.apiDefinitions
|
||||||
end if
|
end if
|
||||||
|
|
||||||
endpoint = m.endpoints[feedSource.endpoint]
|
endpoint = m.endpoints[feedSource.endpoint]
|
||||||
@@ -231,7 +231,7 @@ namespace Invidious
|
|||||||
|
|
||||||
function MakeRequest(feedSource as object, additionalQueryParams = invalid as object, cancellation = invalid as object) as object
|
function MakeRequest(feedSource as object, additionalQueryParams = invalid as object, cancellation = invalid as object) as object
|
||||||
if m.endpoints = invalid
|
if m.endpoints = invalid
|
||||||
m.endpoints = m.node.apiDefinitions
|
m.endpoints = m.invidiousNode.apiDefinitions
|
||||||
end if
|
end if
|
||||||
|
|
||||||
endpoint = m.endpoints[feedSource.endpoint]
|
endpoint = m.endpoints[feedSource.endpoint]
|
||||||
@@ -246,8 +246,10 @@ namespace Invidious
|
|||||||
|
|
||||||
request = HttpClient.Get(instance + endpoint.url)
|
request = HttpClient.Get(instance + endpoint.url)
|
||||||
|
|
||||||
|
authToken = invalid
|
||||||
|
|
||||||
if endpoint.authenticated = true
|
if endpoint.authenticated = true
|
||||||
authToken = m.node.authToken
|
authToken = m.invidiousNode.authToken
|
||||||
if authToken = invalid
|
if authToken = invalid
|
||||||
return {
|
return {
|
||||||
success: false
|
success: false
|
||||||
@@ -264,7 +266,7 @@ namespace Invidious
|
|||||||
if queryParam.default <> invalid
|
if queryParam.default <> invalid
|
||||||
if IsString(queryParam.type) and queryParam.type = "#ISO3166"
|
if IsString(queryParam.type) and queryParam.type = "#ISO3166"
|
||||||
if queryParam.default = "GetUserCountryCode"
|
if queryParam.default = "GetUserCountryCode"
|
||||||
request.QueryParam(queryParamKey, m.node.applicationInfo@.GetUserCountryCode())
|
request.QueryParam(queryParamKey, m.GetUserRegion())
|
||||||
else
|
else
|
||||||
request.QueryParam(queryParamKey, queryParam.default)
|
request.QueryParam(queryParamKey, queryParam.default)
|
||||||
end if
|
end if
|
||||||
@@ -305,23 +307,18 @@ namespace Invidious
|
|||||||
|
|
||||||
response = request.Await()
|
response = request.Await()
|
||||||
|
|
||||||
if m.responseHandlers = invalid
|
responseHandler = invalid
|
||||||
m.responseHandlers = {
|
if IsString(endpoint.responseHandler) and m.DoesExist(endpoint.responseHandler)
|
||||||
DefaultHandler: m.DefaultHandler
|
responseHandler = endpoint.responseHandler
|
||||||
AuthFeedHandler: m.AuthFeedHandler
|
else
|
||||||
PlaylistHandler: m.PlaylistHandler
|
responseHandler = "DefaultHandler"
|
||||||
VideoInfoHandler: m.VideoInfoHandler
|
|
||||||
PlaylistInfoHandler: m.PlaylistInfoHandler
|
|
||||||
ChannelInfoHandler: m.ChannelInfoHandler
|
|
||||||
ChannelVideosHandler: m.ChannelVideosHandler
|
|
||||||
ChannelPlaylistsHandler: m.ChannelPlaylistsHandler
|
|
||||||
WatchHistoryHandler: m.WatchHistoryHandler
|
|
||||||
}
|
|
||||||
end if
|
end if
|
||||||
|
|
||||||
responseHandler = endpoint.responseHandler <> invalid ? m.responseHandlers[endpoint.responseHandler] : m.responseHandlers["DefaultHandler"]
|
result = m[responseHandler]({
|
||||||
|
feedSource: feedSource
|
||||||
result = responseHandler(m, feedSource, response)
|
response: response
|
||||||
|
authToken: authToken
|
||||||
|
})
|
||||||
|
|
||||||
if response.IsSuccess() and result <> invalid
|
if response.IsSuccess() and result <> invalid
|
||||||
return {
|
return {
|
||||||
@@ -336,7 +333,9 @@ namespace Invidious
|
|||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function DefaultHandler(m as object, feedSource as object, response as object) as object
|
function DefaultHandler(context as object) as object
|
||||||
|
response = context.response
|
||||||
|
|
||||||
if response.StatusCode() = 200
|
if response.StatusCode() = 200
|
||||||
json = response.Json()
|
json = response.Json()
|
||||||
return {
|
return {
|
||||||
@@ -346,7 +345,9 @@ namespace Invidious
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function PlaylistHandler(m as object, feedSource as object, response as object) as object
|
function PlaylistHandler(context as object) as object
|
||||||
|
response = context.response
|
||||||
|
|
||||||
if response.StatusCode() = 200
|
if response.StatusCode() = 200
|
||||||
json = response.Json()
|
json = response.Json()
|
||||||
return {
|
return {
|
||||||
@@ -356,7 +357,9 @@ namespace Invidious
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function ChannelVideosHandler(m as object, feedSource as object, response as object) as object
|
function ChannelVideosHandler(context as object) as object
|
||||||
|
response = context.response
|
||||||
|
|
||||||
if response.StatusCode() = 200
|
if response.StatusCode() = 200
|
||||||
json = response.Json()
|
json = response.Json()
|
||||||
return {
|
return {
|
||||||
@@ -367,7 +370,9 @@ namespace Invidious
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function ChannelPlaylistsHandler(m as object, feedSource as object, response as object) as object
|
function ChannelPlaylistsHandler(context as object) as object
|
||||||
|
response = context.response
|
||||||
|
|
||||||
if response.StatusCode() = 200
|
if response.StatusCode() = 200
|
||||||
json = response.Json()
|
json = response.Json()
|
||||||
return {
|
return {
|
||||||
@@ -378,7 +383,10 @@ namespace Invidious
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function VideoInfoHandler(m as object, feedSource as object, response as object) as object
|
function VideoInfoHandler(context as object) as object
|
||||||
|
response = context.response
|
||||||
|
feedSource = context.feedSource
|
||||||
|
|
||||||
statusCode = response.StatusCode()
|
statusCode = response.StatusCode()
|
||||||
if statusCode >= 500
|
if statusCode >= 500
|
||||||
' In some cases, such as a video became private, or a live stream ended,
|
' In some cases, such as a video became private, or a live stream ended,
|
||||||
@@ -406,7 +414,9 @@ namespace Invidious
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function PlaylistInfoHandler(m as object, feedSource as object, response as object) as object
|
function PlaylistInfoHandler(context as object) as object
|
||||||
|
response = context.response
|
||||||
|
|
||||||
if response.StatusCode() = 200
|
if response.StatusCode() = 200
|
||||||
json = response.Json()
|
json = response.Json()
|
||||||
json.type = "playlist"
|
json.type = "playlist"
|
||||||
@@ -417,7 +427,9 @@ namespace Invidious
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function ChannelInfoHandler(m as object, feedSource as object, response as object) as object
|
function ChannelInfoHandler(context as object) as object
|
||||||
|
response = context.response
|
||||||
|
|
||||||
if response.StatusCode() = 200
|
if response.StatusCode() = 200
|
||||||
json = response.Json()
|
json = response.Json()
|
||||||
json.type = "channel"
|
json.type = "channel"
|
||||||
@@ -428,8 +440,11 @@ namespace Invidious
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function AuthFeedHandler(m as object, feedSource as object, response as object) as object
|
function AuthFeedHandler(context as object) as object
|
||||||
m.DeleteExpiredToken(response)
|
response = context.response
|
||||||
|
authToken = context.authToken
|
||||||
|
|
||||||
|
m.DeleteExpiredToken(response, authToken)
|
||||||
|
|
||||||
if response.StatusCode() <> 200
|
if response.StatusCode() <> 200
|
||||||
return invalid
|
return invalid
|
||||||
@@ -455,8 +470,11 @@ namespace Invidious
|
|||||||
}
|
}
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function WatchHistoryHandler(m as object, feedSource as object, response as object) as object
|
function WatchHistoryHandler(context as object) as object
|
||||||
m.DeleteExpiredToken(response)
|
response = context.response
|
||||||
|
authToken = context.authToken
|
||||||
|
|
||||||
|
m.DeleteExpiredToken(response, authToken)
|
||||||
|
|
||||||
if response.StatusCode() <> 200
|
if response.StatusCode() <> 200
|
||||||
return invalid
|
return invalid
|
||||||
@@ -480,53 +498,19 @@ namespace Invidious
|
|||||||
}
|
}
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function DeleteExpiredToken(response as object)
|
function DeleteExpiredToken(response as object, authToken as object) as void
|
||||||
if response.StatusCode() = 403
|
if response.StatusCode() <> 403
|
||||||
LogWarn(`Invidious instance responded with 403: ${response.Text()}`)
|
return
|
||||||
LogWarn("Deleting Invidious token...")
|
|
||||||
m.DeleteAuthToken()
|
|
||||||
end if
|
end if
|
||||||
end function
|
|
||||||
|
|
||||||
function GetAuthToken() as object
|
LogWarn(`Invidious instance responded with 403: ${response.Text()}`)
|
||||||
tokenPayload = RegistryUtils.Read(RegistryUtils.INVIDIOUS_TOKEN)
|
if not IsAssociativeArray(authToken) or not IsString(authToken.token)
|
||||||
if tokenPayload = invalid
|
LogWarn("No valid token to delete")
|
||||||
return invalid
|
return
|
||||||
end if
|
end if
|
||||||
authToken = ParseJson(tokenPayload)
|
|
||||||
if authToken = invalid or authToken.instance = invalid or authToken.token = invalid
|
|
||||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
|
||||||
return invalid
|
|
||||||
end if
|
|
||||||
if not m.VerifyTokenScope(authToken.token)
|
|
||||||
' Right now we're probably in a UI thread, and we can't unregister the token
|
|
||||||
' Without a Task
|
|
||||||
AsyncTask.Start(Tasks.InvidiousUnregisterTokenTask, {
|
|
||||||
invidious: m.node
|
|
||||||
authToken: authToken
|
|
||||||
})
|
|
||||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
|
||||||
message = `It looks like you are logged in to Invidious, but your access token does not have the required permissions.
|
|
||||||
For that reason, we have logged you out. Please log in again.
|
|
||||||
This can happen when Playlet is updated with new features.
|
|
||||||
We apologize for the inconvenience.`
|
|
||||||
DialogUtils.ShowDialog(message, "User logged out")
|
|
||||||
return invalid
|
|
||||||
end if
|
|
||||||
return authToken
|
|
||||||
end function
|
|
||||||
|
|
||||||
function SetAuthToken(token as string, instance as string, username as dynamic)
|
LogInfo("Deleting Invidious token...")
|
||||||
obj = {
|
m.invidiousNode.profiles@.LogoutWithAccessToken(authToken.token)
|
||||||
token: token
|
|
||||||
instance: instance
|
|
||||||
username: username
|
|
||||||
}
|
|
||||||
|
|
||||||
json = FormatJson(obj)
|
|
||||||
RegistryUtils.Write(RegistryUtils.INVIDIOUS_TOKEN, json)
|
|
||||||
|
|
||||||
m.node.authToken = obj
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function VerifyTokenScope(token as string) as boolean
|
function VerifyTokenScope(token as string) as boolean
|
||||||
@@ -550,30 +534,14 @@ We apologize for the inconvenience.`
|
|||||||
return validScopes
|
return validScopes
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function DeleteAuthToken()
|
function UnregisterToken(authToken as object) as object
|
||||||
m.node.authToken = invalid
|
|
||||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
|
||||||
end function
|
|
||||||
|
|
||||||
function Logout() as boolean
|
|
||||||
authToken = m.node.authToken
|
|
||||||
if authToken = invalid
|
|
||||||
return false
|
|
||||||
end if
|
|
||||||
|
|
||||||
m.UnregisterToken(authToken)
|
|
||||||
m.DeleteAuthToken()
|
|
||||||
return true
|
|
||||||
end function
|
|
||||||
|
|
||||||
function UnregisterToken(authToken as object) as void
|
|
||||||
url = `${authToken.instance}${Invidious.AUTH_TOKENS_UNREGISTER}`
|
url = `${authToken.instance}${Invidious.AUTH_TOKENS_UNREGISTER}`
|
||||||
|
|
||||||
request = HttpClient.Post(url, authToken.token)
|
request = HttpClient.Post(url, authToken.token)
|
||||||
request.Headers(m.GetAuthenticationHeaders(authToken.token))
|
request.Headers(m.GetAuthenticationHeaders(authToken.token))
|
||||||
request.Header("Content-Type", "application/json")
|
request.Header("Content-Type", "application/json")
|
||||||
|
|
||||||
request.Await()
|
return request.Await()
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetAuthorizeTokenLink() as dynamic
|
function GetAuthorizeTokenLink() as dynamic
|
||||||
@@ -581,7 +549,7 @@ We apologize for the inconvenience.`
|
|||||||
' Make sure the host is not on https, because https cannot redirect to http, which is our local server
|
' Make sure the host is not on https, because https cannot redirect to http, which is our local server
|
||||||
invidiousHost = instance.Replace("https://", "http://")
|
invidiousHost = instance.Replace("https://", "http://")
|
||||||
|
|
||||||
address = m.node.webServer@.GetServerAddress()
|
address = m.invidiousNode.webServer@.GetServerAddress()
|
||||||
if address = invalid
|
if address = invalid
|
||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
@@ -594,7 +562,7 @@ We apologize for the inconvenience.`
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function GetSubscriptions(cancellation = invalid as object) as object
|
function GetSubscriptions(cancellation = invalid as object) as object
|
||||||
authToken = m.node.authToken
|
authToken = m.invidiousNode.authToken
|
||||||
if authToken = invalid
|
if authToken = invalid
|
||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
@@ -608,7 +576,7 @@ We apologize for the inconvenience.`
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function Subscribe(channelId as string, cancellation = invalid as object) as object
|
function Subscribe(channelId as string, cancellation = invalid as object) as object
|
||||||
authToken = m.node.authToken
|
authToken = m.invidiousNode.authToken
|
||||||
if authToken = invalid
|
if authToken = invalid
|
||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
@@ -622,7 +590,7 @@ We apologize for the inconvenience.`
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function Unsubscribe(channelId as string, cancellation = invalid as object) as object
|
function Unsubscribe(channelId as string, cancellation = invalid as object) as object
|
||||||
authToken = m.node.authToken
|
authToken = m.invidiousNode.authToken
|
||||||
if authToken = invalid
|
if authToken = invalid
|
||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
import "InvidiousService.bs"
|
|
||||||
|
|
||||||
@asynctask
|
|
||||||
function InvidiousUnregisterTokenTask(input as object) as object
|
|
||||||
invidiousNode = input.invidious
|
|
||||||
authToken = input.authToken
|
|
||||||
|
|
||||||
service = new Invidious.InvidiousService(invidiousNode)
|
|
||||||
service.UnregisterToken(authToken)
|
|
||||||
|
|
||||||
return invalid
|
|
||||||
end function
|
|
||||||
@@ -0,0 +1,331 @@
|
|||||||
|
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
||||||
|
import "pkg:/source/AsyncTask/Tasks.bs"
|
||||||
|
import "pkg:/source/utils/ArrayUtils.bs"
|
||||||
|
import "pkg:/source/utils/ColorUtils.bs"
|
||||||
|
import "pkg:/source/utils/CryptoUtils.bs"
|
||||||
|
import "pkg:/source/utils/Logging.bs"
|
||||||
|
import "pkg:/source/utils/RegistryUtils.bs"
|
||||||
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
|
|
||||||
|
' TODO:P1 add the ability to change color of profiles
|
||||||
|
function Init()
|
||||||
|
m.disableSavingToRegistry = false
|
||||||
|
content = m.top.findNode("ProfilesContent")
|
||||||
|
m.top.content = content
|
||||||
|
m.profilesContent = content.getChild(0)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnNodeReady()
|
||||||
|
LoadProfilesFromRegistry()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function LoadProfilesFromRegistry()
|
||||||
|
LogInfo("Loading profiles from registry...")
|
||||||
|
|
||||||
|
' Step 1: Load user profiles from registry
|
||||||
|
userProfiles = RegistryUtils.Read(RegistryUtils.USER_PROFILES)
|
||||||
|
|
||||||
|
if userProfiles = invalid
|
||||||
|
userProfiles = {
|
||||||
|
profiles: []
|
||||||
|
currentProfile: invalid
|
||||||
|
}
|
||||||
|
else
|
||||||
|
userProfiles = ParseJson(userProfiles)
|
||||||
|
end if
|
||||||
|
|
||||||
|
' Step 2: Migrate existing profiles to new format (if needed)
|
||||||
|
isDirty = MigrateExistingProfiles(userProfiles)
|
||||||
|
|
||||||
|
' Step 3: Save user preferences (if needed)
|
||||||
|
if isDirty
|
||||||
|
SaveUserProfilesToRegistry()
|
||||||
|
end if
|
||||||
|
|
||||||
|
' Step 4: Load user profiles into content nodes
|
||||||
|
profileNodes = []
|
||||||
|
for each profile in userProfiles.profiles
|
||||||
|
profileNode = CreateObject("roSGNode", "ProfileContentNode")
|
||||||
|
profileNode.id = profile.id
|
||||||
|
profileNode.type = profile.type
|
||||||
|
profileNode.username = profile.username
|
||||||
|
profileNode.serverUrl = profile.serverUrl
|
||||||
|
profileNode.accessToken = profile.accessToken
|
||||||
|
profileNode.color = profile.color
|
||||||
|
|
||||||
|
profileNodes.Push(profileNode)
|
||||||
|
end for
|
||||||
|
|
||||||
|
m.profilesContent.insertChildren(profileNodes, 0)
|
||||||
|
|
||||||
|
if not StringUtils.IsNullOrEmpty(userProfiles.currentProfile)
|
||||||
|
for each profileNode in profileNodes
|
||||||
|
if profileNode.id = userProfiles.currentProfile
|
||||||
|
' Setting current profile will also save the profiles to registry
|
||||||
|
' but we just saved the profiles
|
||||||
|
m.disableSavingToRegistry = true
|
||||||
|
SetCurrentProfile(profileNode)
|
||||||
|
m.disableSavingToRegistry = false
|
||||||
|
exit for
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
end if
|
||||||
|
|
||||||
|
if profileNodes.Count() > 0
|
||||||
|
AsyncTask.Start(Tasks.ProfilesVerifyTokensTask, {
|
||||||
|
profiles: m.top
|
||||||
|
invidious: m.invidious
|
||||||
|
profileNodes: profileNodes
|
||||||
|
})
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function MigrateExistingProfiles(userProfiles as object) as boolean
|
||||||
|
tokenPayload = RegistryUtils.Read(RegistryUtils.INVIDIOUS_TOKEN)
|
||||||
|
if tokenPayload = invalid
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
|
||||||
|
authToken = ParseJson(tokenPayload)
|
||||||
|
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||||
|
|
||||||
|
if authToken = invalid or authToken.instance = invalid or authToken.token = invalid or authToken.username = invalid
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
|
||||||
|
id = CreateProfileId(authToken.username, authToken.instance)
|
||||||
|
for each profile in userProfiles.profiles
|
||||||
|
if profile.id = id
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
|
||||||
|
profile = {
|
||||||
|
"id": id
|
||||||
|
"type": "invidious"
|
||||||
|
"username": authToken.username
|
||||||
|
"serverUrl": authToken.instance
|
||||||
|
"accessToken": authToken.token
|
||||||
|
"color": ColorUtils.RandomSoftColorHex()
|
||||||
|
}
|
||||||
|
|
||||||
|
userProfiles.profiles.Unshift(profile)
|
||||||
|
if StringUtils.IsNullOrEmpty(userProfiles["currentProfile"])
|
||||||
|
userProfiles["currentProfile"] = profile.id
|
||||||
|
end if
|
||||||
|
|
||||||
|
return true
|
||||||
|
end function
|
||||||
|
|
||||||
|
function SaveUserProfilesToRegistry() as void
|
||||||
|
if m.disableSavingToRegistry
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
userProfiles = GetProfilesDto(true)
|
||||||
|
|
||||||
|
userProfiles.__version = m.top.__version
|
||||||
|
RegistryUtils.Write(RegistryUtils.USER_PROFILES, FormatJson(userProfiles))
|
||||||
|
end function
|
||||||
|
|
||||||
|
function GetProfilesDto(includeAccessToken as boolean) as object
|
||||||
|
userProfiles = {
|
||||||
|
"profiles": []
|
||||||
|
"currentProfile": invalid
|
||||||
|
}
|
||||||
|
|
||||||
|
profileNodes = m.profilesContent.getChildren(-1, 0)
|
||||||
|
|
||||||
|
for each profileNode in profileNodes
|
||||||
|
if profileNode.type = "login"
|
||||||
|
continue for
|
||||||
|
end if
|
||||||
|
|
||||||
|
color = profileNode.color
|
||||||
|
if IsInt(color)
|
||||||
|
' Use hex color for web app
|
||||||
|
color = ColorUtils.IntToHex(color)
|
||||||
|
end if
|
||||||
|
|
||||||
|
profile = {
|
||||||
|
"id": profileNode.id
|
||||||
|
"type": profileNode.type
|
||||||
|
"username": profileNode.username
|
||||||
|
"serverUrl": profileNode.serverUrl
|
||||||
|
"color": color
|
||||||
|
}
|
||||||
|
|
||||||
|
if includeAccessToken
|
||||||
|
profile["accessToken"] = profileNode.accessToken
|
||||||
|
end if
|
||||||
|
|
||||||
|
userProfiles.profiles.Push(profile)
|
||||||
|
end for
|
||||||
|
|
||||||
|
currentProfile = m.top.currentProfile
|
||||||
|
if currentProfile <> invalid
|
||||||
|
userProfiles["currentProfile"] = currentProfile.id
|
||||||
|
end if
|
||||||
|
|
||||||
|
return userProfiles
|
||||||
|
end function
|
||||||
|
|
||||||
|
function LoginWithProfile(newProfile as object)
|
||||||
|
isNewProfile = true
|
||||||
|
if StringUtils.IsNullOrEmpty(newProfile.id)
|
||||||
|
newProfile.id = CreateProfileId(newProfile.username, newProfile.serverUrl)
|
||||||
|
end if
|
||||||
|
|
||||||
|
existingProfile = invalid
|
||||||
|
profiles = m.profilesContent.getChildren(-1, 0)
|
||||||
|
for each profile in profiles
|
||||||
|
if profile.id = newProfile.id
|
||||||
|
existingProfile = profile
|
||||||
|
isNewProfile = false
|
||||||
|
exit for
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
|
||||||
|
if not isNewProfile
|
||||||
|
' Refresh token of existing profile
|
||||||
|
existingProfile.accessToken = newProfile.accessToken
|
||||||
|
newProfile = existingProfile
|
||||||
|
end if
|
||||||
|
|
||||||
|
if isNewProfile
|
||||||
|
newProfile.color = ColorUtils.RandomSoftColorHex()
|
||||||
|
m.profilesContent.insertChild(newProfile, 0)
|
||||||
|
end if
|
||||||
|
SetCurrentProfile(newProfile)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function LogoutWithProfile(profile as object) as void
|
||||||
|
if profile = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
profile = m.profilesContent.findNode(profile.id)
|
||||||
|
if profile = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.profilesContent.removeChild(profile)
|
||||||
|
currentProfile = m.top.currentProfile
|
||||||
|
if currentProfile <> invalid and currentProfile.id = profile.id
|
||||||
|
SetCurrentProfile(invalid)
|
||||||
|
else
|
||||||
|
RefreshActiveProfileState(currentProfile)
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.top.onProfileLogout = true
|
||||||
|
|
||||||
|
AsyncTask.Start(Tasks.ProfilesInvidiousUnregisterTokenTask, {
|
||||||
|
profiles: m.top
|
||||||
|
invidious: m.invidious
|
||||||
|
profileNodes: [profile]
|
||||||
|
})
|
||||||
|
end function
|
||||||
|
|
||||||
|
function LogoutWithProfiles(profiles as object) as void
|
||||||
|
if profiles = invalid or profiles.Count() = 0
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
currentProfile = m.top.currentProfile
|
||||||
|
logoutFromCurrentProfile = false
|
||||||
|
onProfileLogout = false
|
||||||
|
for each profile in profiles
|
||||||
|
profileNode = m.profilesContent.findNode(profile.id)
|
||||||
|
if profileNode = invalid
|
||||||
|
continue for
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.profilesContent.removeChild(profileNode)
|
||||||
|
onProfileLogout = true
|
||||||
|
if currentProfile <> invalid and currentProfile.id = profile.id
|
||||||
|
logoutFromCurrentProfile = true
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
|
||||||
|
if logoutFromCurrentProfile
|
||||||
|
SetCurrentProfile(invalid)
|
||||||
|
else
|
||||||
|
RefreshActiveProfileState(currentProfile)
|
||||||
|
end if
|
||||||
|
|
||||||
|
if onProfileLogout
|
||||||
|
m.top.onProfileLogout = true
|
||||||
|
end if
|
||||||
|
|
||||||
|
AsyncTask.Start(Tasks.ProfilesInvidiousUnregisterTokenTask, {
|
||||||
|
profiles: m.top
|
||||||
|
invidious: m.invidious
|
||||||
|
profileNodes: profiles
|
||||||
|
})
|
||||||
|
end function
|
||||||
|
|
||||||
|
function LogoutWithAccessToken(accessToken as dynamic) as void
|
||||||
|
if StringUtils.IsNullOrEmpty(accessToken)
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
' We are not going to invalidate the token on the server
|
||||||
|
' because we are likely dealing with an invalid token
|
||||||
|
' in the first place. All we need to do is remove the
|
||||||
|
' profile from the list of profiles.
|
||||||
|
|
||||||
|
allProfiles = m.profilesContent.getChildren(-1, 0)
|
||||||
|
for each profile in allProfiles
|
||||||
|
if profile.accessToken = accessToken
|
||||||
|
m.profilesContent.removeChild(profile)
|
||||||
|
currentProfile = m.top.currentProfile
|
||||||
|
if currentProfile <> invalid and currentProfile.id = profile.id
|
||||||
|
SetCurrentProfile(invalid)
|
||||||
|
else
|
||||||
|
RefreshActiveProfileState(currentProfile)
|
||||||
|
end if
|
||||||
|
m.top.onProfileLogout = true
|
||||||
|
exit for
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
end function
|
||||||
|
|
||||||
|
function SetCurrentProfile(newActiveProfile as object) as void
|
||||||
|
if newActiveProfile = invalid
|
||||||
|
RefreshActiveProfileState(invalid)
|
||||||
|
m.top.currentProfile = invalid
|
||||||
|
m.invidious.authToken = invalid
|
||||||
|
LogInfo("Current profile set to <invalid>")
|
||||||
|
SaveUserProfilesToRegistry()
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
RefreshActiveProfileState(newActiveProfile)
|
||||||
|
|
||||||
|
m.top.currentProfile = newActiveProfile
|
||||||
|
m.invidious.authToken = {
|
||||||
|
token: newActiveProfile.accessToken
|
||||||
|
instance: newActiveProfile.serverUrl
|
||||||
|
username: newActiveProfile.username
|
||||||
|
}
|
||||||
|
LogInfo("Current profile set to", newActiveProfile.username, "@", newActiveProfile.serverUrl)
|
||||||
|
SaveUserProfilesToRegistry()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function RefreshActiveProfileState(activeProfile as object) as void
|
||||||
|
allProfiles = m.profilesContent.getChildren(-1, 0)
|
||||||
|
if activeProfile = invalid
|
||||||
|
for each profile in allProfiles
|
||||||
|
profile.isSelected = false
|
||||||
|
end for
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
for each profile in allProfiles
|
||||||
|
profile.isSelected = profile.id = activeProfile.id
|
||||||
|
end for
|
||||||
|
end function
|
||||||
|
|
||||||
|
function CreateProfileId(username as string, serverUrl as string) as string
|
||||||
|
return "v1:" + CryptoUtils.GetMd5(username + serverUrl)
|
||||||
|
end function
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<component name="Profiles" extends="Node" includes="AutoBind">
|
||||||
|
<interface>
|
||||||
|
<!--
|
||||||
|
The version of the profiles. This is used to determine if the
|
||||||
|
profiles saved need to be migrated. If the version is less than the
|
||||||
|
current version, a migration is needed.
|
||||||
|
-->
|
||||||
|
<field id="__version" type="integer" value="1" />
|
||||||
|
<field id="currentProfile" type="node" />
|
||||||
|
<field id="onProfileLogout" type="boolean" alwaysNotify="true" />
|
||||||
|
<field id="content" type="node" />
|
||||||
|
|
||||||
|
<field id="invidious" type="node" />
|
||||||
|
|
||||||
|
<function name="GetProfilesDto" />
|
||||||
|
<function name="LoginWithProfile" />
|
||||||
|
<function name="LogoutWithProfile" />
|
||||||
|
<function name="LogoutWithProfiles" />
|
||||||
|
<function name="LogoutWithAccessToken" />
|
||||||
|
<function name="SetCurrentProfile" />
|
||||||
|
</interface>
|
||||||
|
<children>
|
||||||
|
<!-- Note: two content nodes because we're rendering profiles in a RowList on the ProfilesScreen -->
|
||||||
|
<ContentNode id="ProfilesContent">
|
||||||
|
<ContentNode>
|
||||||
|
<ProfileContentNode type="login">
|
||||||
|
</ProfileContentNode>
|
||||||
|
</ContentNode>
|
||||||
|
</ContentNode>
|
||||||
|
</children>
|
||||||
|
</component>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||||
|
|
||||||
|
@asynctask
|
||||||
|
function ProfilesInvidiousUnregisterTokenTask(input as object) as object
|
||||||
|
profileContentNodes = input.profileNodes
|
||||||
|
invidiousNode = input.invidious
|
||||||
|
|
||||||
|
service = new Invidious.InvidiousService(invidiousNode)
|
||||||
|
|
||||||
|
for each profileNode in profileContentNodes
|
||||||
|
authToken = {
|
||||||
|
instance: profileNode.serverUrl
|
||||||
|
token: profileNode.accessToken
|
||||||
|
}
|
||||||
|
response = service.UnregisterToken(authToken)
|
||||||
|
if not response.IsSuccess()
|
||||||
|
LogWarn(`Failed to unregister token: ${response.ErrorMessage()}`)
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
|
||||||
|
return invalid
|
||||||
|
end function
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||||
|
|
||||||
|
@asynctask
|
||||||
|
function ProfilesVerifyTokensTask(input as object) as object
|
||||||
|
profilesNode = input.profiles
|
||||||
|
invidiousNode = input.invidious
|
||||||
|
profileContentNodes = input.profileNodes
|
||||||
|
|
||||||
|
service = new Invidious.InvidiousService(invidiousNode)
|
||||||
|
invalidProfiles = []
|
||||||
|
|
||||||
|
for each profileNode in profileContentNodes
|
||||||
|
if not service.VerifyTokenScope(profileNode.accessToken)
|
||||||
|
invalidProfiles.push(profileNode)
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
|
||||||
|
if invalidProfiles.Count() = 0
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
|
||||||
|
profilesNode@.LogoutWithProfiles(invalidProfiles)
|
||||||
|
|
||||||
|
profileNames = []
|
||||||
|
for each profileNode in invalidProfiles
|
||||||
|
profileNames.push(profileNode.username)
|
||||||
|
end for
|
||||||
|
profileNames = profileNames.join(", ")
|
||||||
|
|
||||||
|
message = `It looks like you are logged in to Invidious, but do not have the required permissions.
|
||||||
|
For that reason, we have logged you out from the following profiles: ${profileNames}
|
||||||
|
Please log in again.
|
||||||
|
This can happen when Playlet is updated with new features.
|
||||||
|
We apologize for the inconvenience.`
|
||||||
|
DialogUtils.ShowDialog(message, "User logged out")
|
||||||
|
|
||||||
|
return invalid
|
||||||
|
end function
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<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>
|
|
||||||
@@ -8,7 +8,6 @@ function OnContentSet() as void
|
|||||||
"playlist": "playlistRowCellVisible"
|
"playlist": "playlistRowCellVisible"
|
||||||
"channel": "channelRowCellVisible"
|
"channel": "channelRowCellVisible"
|
||||||
"loading": "loadingRowCellVisible"
|
"loading": "loadingRowCellVisible"
|
||||||
"action": "actionRowCellVisible"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contentProperties = {
|
contentProperties = {
|
||||||
@@ -16,7 +15,6 @@ function OnContentSet() as void
|
|||||||
"playlist": "playlistRowCellItemContent"
|
"playlist": "playlistRowCellItemContent"
|
||||||
"channel": "channelRowCellItemContent"
|
"channel": "channelRowCellItemContent"
|
||||||
"loading": "loadingRowCellItemContent"
|
"loading": "loadingRowCellItemContent"
|
||||||
"action": "actionRowCellItemContent"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if content = invalid
|
if content = invalid
|
||||||
|
|||||||
@@ -8,13 +8,11 @@
|
|||||||
<field id="playlistRowCellVisible" type="boolean" alias="PlaylistRowCell.visible" />
|
<field id="playlistRowCellVisible" type="boolean" alias="PlaylistRowCell.visible" />
|
||||||
<field id="channelRowCellVisible" type="boolean" alias="ChannelRowCell.visible" />
|
<field id="channelRowCellVisible" type="boolean" alias="ChannelRowCell.visible" />
|
||||||
<field id="loadingRowCellVisible" type="boolean" alias="LoadingRowCell.visible" />
|
<field id="loadingRowCellVisible" type="boolean" alias="LoadingRowCell.visible" />
|
||||||
<field id="actionRowCellVisible" type="boolean" alias="ActionRowCell.visible" />
|
|
||||||
|
|
||||||
<field id="videoRowCellItemContent" type="node" alias="VideoRowCell.itemContent" />
|
<field id="videoRowCellItemContent" type="node" alias="VideoRowCell.itemContent" />
|
||||||
<field id="playlistRowCellItemContent" type="node" alias="PlaylistRowCell.itemContent" />
|
<field id="playlistRowCellItemContent" type="node" alias="PlaylistRowCell.itemContent" />
|
||||||
<field id="channelRowCellItemContent" type="node" alias="ChannelRowCell.itemContent" />
|
<field id="channelRowCellItemContent" type="node" alias="ChannelRowCell.itemContent" />
|
||||||
<field id="loadingRowCellItemContent" type="node" alias="LoadingRowCell.itemContent" />
|
<field id="loadingRowCellItemContent" type="node" alias="LoadingRowCell.itemContent" />
|
||||||
<field id="actionRowCellItemContent" type="node" alias="ActionRowCell.itemContent" />
|
|
||||||
|
|
||||||
<field id="loadingRowCellIndex" type="integer" alias="LoadingRowCell.index" />
|
<field id="loadingRowCellIndex" type="integer" alias="LoadingRowCell.index" />
|
||||||
</interface>
|
</interface>
|
||||||
@@ -23,6 +21,5 @@
|
|||||||
<PlaylistRowCell id="PlaylistRowCell" />
|
<PlaylistRowCell id="PlaylistRowCell" />
|
||||||
<ChannelRowCell id="ChannelRowCell" />
|
<ChannelRowCell id="ChannelRowCell" />
|
||||||
<LoadingRowCell id="LoadingRowCell" />
|
<LoadingRowCell id="LoadingRowCell" />
|
||||||
<ActionRowCell id="ActionRowCell" />
|
|
||||||
</children>
|
</children>
|
||||||
</component>
|
</component>
|
||||||
@@ -108,12 +108,8 @@ function OnRowItemSelected(index as object) as void
|
|||||||
authorId = rowItem.authorId
|
authorId = rowItem.authorId
|
||||||
LogInfo("Open channel: " + authorId)
|
LogInfo("Open channel: " + authorId)
|
||||||
OpenChannel(rowItem)
|
OpenChannel(rowItem)
|
||||||
else if rowItem.type = "action"
|
else
|
||||||
if rowItem.action = "LoginDialog"
|
LogWarn("Unknown row item type:", rowItem.type)
|
||||||
dialog = CreateObject("roSGNode", "LoginDialog")
|
|
||||||
dialog@.BindNode()
|
|
||||||
m.top.getScene().dialog = dialog
|
|
||||||
end if
|
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import "pkg:/components/Dialog/DialogUtils.bs"
|
|||||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||||
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
||||||
|
|
||||||
|
' TODO:P1 handle case where all feedSources are empty
|
||||||
@asynctask
|
@asynctask
|
||||||
function VideoRowListRowContentTask(input as object) as object
|
function VideoRowListRowContentTask(input as object) as object
|
||||||
try
|
try
|
||||||
@@ -59,17 +60,13 @@ function VideoRowListRowContentTask(input as object) as object
|
|||||||
|
|
||||||
if not response.success
|
if not response.success
|
||||||
if response.error = Invidious.ERROR_NOT_AUTHENTICATED
|
if response.error = Invidious.ERROR_NOT_AUTHENTICATED
|
||||||
RemovePlaceHolderItems(feedContentNode)
|
if feedSources.Count() = 1
|
||||||
actionNode = CreateObject("roSGNode", "ActionContentNode")
|
parent = feedContentNode.getParent()
|
||||||
actionNode.title = `Login to view ${feedSource.title}`
|
parent.removeChild(feedContentNode)
|
||||||
actionNode.action = "LoginDialog"
|
return {
|
||||||
|
success: true
|
||||||
feedSource.state.loadState = FeedLoadState.Loaded
|
}
|
||||||
feedSources[feedSourcesIndex] = feedSource
|
end if
|
||||||
feedContentNode.feedSources = feedSources
|
|
||||||
|
|
||||||
feedContentNode.appendChild(actionNode)
|
|
||||||
feedContentNode.loadState = FeedLoadState.Loaded
|
|
||||||
|
|
||||||
continue while
|
continue while
|
||||||
end if
|
end if
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ namespace Http
|
|||||||
function new(server as object)
|
function new(server as object)
|
||||||
super()
|
super()
|
||||||
|
|
||||||
m.invidiousNode = server.task.invidious
|
task = server.task
|
||||||
|
m.profilesNode = task.profiles
|
||||||
|
m.invidiousNode = task.invidious
|
||||||
m.invidiousService = new Invidious.InvidiousService(m.invidiousNode)
|
m.invidiousService = new Invidious.InvidiousService(m.invidiousNode)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -21,16 +23,6 @@ namespace Http
|
|||||||
return true
|
return true
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@get("/invidious/logout")
|
|
||||||
function Logout(context as object) as boolean
|
|
||||||
response = context.response
|
|
||||||
|
|
||||||
m.invidiousService.Logout()
|
|
||||||
|
|
||||||
response.Default(204, "OK")
|
|
||||||
return true
|
|
||||||
end function
|
|
||||||
|
|
||||||
@get("/invidious/token_callback")
|
@get("/invidious/token_callback")
|
||||||
function OnTokenReceived(context as object) as boolean
|
function OnTokenReceived(context as object) as boolean
|
||||||
request = context.request
|
request = context.request
|
||||||
@@ -42,7 +34,12 @@ namespace Http
|
|||||||
username = request.query["username"].DecodeUriComponent().DecodeUriComponent()
|
username = request.query["username"].DecodeUriComponent().DecodeUriComponent()
|
||||||
referer = request.query["ref"].DecodeUriComponent()
|
referer = request.query["ref"].DecodeUriComponent()
|
||||||
|
|
||||||
m.invidiousNode@.SetAuthToken(token, referer, username)
|
profile = CreateObject("roSGNode", "ProfileContentNode")
|
||||||
|
profile.username = username
|
||||||
|
profile.accessToken = token
|
||||||
|
profile.serverUrl = referer
|
||||||
|
|
||||||
|
m.profilesNode@.LoginWithProfile(profile)
|
||||||
end if
|
end if
|
||||||
response.Redirect("/")
|
response.Redirect("/")
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
namespace Http
|
||||||
|
|
||||||
|
class ProfilesRouter extends HttpRouter
|
||||||
|
|
||||||
|
function new(server as object)
|
||||||
|
super()
|
||||||
|
|
||||||
|
m.profilesNode = server.task.profiles
|
||||||
|
m.profilesContent = m.profilesNode.content.getChild(0)
|
||||||
|
end function
|
||||||
|
|
||||||
|
@get("/api/profiles")
|
||||||
|
function GetProfiles(context as object) as boolean
|
||||||
|
response = context.response
|
||||||
|
|
||||||
|
profiles = m.profilesNode@.GetProfilesDto(false)
|
||||||
|
response.Json(profiles)
|
||||||
|
return true
|
||||||
|
end function
|
||||||
|
|
||||||
|
@post("/api/profiles/activate")
|
||||||
|
function ActivateProfile(context as object) as boolean
|
||||||
|
request = context.request
|
||||||
|
response = context.response
|
||||||
|
|
||||||
|
payload = request.Json()
|
||||||
|
if payload = invalid
|
||||||
|
response.Default(400, `Invalid JSON payload`)
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
id = payload.id
|
||||||
|
if StringUtils.IsNullOrEmpty(id)
|
||||||
|
response.Default(400, "Missing profile id")
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
profile = m.profilesContent.findNode(id)
|
||||||
|
if profile = invalid
|
||||||
|
response.Default(404, `Profile id "${id}" not found`)
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.profilesNode@.SetCurrentProfile(profile)
|
||||||
|
response.Default(200, "Profile updated")
|
||||||
|
return true
|
||||||
|
end function
|
||||||
|
|
||||||
|
@delete("/api/profiles")
|
||||||
|
function Logout(context as object) as boolean
|
||||||
|
request = context.request
|
||||||
|
response = context.response
|
||||||
|
|
||||||
|
id = request.query.id
|
||||||
|
if StringUtils.IsNullOrEmpty(id)
|
||||||
|
response.Default(400, "Missing profile id")
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
profile = m.profilesContent.findNode(id)
|
||||||
|
if profile = invalid
|
||||||
|
response.Default(404, `Profile id "${id}" not found`)
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.profilesNode@.LogoutWithProfile(profile)
|
||||||
|
response.Default(200, "Profile logged out")
|
||||||
|
return true
|
||||||
|
end function
|
||||||
|
|
||||||
|
end class
|
||||||
|
|
||||||
|
end namespace
|
||||||
@@ -11,6 +11,7 @@ namespace Http
|
|||||||
m.applicationInfoNode = task.applicationInfo
|
m.applicationInfoNode = task.applicationInfo
|
||||||
m.invidiousNode = task.invidious
|
m.invidiousNode = task.invidious
|
||||||
m.preferencesNode = task.preferences
|
m.preferencesNode = task.preferences
|
||||||
|
m.profilesNode = task.profiles
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@get("/api/state")
|
@get("/api/state")
|
||||||
@@ -18,7 +19,7 @@ namespace Http
|
|||||||
request = context.request
|
request = context.request
|
||||||
response = context.response
|
response = context.response
|
||||||
|
|
||||||
keys = ["app", "device", "invidious", "preferences"]
|
keys = ["app", "device", "invidious", "preferences", "profiles"]
|
||||||
|
|
||||||
if request.query.DoesExist("key")
|
if request.query.DoesExist("key")
|
||||||
keys = request.query["key"]
|
keys = request.query["key"]
|
||||||
@@ -27,9 +28,14 @@ namespace Http
|
|||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
keysDict = {}
|
||||||
|
for each key in keys
|
||||||
|
keysDict[key] = true
|
||||||
|
end for
|
||||||
|
|
||||||
state = {}
|
state = {}
|
||||||
|
|
||||||
if ArrayUtils.IndexOfString(keys, "app") <> -1
|
if keysDict["app"] = true
|
||||||
appInfo = m.applicationInfoNode@.GetAppInfo()
|
appInfo = m.applicationInfoNode@.GetAppInfo()
|
||||||
|
|
||||||
if appInfo.lib_version_latest = "N/A"
|
if appInfo.lib_version_latest = "N/A"
|
||||||
@@ -46,25 +52,25 @@ namespace Http
|
|||||||
state["app"] = appInfo
|
state["app"] = appInfo
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if ArrayUtils.IndexOfString(keys, "device") <> -1
|
if keysDict["device"] = true
|
||||||
state["device"] = m.applicationInfoNode@.GetDeviceInfo()
|
state["device"] = m.applicationInfoNode@.GetDeviceInfo()
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if ArrayUtils.IndexOfString(keys, "invidious") <> -1
|
if keysDict["invidious"] = true
|
||||||
authToken = m.invidiousNode.authToken
|
|
||||||
state["invidious"] = {
|
state["invidious"] = {
|
||||||
current_instance: m.invidiousNode@.GetCurrentInstance()
|
current_instance: m.invidiousNode@.GetCurrentInstance()
|
||||||
auth_url: m.invidiousNode@.GetAuthorizeTokenLink()
|
auth_url: m.invidiousNode@.GetAuthorizeTokenLink()
|
||||||
logged_in: authToken <> invalid
|
|
||||||
logged_in_instance: authToken <> invalid ? authToken.instance : invalid
|
|
||||||
logged_in_username: authToken <> invalid ? authToken.username : invalid
|
|
||||||
}
|
}
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if ArrayUtils.IndexOfString(keys, "preferences") <> -1
|
if keysDict["preferences"] = true
|
||||||
state["preferences"] = m.preferencesNode@.GetUserPreferences()
|
state["preferences"] = m.preferencesNode@.GetUserPreferences()
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
if keysDict["profiles"] = true
|
||||||
|
state["profiles"] = m.profilesNode@.GetProfilesDto(false)
|
||||||
|
end if
|
||||||
|
|
||||||
response.Json(state)
|
response.Json(state)
|
||||||
return true
|
return true
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import "pkg:/components/Web/PlayletWebServer/Middleware/HomeRouter.bs"
|
|||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/InvidiousRouter.bs"
|
import "pkg:/components/Web/PlayletWebServer/Middleware/InvidiousRouter.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/PlayletLibUrlsRouter.bs"
|
import "pkg:/components/Web/PlayletWebServer/Middleware/PlayletLibUrlsRouter.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/PreferencesRouter.bs"
|
import "pkg:/components/Web/PlayletWebServer/Middleware/PreferencesRouter.bs"
|
||||||
|
import "pkg:/components/Web/PlayletWebServer/Middleware/ProfilesRouter.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/RegistryRouter.bs"
|
import "pkg:/components/Web/PlayletWebServer/Middleware/RegistryRouter.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/SearchHistoryRouter.bs"
|
import "pkg:/components/Web/PlayletWebServer/Middleware/SearchHistoryRouter.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/StateApiRouter.bs"
|
import "pkg:/components/Web/PlayletWebServer/Middleware/StateApiRouter.bs"
|
||||||
@@ -41,6 +42,7 @@ function SetupRoutes(server as object)
|
|||||||
server.UseRouter(new Http.DashRouter(server))
|
server.UseRouter(new Http.DashRouter(server))
|
||||||
server.UseRouter(new Http.PreferencesRouter(server))
|
server.UseRouter(new Http.PreferencesRouter(server))
|
||||||
server.UseRouter(new Http.InvidiousRouter(server))
|
server.UseRouter(new Http.InvidiousRouter(server))
|
||||||
|
server.UseRouter(new Http.ProfilesRouter(server))
|
||||||
server.UseRouter(new Http.VideoQueueRouter(server))
|
server.UseRouter(new Http.VideoQueueRouter(server))
|
||||||
server.UseRouter(new Http.BookmarksRouter(server))
|
server.UseRouter(new Http.BookmarksRouter(server))
|
||||||
server.UseRouter(new Http.HomeLayoutRouter(server))
|
server.UseRouter(new Http.HomeLayoutRouter(server))
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
<field id="appController" type="node" />
|
<field id="appController" type="node" />
|
||||||
<field id="preferences" type="node" />
|
<field id="preferences" type="node" />
|
||||||
<field id="invidious" type="node" />
|
<field id="invidious" type="node" />
|
||||||
|
<field id="profiles" type="node" />
|
||||||
<field id="applicationInfo" type="node" />
|
<field id="applicationInfo" type="node" />
|
||||||
<field id="videoQueue" type="node" />
|
<field id="videoQueue" type="node" />
|
||||||
<field id="bookmarks" type="node" />
|
<field id="bookmarks" type="node" />
|
||||||
|
|||||||
|
After Width: | Height: | Size: 2.4 KiB |
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||||
|
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||||
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
viewBox="0 0 512 512" xml:space="preserve">
|
||||||
|
<polygon style="fill:#F8C660;" points="419.694,214.205 337.847,109.715 255.99,214.205 174.143,109.715 92.296,214.205
|
||||||
|
10.449,109.715 10.449,360.489 501.551,360.489 501.551,109.715 "/>
|
||||||
|
<rect x="10.449" y="360.489" style="fill:#ECF0F1;" width="491.102" height="41.796"/>
|
||||||
|
<g>
|
||||||
|
<circle style="fill:#DF5F4E;" cx="174.143" cy="277.242" r="37.616"/>
|
||||||
|
<circle style="fill:#DF5F4E;" cx="337.836" cy="277.242" r="37.616"/>
|
||||||
|
<path style="fill:#DF5F4E;" d="M501.551,314.863c-20.898,0-37.616-16.842-37.616-37.616c0-20.775,16.718-37.616,37.616-37.616
|
||||||
|
V314.863z"/>
|
||||||
|
<path style="fill:#DF5F4E;" d="M10.449,239.63c20.898,0,37.616,16.842,37.616,37.616c0,20.775-16.718,37.616-37.616,37.616V239.63z
|
||||||
|
"/>
|
||||||
|
</g>
|
||||||
|
<g>
|
||||||
|
<path style="fill:#231F20;" d="M504.959,99.838c-4.214-1.453-8.885-0.074-11.634,3.434l-73.632,93.99l-73.621-93.989
|
||||||
|
c-1.981-2.529-5.013-4.005-8.225-4.005c-3.211,0-6.245,1.477-8.225,4.005l-73.632,93.99l-73.621-93.989
|
||||||
|
c-1.981-2.529-5.013-4.005-8.225-4.005s-6.245,1.477-8.225,4.005l-73.621,93.989l-73.621-93.989
|
||||||
|
c-2.749-3.509-7.42-4.889-11.634-3.435C2.827,101.291,0,105.257,0,109.715v292.571c0,5.771,4.679,10.448,10.449,10.448h491.102
|
||||||
|
c5.77,0,10.449-4.677,10.449-10.448V109.715C512,105.257,509.172,101.291,504.959,99.838z M491.102,302.324
|
||||||
|
c-9.81-4.102-16.718-13.798-16.718-25.078c0-11.28,6.909-20.975,16.718-25.078V302.324z M84.07,220.648
|
||||||
|
c6.988,6.988,15.874,0.706,16.366,0.095c0.028-0.036,0.056-0.059,0.086-0.095l73.621-93.989l73.621,93.989
|
||||||
|
c2.061,2.631,5.13,4.006,8.233,4.006c5.053,0,8.207-3.989,8.218-4.005l73.632-93.99c0,0,74.8,95.371,75.154,95.555
|
||||||
|
c0.085,0.071,0.162,0.147,0.249,0.216c4.543,3.559,11.109,2.762,14.669-1.782l63.182-80.653v90.343
|
||||||
|
c-21.494,4.786-37.616,23.994-37.616,46.908c0,22.914,16.123,42.123,37.616,46.908v25.886H20.898v-25.886
|
||||||
|
c21.494-4.786,37.616-23.994,37.616-46.908s-16.123-42.123-37.616-46.908v-90.34L84.07,220.648z M20.898,252.169
|
||||||
|
c9.81,4.102,16.718,13.798,16.718,25.078c0,11.28-6.909,20.975-16.718,25.078V252.169z M491.102,391.836H20.898v-20.898h470.204
|
||||||
|
V391.836z"/>
|
||||||
|
<path style="fill:#231F20;" d="M174.143,325.312c26.503,0,48.065-21.563,48.065-48.065c0-26.503-21.563-48.065-48.065-48.065
|
||||||
|
s-48.065,21.563-48.065,48.065C126.077,303.749,147.64,325.312,174.143,325.312z M174.143,250.079
|
||||||
|
c14.981,0,27.167,12.188,27.167,27.167c0,14.98-12.187,27.167-27.167,27.167c-14.981,0-27.167-12.188-27.167-27.167
|
||||||
|
C146.975,262.267,159.162,250.079,174.143,250.079z"/>
|
||||||
|
<path style="fill:#231F20;" d="M337.842,325.312c26.503,0,48.065-21.563,48.065-48.065c0-26.503-21.563-48.065-48.065-48.065
|
||||||
|
c-26.503,0-48.065,21.563-48.065,48.065C289.776,303.749,311.339,325.312,337.842,325.312z M337.842,250.079
|
||||||
|
c14.981,0,27.167,12.188,27.167,27.167c0,14.98-12.187,27.167-27.167,27.167c-14.981,0-27.167-12.188-27.167-27.167
|
||||||
|
C310.674,262.267,322.861,250.079,337.842,250.079z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
inputHash: 'cb60a03d94432dc8c59e759b0b964fe0',
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
outputFilePath: 'images/icons/crown.png',
|
||||||
|
outputHash: 'ae78dc598a50ae81eb18c0167d783121',
|
||||||
|
width: 80,
|
||||||
|
height: 80,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.3 KiB |
@@ -1 +1,12 @@
|
|||||||
<svg viewBox="0 0 190.516 190.516" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><defs><clipPath clipPathUnits="userSpaceOnUse" id="a"><circle style="display:inline;fill:red;stroke-width:.808149;stroke-linejoin:round" cx="99.697" cy="190.975" r="67.373"/></clipPath></defs><g style="display:inline" transform="translate(-5.483 -14.747)"><circle style="display:inline;fill:#000;stroke:none;stroke-width:1.2888;stroke-linejoin:round" cx="100.741" cy="110.005" r="95.258"/><circle style="display:inline;fill:#fff;stroke:none;stroke-width:1.2888;stroke-linejoin:round" cx="100.741" cy="110.005" r="95.258" clip-path="url(#a)"/><circle style="display:inline;fill:#fff;stroke:none;stroke-width:.907953;stroke-linejoin:round" cx="99.6" cy="85.809" r="38.136"/></g></svg>
|
<svg viewBox="0 0 190.516 190.516" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<defs>
|
||||||
|
<clipPath clipPathUnits="userSpaceOnUse" id="a">
|
||||||
|
<circle style="display:inline;fill:red;stroke-width:.808149;stroke-linejoin:round" cx="99.697" cy="190.975" r="67.373"/>
|
||||||
|
</clipPath>
|
||||||
|
</defs>
|
||||||
|
<g style="display:inline" transform="translate(-5.483 -14.747)">
|
||||||
|
<circle style="display:inline;fill:#242424;stroke:none;stroke-width:1.2888;stroke-linejoin:round" cx="100.741" cy="110.005" r="95.258"/>
|
||||||
|
<circle style="display:inline;fill:#DBDBDB;stroke:none;stroke-width:1.2888;stroke-linejoin:round" cx="100.741" cy="110.005" r="95.258" clip-path="url(#a)"/>
|
||||||
|
<circle style="display:inline;fill:#DBDBDB;stroke:none;stroke-width:.907953;stroke-linejoin:round" cx="99.6" cy="85.809" r="38.136"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 773 B After Width: | Height: | Size: 861 B |
@@ -1,11 +1,17 @@
|
|||||||
{
|
{
|
||||||
inputHash: '9345dbe14b95ef513b0a5919226cd277',
|
inputHash: 'd05489dbec5e0e5b3b6889b41b033c38',
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
outputFilePath: 'images/icons/user.png',
|
outputFilePath: 'images/icons/user.png',
|
||||||
outputHash: '5cda73aaa2eeaee05dd0c1705129eed2',
|
outputHash: '0c541921e88abe409a9ca047a6661683',
|
||||||
width: 80,
|
width: 64,
|
||||||
height: 80,
|
height: 64,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
outputFilePath: 'images/icons/user-200.png',
|
||||||
|
outputHash: '499cdc27460b66a5cef811620138c549',
|
||||||
|
width: 200,
|
||||||
|
height: 200,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,18 @@ namespace ArrayUtils
|
|||||||
return -1
|
return -1
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function IndexOfNode(array as object, value as dynamic) as integer
|
||||||
|
if not IsNode(value)
|
||||||
|
return -1
|
||||||
|
end if
|
||||||
|
for i = 0 to array.Count() - 1
|
||||||
|
if value.isSameNode(array[i])
|
||||||
|
return i
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
return -1
|
||||||
|
end function
|
||||||
|
|
||||||
function Insert(array as object, value as dynamic, index as integer) as void
|
function Insert(array as object, value as dynamic, index as integer) as void
|
||||||
if index = 0
|
if index = 0
|
||||||
array.Unshift(value)
|
array.Unshift(value)
|
||||||
|
|||||||
@@ -7,25 +7,16 @@ namespace ColorUtils
|
|||||||
color = color.mid(1)
|
color = color.mid(1)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
value = Val(color.mid(0, 2), 16) * 16777216 + Val(color.mid(2, 2), 16) * 65536 + Val(color.mid(4, 2), 16) * 256
|
return Val(color, 16)
|
||||||
if color.Len() = 6
|
|
||||||
value += 255
|
|
||||||
else if color.Len() = 8
|
|
||||||
value += Val(color.mid(6, 2), 16)
|
|
||||||
end if
|
|
||||||
|
|
||||||
return value
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function IntToHex(color as integer) as string
|
function IntToHex(color as integer) as string
|
||||||
hexDigits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
|
hex = UCase(StrI(color, 16))
|
||||||
hexString = "#"
|
length = Len(hex)
|
||||||
|
for i = 0 to 7 - length
|
||||||
for i = 7 to 0 step -1
|
hex = "0" + hex
|
||||||
hexString = hexString + hexDigits[(color >> (i * 4)) and &hF]
|
|
||||||
end for
|
end for
|
||||||
|
return "#" + hex
|
||||||
return hexString
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function RgbaToInt(r as integer, g as integer, b as integer, a = 255 as integer) as integer
|
function RgbaToInt(r as integer, g as integer, b as integer, a = 255 as integer) as integer
|
||||||
@@ -40,4 +31,8 @@ namespace ColorUtils
|
|||||||
return RgbaToInt(Rnd(100) + 100, Rnd(100) + 100, Rnd(100) + 100)
|
return RgbaToInt(Rnd(100) + 100, Rnd(100) + 100, Rnd(100) + 100)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function RandomSoftColorHex() as string
|
||||||
|
return IntToHex(RandomSoftColorInt())
|
||||||
|
end function
|
||||||
|
|
||||||
end namespace
|
end namespace
|
||||||
@@ -6,10 +6,10 @@ namespace Tests
|
|||||||
@describe("ColorUtils")
|
@describe("ColorUtils")
|
||||||
|
|
||||||
@it("Converts from hex to int")
|
@it("Converts from hex to int")
|
||||||
@params("#00d400B3", 13893811)
|
@params("#00D400B3", 13893811)
|
||||||
@params("#ffff00B3", -65357)
|
@params("#FFFF00B3", -65357)
|
||||||
@params("#008a5cB3", 9067699)
|
@params("#008A5CB3", 9067699)
|
||||||
@params("#cc00ffB3", -872349773)
|
@params("#CC00FFB3", -872349773)
|
||||||
function _(hexColor as string, expectedInt as integer)
|
function _(hexColor as string, expectedInt as integer)
|
||||||
m.assertEqual(ColorUtils.HexToInt(hexColor), expectedInt)
|
m.assertEqual(ColorUtils.HexToInt(hexColor), expectedInt)
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -3,17 +3,18 @@ namespace RegistryUtils
|
|||||||
const DEFAULT_SECTION = "Playlet"
|
const DEFAULT_SECTION = "Playlet"
|
||||||
|
|
||||||
const USER_PREFERENCES = "user_prefs"
|
const USER_PREFERENCES = "user_prefs"
|
||||||
|
const USER_PROFILES = "user_profiles"
|
||||||
|
|
||||||
const SEARCH_HISTORY = "search_history"
|
const SEARCH_HISTORY = "search_history"
|
||||||
const PLAYLET_LIB_URLS = "playlet_lib_urls"
|
const PLAYLET_LIB_URLS = "playlet_lib_urls"
|
||||||
const BOOKMARKS = "bookmarks"
|
const BOOKMARKS = "bookmarks"
|
||||||
|
|
||||||
const INVIDIOUS_TOKEN = "invidious_token"
|
|
||||||
|
|
||||||
const LAST_LOUNGE_DATA = "last_lounge_data"
|
const LAST_LOUNGE_DATA = "last_lounge_data"
|
||||||
|
|
||||||
' "invidious_instances" is deprecated, but we keep for migration purposes
|
' "invidious_instances" is deprecated, but we keep for migration purposes
|
||||||
const INVIDIOUS_INSTANCES = "invidious_instances"
|
const INVIDIOUS_INSTANCES = "invidious_instances"
|
||||||
|
' "invidious_token" is deprecated, but we keep for migration purposes
|
||||||
|
const INVIDIOUS_TOKEN = "invidious_token"
|
||||||
|
|
||||||
function Read(key as string, sectionName = DEFAULT_SECTION as string) as dynamic
|
function Read(key as string, sectionName = DEFAULT_SECTION as string) as dynamic
|
||||||
section = CreateObject("roRegistrySection", sectionName)
|
section = CreateObject("roRegistrySection", sectionName)
|
||||||
|
|||||||
@@ -45,8 +45,17 @@ export class PlayletApi {
|
|||||||
return await response;
|
return await response;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async logout() {
|
static async getProfiles() {
|
||||||
await fetch(`${PlayletApi.host()}/invidious/logout`);
|
const response = await fetch(`${PlayletApi.host()}/api/profiles`);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
static async activateProfile(profileId) {
|
||||||
|
await this.postJson(`${PlayletApi.host()}/api/profiles/activate`, { id: profileId });
|
||||||
|
}
|
||||||
|
|
||||||
|
static async logout(profileId) {
|
||||||
|
return await fetch(`${PlayletApi.host()}/api/profiles?id=${profileId}`, { method: "DELETE" });
|
||||||
}
|
}
|
||||||
|
|
||||||
static async playVideo(args) {
|
static async playVideo(args) {
|
||||||
|
|||||||
@@ -1,55 +1,48 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import PlayletLogoDark from "assets/logo-dark.svg.svelte";
|
import PlayletLogoDark from "assets/logo-dark.svg.svelte";
|
||||||
import PlayletLogoLight from "assets/logo-light.svg.svelte";
|
import PlayletLogoLight from "assets/logo-light.svg.svelte";
|
||||||
import UserIcon from "assets/user.svg.svelte";
|
|
||||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
|
||||||
import { ExternalControlProtocol } from "lib/Api/ExternalControlProtocol";
|
import { ExternalControlProtocol } from "lib/Api/ExternalControlProtocol";
|
||||||
import { appThemeStore, playletStateStore } from "lib/Stores";
|
import { appThemeStore, playletStateStore } from "lib/Stores";
|
||||||
import ThemeSelect from "lib/ThemeToggle.svelte";
|
import ThemeSelect from "lib/ThemeToggle.svelte";
|
||||||
|
import ProfilesDialog from "./ProfilesDialog.svelte";
|
||||||
|
import ProfileAvatar from "./ProfileAvatar.svelte";
|
||||||
|
|
||||||
|
let profilesDialog;
|
||||||
let version;
|
let version;
|
||||||
let loggedIn = false;
|
let currentProfile;
|
||||||
let auth_url;
|
|
||||||
let currentInstance;
|
|
||||||
let loggedInInstance;
|
|
||||||
let username;
|
|
||||||
let appId = "693751";
|
let appId = "693751";
|
||||||
|
|
||||||
playletStateStore.subscribe((value) => {
|
playletStateStore.subscribe((value) => {
|
||||||
version = value?.app?.lib_version ?? "";
|
version = getAppVersion(value);
|
||||||
if (value?.app?.id) {
|
if (value?.app?.id) {
|
||||||
appId = value?.app?.id;
|
appId = value?.app?.id;
|
||||||
}
|
}
|
||||||
|
let profiles = value?.profiles?.profiles ?? [];
|
||||||
|
currentProfile = profiles.find(
|
||||||
|
(p) => p.id === value?.profiles?.currentProfile
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const showProfilesDialog = () => {
|
||||||
|
profilesDialog.show();
|
||||||
|
};
|
||||||
|
|
||||||
|
function getAppVersion(playletState) {
|
||||||
|
let version = playletState?.app?.lib_version ?? "";
|
||||||
|
const appId = playletState?.app?.id;
|
||||||
if (appId === "dev") {
|
if (appId === "dev") {
|
||||||
version += "-dev";
|
version += "-dev";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
value?.app?.lib_url_type === "custom" &&
|
playletState?.app?.lib_url_type === "custom" &&
|
||||||
value?.app?.lib_url ===
|
playletState?.app?.lib_url ===
|
||||||
"https://github.com/iBicha/playlet/releases/download/canary/playlet-lib.zip"
|
"https://github.com/iBicha/playlet/releases/download/canary/playlet-lib.zip"
|
||||||
) {
|
) {
|
||||||
version += "-canary";
|
version += "-canary";
|
||||||
}
|
}
|
||||||
loggedIn = value?.invidious?.logged_in;
|
return version;
|
||||||
auth_url = value?.invidious?.auth_url;
|
}
|
||||||
currentInstance = value?.invidious?.current_instance;
|
|
||||||
loggedInInstance = value?.invidious?.logged_in_instance;
|
|
||||||
username = value?.invidious?.logged_in_username;
|
|
||||||
});
|
|
||||||
|
|
||||||
const login = () => {
|
|
||||||
if (!auth_url) {
|
|
||||||
alert("Error with login, please refresh the page.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
window.location = auth_url;
|
|
||||||
};
|
|
||||||
const logout = async () => {
|
|
||||||
await PlayletApi.logout();
|
|
||||||
PlayletApi.getState().then((value) => {
|
|
||||||
playletStateStore.set(value);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="navbar bg-base-100 sticky top-0 z-40">
|
<div class="navbar bg-base-100 sticky top-0 z-40">
|
||||||
@@ -65,41 +58,18 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex-none">
|
<div class="flex-none">
|
||||||
<ThemeSelect />
|
<ThemeSelect />
|
||||||
{#if loggedIn && username}
|
{#if currentProfile && currentProfile.username}
|
||||||
<div class="badge badge-outline">
|
<div class="badge badge-outline">
|
||||||
<span>{username}</span>
|
<span>{currentProfile.username}</span>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="dropdown dropdown-end">
|
<button
|
||||||
<div tabindex="-1" class="btn btn-ghost btn-circle avatar">
|
on:click={showProfilesDialog}
|
||||||
<div class="w-8 rounded-full">
|
class="btn btn-ghost btn-circle avatar"
|
||||||
<UserIcon />
|
>
|
||||||
</div>
|
<ProfileAvatar />
|
||||||
</div>
|
</button>
|
||||||
<ul
|
|
||||||
tabindex="-1"
|
|
||||||
class="menu menu-sm dropdown-content mt-3 p-2 shadow bg-base-100 rounded-box"
|
|
||||||
>
|
|
||||||
{#if loggedIn}
|
|
||||||
<li>
|
|
||||||
<div
|
|
||||||
class="tooltip tooltip-left"
|
|
||||||
data-tip={`Logout from ${loggedInInstance}`}
|
|
||||||
>
|
|
||||||
<button on:click={logout}>Logout</button>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
{:else}
|
|
||||||
<li>
|
|
||||||
<div
|
|
||||||
class="tooltip tooltip-left"
|
|
||||||
data-tip={`Login using ${currentInstance}`}
|
|
||||||
>
|
|
||||||
<button on:click={login}>Login to Invidious</button>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
{/if}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<ProfilesDialog bind:this={profilesDialog} />
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { playletStateStore } from "lib/Stores";
|
||||||
|
import UserIcon from "assets/user.svg.svelte";
|
||||||
|
|
||||||
|
let currentProfile;
|
||||||
|
|
||||||
|
playletStateStore.subscribe((value) => {
|
||||||
|
let profiles = value?.profiles?.profiles ?? [];
|
||||||
|
currentProfile = profiles.find(
|
||||||
|
(p) => p.id === value?.profiles?.currentProfile
|
||||||
|
);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{#if currentProfile && currentProfile.username}
|
||||||
|
<div class="avatar placeholder m-1.5">
|
||||||
|
<div
|
||||||
|
class="rounded-full w-8 ring ring-offset-base-100 ring-offset-2"
|
||||||
|
style="background-color: {currentProfile.color}"
|
||||||
|
>
|
||||||
|
<span class="text-xl font-medium text-gray-200"
|
||||||
|
>{currentProfile.username.substring(0, 1).toUpperCase()}</span
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="w-8 rounded-full">
|
||||||
|
<UserIcon />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { playletStateStore } from "lib/Stores";
|
||||||
|
import { PlayletApi } from "./Api/PlayletApi";
|
||||||
|
import { get } from "svelte/store";
|
||||||
|
|
||||||
|
export function show() {
|
||||||
|
modal.showModal();
|
||||||
|
refreshProfiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function close() {
|
||||||
|
modal.close();
|
||||||
|
accordionState = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let modal;
|
||||||
|
|
||||||
|
let profiles = [];
|
||||||
|
let currentProfile;
|
||||||
|
|
||||||
|
let authUrl;
|
||||||
|
let currentInstance;
|
||||||
|
|
||||||
|
let accordionState = null;
|
||||||
|
|
||||||
|
playletStateStore.subscribe((value) => {
|
||||||
|
authUrl = value?.invidious?.auth_url;
|
||||||
|
currentInstance = value?.invidious?.current_instance;
|
||||||
|
profiles = value?.profiles?.profiles ?? [];
|
||||||
|
currentProfile = profiles.find(
|
||||||
|
(p) => p.id === value?.profiles?.currentProfile
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
function refreshProfiles() {
|
||||||
|
PlayletApi.getProfiles().then((profiles) => {
|
||||||
|
const state = get(playletStateStore);
|
||||||
|
state.profiles = profiles;
|
||||||
|
playletStateStore.set(state);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function activate(profileId: string) {
|
||||||
|
await PlayletApi.activateProfile(profileId);
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function logout(profileId: string) {
|
||||||
|
await PlayletApi.logout(profileId);
|
||||||
|
if (profileId === currentProfile?.id) {
|
||||||
|
window.location.reload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
refreshProfiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
function login() {
|
||||||
|
if (!authUrl) {
|
||||||
|
alert("Error with login, please refresh the page.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.location = authUrl;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<dialog bind:this={modal} class="modal">
|
||||||
|
<form method="dialog" class="modal-box bg-base-100">
|
||||||
|
<div class="flex flex-col items-center">
|
||||||
|
<div class="text-xl font-medium m-4">Profiles</div>
|
||||||
|
|
||||||
|
{#each profiles as profile}
|
||||||
|
<div class="collapse collapse-arrow bg-base-300 m-1">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="profiles-accordion"
|
||||||
|
value={profile.id}
|
||||||
|
bind:group={accordionState}
|
||||||
|
/>
|
||||||
|
<div class="collapse-title flex">
|
||||||
|
<div>
|
||||||
|
<div class="avatar placeholder">
|
||||||
|
<div
|
||||||
|
class="rounded-full w-12 {profile.id === currentProfile?.id
|
||||||
|
? 'ring ring-primary ring-offset-base-100 ring-offset-2'
|
||||||
|
: ''} "
|
||||||
|
style="background-color: {profile.color}"
|
||||||
|
>
|
||||||
|
<span class="text-xl font-medium text-gray-200"
|
||||||
|
>{profile.username.substring(0, 1).toUpperCase()}</span
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="ml-4">
|
||||||
|
<div class="font-medium">
|
||||||
|
{profile.username}
|
||||||
|
</div>
|
||||||
|
<div class="text-xs font-light">
|
||||||
|
<a
|
||||||
|
class="link"
|
||||||
|
href={profile.serverUrl}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer">{profile.serverUrl}</a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="collapse-content">
|
||||||
|
{#if profile.id !== currentProfile?.id}
|
||||||
|
<button
|
||||||
|
on:click={() => activate(profile.id)}
|
||||||
|
class="btn btn-primary m-1">Activate</button
|
||||||
|
>
|
||||||
|
{/if}
|
||||||
|
<button
|
||||||
|
on:click={() => logout(profile.id)}
|
||||||
|
class="btn btn-primary m-1">Logout</button
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
<div class="flex items-center">
|
||||||
|
<button class="btn btn-primary" on:click={login}>
|
||||||
|
<div class="">
|
||||||
|
<div class="text-m">Login to Invidious</div>
|
||||||
|
<div class="text-xs font-light">{currentInstance}</div>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
<button class="btn m-6" on:click={close}>Close</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<form method="dialog" class="modal-backdrop">
|
||||||
|
<button on:click={close}>Close</button>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
@@ -83,6 +83,7 @@
|
|||||||
let deviceInfo = {};
|
let deviceInfo = {};
|
||||||
let invidiousInfo = {};
|
let invidiousInfo = {};
|
||||||
let preferencesInfo = {};
|
let preferencesInfo = {};
|
||||||
|
let profilesInfo = {};
|
||||||
const feedbackTitle = encodeURIComponent("[Feedback] Playlet");
|
const feedbackTitle = encodeURIComponent("[Feedback] Playlet");
|
||||||
let githubUrlIssue = "https://github.com/iBicha/playlet/issues/new";
|
let githubUrlIssue = "https://github.com/iBicha/playlet/issues/new";
|
||||||
let mailToUrl = "mailto:brahim.hadriche@gmail.com";
|
let mailToUrl = "mailto:brahim.hadriche@gmail.com";
|
||||||
@@ -92,6 +93,7 @@
|
|||||||
deviceInfo = value.device || {};
|
deviceInfo = value.device || {};
|
||||||
invidiousInfo = value.invidious || {};
|
invidiousInfo = value.invidious || {};
|
||||||
preferencesInfo = value.preferences || {};
|
preferencesInfo = value.preferences || {};
|
||||||
|
profilesInfo = value.profiles || {};
|
||||||
githubUrlIssue = createGithubIssueUrl();
|
githubUrlIssue = createGithubIssueUrl();
|
||||||
mailToUrl = createMailToUrl();
|
mailToUrl = createMailToUrl();
|
||||||
});
|
});
|
||||||
@@ -118,6 +120,11 @@ ${JSON.stringify(invidiousInfo, null, 2)}
|
|||||||
#### User preferences
|
#### User preferences
|
||||||
\`\`\`
|
\`\`\`
|
||||||
${JSON.stringify(preferencesInfo, null, 2)}
|
${JSON.stringify(preferencesInfo, null, 2)}
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
#### Profiles
|
||||||
|
\`\`\`
|
||||||
|
${JSON.stringify(profilesInfo, null, 2)}
|
||||||
\`\`\``;
|
\`\`\``;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ export type PlayletState = {
|
|||||||
device?: any,
|
device?: any,
|
||||||
invidious?: any,
|
invidious?: any,
|
||||||
preferences?: any,
|
preferences?: any,
|
||||||
|
profiles?: any,
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
playletStateStore.subscribe((value) => {
|
playletStateStore.subscribe((value) => {
|
||||||
invidiousApi.instance = value?.invidious?.current_instance;
|
invidiousApi.instance = value?.invidious?.current_instance;
|
||||||
invidiousApi.userCountryCode = value?.device?.user_country_code ?? "US";
|
invidiousApi.userCountryCode = value?.device?.user_country_code ?? "US";
|
||||||
invidiousApi.isLoggedIn = value.invidious?.logged_in ?? false;
|
invidiousApi.isLoggedIn = !!(value.profiles?.currentProfile ?? false);
|
||||||
loadRow();
|
loadRow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const types = [
|
|||||||
{ name: 'AssociativeArray', interface: 'ifAssociativeArray', type: 'object', defaultValue: '{}' },
|
{ name: 'AssociativeArray', interface: 'ifAssociativeArray', type: 'object', defaultValue: '{}' },
|
||||||
{ name: 'ByteArray', interface: 'ifByteArray', type: null, defaultValue: null },
|
{ name: 'ByteArray', interface: 'ifByteArray', type: null, defaultValue: null },
|
||||||
{ name: 'Function', interface: 'ifFunction', type: null, defaultValue: null },
|
{ name: 'Function', interface: 'ifFunction', type: null, defaultValue: null },
|
||||||
|
{ name: 'Node', interface: 'ifSGNodeDict', type: null, defaultValue: null },
|
||||||
];
|
];
|
||||||
|
|
||||||
const generatedCodeHeader = `' The rest of this file is generated by the TypeGenPlugin`
|
const generatedCodeHeader = `' The rest of this file is generated by the TypeGenPlugin`
|
||||||
|
|||||||