import "pkg:/components/Dialog/DialogUtils.bs" import "pkg:/components/Navigation/Navigation.bs" import "pkg:/components/Screens/ProfileScreen/BackendTypeSelectionView/BackendTypeSelectionViewUtils.bs" import "pkg:/components/Screens/ProfileScreen/ProfileView/ProfileViewUtils.bs" import "pkg:/source/utils/FocusManagement.bs" import "pkg:/source/utils/Logging.bs" import "pkg:/source/utils/RemoteKeys.bs" import "pkg:/source/utils/Types.bs" function Init() m.top.focusable = true m.profileRowList = m.top.FindNode("ProfileRowList") end function function OnNodeReady() SetNavigation(invalid, RemoteKeys.Back, m.navBar) SetNavigation(invalid, RemoteKeys.Left, m.navBar) m.profileRowList.content = m.profilesService.content m.profileRowList.observeFieldScoped("rowItemSelected", FuncName(OnRowItemSelected)) m.profilesService.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" #if YT_OAUTH_SUPPORT backendTypeSelectionView = BackendTypeSelectionViewUtils.Open(m.appController) backendTypeSelectionView.observeFieldScoped("selectedBackendType", FuncName(OnBackEndSelected)) return #else LoginWithInvidious() return #end if end if ProfileViewUtils.Open(selectedProfile, m.appController) end function function OnBackEndSelected(event as object) as void backendTypeSelectionView = event.GetRoSGNode() backendTypeSelectionView.unobserveFieldScoped("selectedBackendType") selectedBackendType = event.getData() if selectedBackendType = "BackendTypeInvidious" LoginWithInvidious() else if selectedBackendType = "BackendTypeYouTube" ShowLoginWithYouTubeDialog() else LogError("Unknown backend type:", selectedBackendType) end if end function function LoginWithInvidious() as void invidiousInstance = m.preferences["invidious.instance"] if StringUtils.IsNullOrEmpty(invidiousInstance) DialogUtils.ShowDialogEx({ title: "No Invidious Instance" message: [ "Playlet built-in backend does not support login yet.", "Can only login if an Invidious instance is set in the settings." ] }) return end if dialog = CreateObject("roSGNode", "InvidiousLoginDialog") dialog@.BindNode() m.top.getScene().dialog = dialog end function function ShowLoginWithYouTubeDialog() as void ' TODO:P2 localize dialog = DialogUtils.ShowDialogEx({ title: "Disclaimer" message: "Playlet authors acknowledge that all trademarks and registered trademarks mentioned in this application and related pages are the property of their respective owners. The use of these trademarks or trade names is for identification purposes only and does not imply any endorsement, affiliation, or sponsorship by the trademark owner." buttons: [ Tr(Locale.Buttons.OK) Tr(Locale.Buttons.Cancel) ] }) dialog.ObserveField("buttonSelected", FuncName(OnLoginWithYouTubeDialogButtonSelected)) end function function OnLoginWithYouTubeDialogButtonSelected(event as object) as void buttonSelected = event.getData() if buttonSelected <> 0 return end if LoginWithYouTube() end function function LoginWithYouTube() as void dialog = CreateObject("roSGNode", "YouTubeLoginDialog") dialog@.BindNode() m.top.getScene().dialog = dialog end function function OnCurrentProfileChanged() as void currentProfile = m.profilesService.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