import "pkg:/components/Navigation/Navigation.bs" import "pkg:/source/utils/DisposableObserve.bs" import "pkg:/source/utils/FocusManagement.bs" import "pkg:/source/utils/Locale.bs" import "pkg:/source/utils/RemoteKeys.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") 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, RemoteKeys.Down, m.logoutButton) SetNavigation(m.logoutButton, RemoteKeys.Down, m.closeButton) SetNavigation(m.closeButton, RemoteKeys.Up, m.logoutButton) SetNavigation(m.logoutButton, RemoteKeys.Up, m.activateButton) DisposableObserveFieldScoped(m.profilesService, "currentProfile", FuncName(OnCunrrentProfileChanged)) DisposableObserveFieldScoped(m.profilesService, "onProfileLogout", FuncName(OnProfileLogout)) end function function OnContentSet() as void content = m.top.content if content = invalid return end if username = content.username m.top.username = username thumbnail = content.thumbnail if not StringUtils.IsNullOrEmpty(thumbnail) m.top.circlePosterInnerUri = thumbnail ' bs:disable-next-line LINT3023 m.top.circlePosterInnerBlendColor = "#FFFFFFFF" m.top.letter = "" else m.top.circlePosterInnerUri = "pkg:/images/white-circle.png" m.top.circlePosterInnerBlendColor = content.color if not StringUtils.IsNullOrEmpty(username) letter = username.Left(1) if letter = "@" and Len(username) > 1 letter = username.Mid(1, 1) end if m.top.letter = UCase(letter) else m.top.letter = "" end if end if m.top.crownVisible = content.isSelected backendType = content.type if backendType = "invidious" m.top.serverUrl = content.serverUrl m.top.backendTypePosterUri = "pkg:/images/invidious-logo.png" else if backendType = "youtube" m.top.serverUrl = "YouTube" m.top.backendTypePosterUri = "pkg:/images/youtube-logo.png" else m.top.serverUrl = "" m.top.backendTypePosterUri = "" end if 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 = RemoteKeys.Options or key = RemoteKeys.Play or key = RemoteKeys.Pause or key = RemoteKeys.PlayOnly ' A pass-through to the app controller, so it can toggle picture-in-picture and pause/play return false end if if key = RemoteKeys.Back and press Close() return true end if return true end function function Activate() as void content = m.top.content if content = invalid return end if profile = m.profilesService.content.getChild(0).findNode(content.id) if profile = invalid return end if m.top.content = invalid m.profilesService@.SetCurrentProfile(profile) Close() end function function Logout() as void content = m.top.content if content = invalid return end if m.top.content = invalid m.profilesService@.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.profilesService.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 m.activateButton.text = Tr(Locale.Buttons.InUse) m.activateButton.disabled = true else m.activateButton.text = Tr(Locale.Buttons.Activate) m.activateButton.disabled = false end if end function