import "pkg:/components/Dialog/DialogUtils.bs" import "pkg:/components/Screens/ProfileScreen/YouTubeAccountSelectionView/YouTubeAccountSelectionViewUtils.bs" import "pkg:/source/AsyncTask/AsyncTask.bs" import "pkg:/source/AsyncTask/Tasks.bs" import "pkg:/source/utils/ErrorUtils.bs" import "pkg:/source/utils/Locale.bs" import "pkg:/source/utils/Logging.bs" import "pkg:/source/utils/Types.bs" function Init() m.qrCode = m.top.findNode("QrCodePoster") codeLabel = m.top.findNode("codeLabel") if codeLabel <> invalid codeLabel = codeLabel.getChild(0) if codeLabel <> invalid codeFont = m.top.findNode("codeFont") codeLabel.font = codeFont end if end if m.top.width = "920" m.top.observeFieldScoped("buttonSelected", FuncName(Close)) m.top.observeFieldScoped("wasClosed", FuncName(OnWasClosed)) scanLabel = m.top.findNode("scanLabel") scanLabel.text = Tr(Locale.Dialogs.ScanTheQrCode) linkInstructionLabel = m.top.findNode("linkInstructionLabel") linkInstructionLabel.text = Tr(Locale.Dialogs.OpenLinkAndEnterFollowingCode).replace("%1", `'https://yt.be/activate'`) end function function OnNodeReady() m.task = AsyncTask.Start(Tasks.YouTubeLoginTask, { dialog: m.top profilesService: m.top.profilesService }, OnYouTubeLoginTaskResult) end function function OnYouTubeLoginTaskResult(output as object) as void m.task = invalid if output.cancelled Close() return end if if not output.success or not output.result.success ' output.error for unhandled exception error = output.error if error = invalid ' output.result.error for network errors error = output.result.error end if error = ErrorUtils.Format(error) LogError(error) DialogUtils.ShowDialogEx({ message: error title: Tr(Locale.Generic.Error) large: true }) return end if accounts = output.result.accounts accessToken = output.result.accessToken ' if accounts is invalid, we're going to assume a profile is already created. if accounts = invalid or accessToken = invalid Close() return end if ' The accountSelectionView will take over the creation of the profile. accountSelectionView = YouTubeAccountSelectionViewUtils.Open(m.top.appController) accountSelectionView.accessToken = accessToken accountSelectionView.accounts = accounts Close() end function function OnCodeSet(event as object) code = event.getData() m.qrCode.text = code end function function Close() m.top.close = true end function function OnWasClosed() if m.task <> invalid m.task.cancel = true m.task = invalid end if end function function OnUrlSet() m.qrCode.text = m.top.url end function