1- import { Component , OnInit , inject } from '@angular/core' ;
1+ import { Component , inject , OnInit } from '@angular/core' ;
22import { ActivatedRoute , ParamMap } from "@angular/router" ;
33import { Errors } from "../login-landing/errors" ;
44import { HttpErrorResponse } from "@angular/common/http" ;
@@ -10,106 +10,106 @@ import {CdkCopyToClipboard} from "@angular/cdk/clipboard";
1010import { interval , Subscription } from "rxjs" ;
1111
1212@Component ( {
13- selector : 'app-login-landing-desktop' ,
14- imports : [
15- LoadingIconComponent ,
16- LogoComponent ,
17- MatButton ,
18- CdkCopyToClipboard
19- ] ,
20- templateUrl : './login-landing-desktop.component.html' ,
21- styleUrl : './login-landing-desktop.component.scss'
13+ selector : 'app-login-landing-desktop' ,
14+ imports : [
15+ LoadingIconComponent ,
16+ LogoComponent ,
17+ MatButton ,
18+ CdkCopyToClipboard
19+ ] ,
20+ templateUrl : './login-landing-desktop.component.html' ,
21+ styleUrl : './login-landing-desktop.component.scss'
2222} )
2323export class LoginLandingDesktopComponent implements OnInit {
24- private route = inject ( ActivatedRoute ) ;
25- private timer : Subscription | undefined ;
26- private desktopData : string | undefined ;
24+ private route = inject ( ActivatedRoute ) ;
25+ private timer : Subscription | undefined ;
26+ private desktopData : string | undefined ;
2727
28- loggedIn : boolean = false ;
29- error : string = '' ;
30- oAuth : OAuth | null = null ;
31- loading : boolean = true ;
28+ loggedIn : boolean = false ;
29+ error : string = '' ;
30+ oAuth : OAuth | null = null ;
31+ loading : boolean = true ;
3232
33- ngOnInit ( ) : void {
34- this . route . queryParamMap . subscribe ( {
35- next : ( params : ParamMap ) => {
36- const error = params . get ( 'error' ) ;
37- if ( null !== error ) {
38- const errorNum = + error ;
39- if ( Errors . TWITCH_ACCOUNT_HAS_NO_EMAIL === errorNum ) {
40- this . onLoginFailed ( 'Your Twitch account must have a valid e-mail address, please add one and try again' )
41- } else if ( Errors . TWITCH_ERROR_WITH_TOKEN === errorNum ) {
42- this . onLoginFailed ( 'Twitch failed to give us a valid token, please try again' )
43- } else {
44- this . onLoginFailed ( 'Sorry we did something wrong trying to log you in, please try again' )
45- }
33+ ngOnInit ( ) : void {
34+ this . route . queryParamMap . subscribe ( {
35+ next : ( params : ParamMap ) => {
36+ const error = params . get ( 'error' ) ;
37+ if ( null !== error ) {
38+ const errorNum = + error ;
39+ if ( Errors . TWITCH_ACCOUNT_HAS_NO_EMAIL === errorNum ) {
40+ this . onLoginFailed ( 'Your Twitch account must have a valid e-mail address, please add one and try again' )
41+ } else if ( Errors . TWITCH_ERROR_WITH_TOKEN === errorNum ) {
42+ this . onLoginFailed ( 'Twitch failed to give us a valid token, please try again' )
43+ } else {
44+ this . onLoginFailed ( 'Sorry we did something wrong trying to log you in, please try again' )
45+ }
4646
47- return ;
48- }
47+ return ;
48+ }
4949
50- const oAuth = {
51- bearer : params . get ( 'bearer' ) ,
52- refresh : params . get ( 'refresh' ) ,
53- expiresUtc : params . get ( 'expiresUtc' ) ,
54- } ;
50+ const oAuth = {
51+ bearer : params . get ( 'bearer' ) ,
52+ refresh : params . get ( 'refresh' ) ,
53+ expiresUtc : params . get ( 'expiresUtc' ) ,
54+ } ;
5555
56- if ( null === oAuth . bearer || null === oAuth . refresh || null === oAuth . expiresUtc ) {
57- this . onLoginFailed ( ) ;
58- return ;
59- }
56+ if ( null === oAuth . bearer || null === oAuth . refresh || null === oAuth . expiresUtc ) {
57+ this . onLoginFailed ( ) ;
58+ return ;
59+ }
6060
61- this . oAuth = {
62- bearer : oAuth . bearer ,
63- refresh : oAuth . refresh ,
64- expiresUtc : oAuth . expiresUtc
65- } ;
61+ this . oAuth = {
62+ bearer : oAuth . bearer ,
63+ refresh : oAuth . refresh ,
64+ expiresUtc : oAuth . expiresUtc
65+ } ;
6666
67- // DO NOT assign this.desktopData until AFTER you update the clipboard successfully.
68- // The absence of a value on this.desktopData is what tells the application we haven't logged in yet.
69- const json = JSON . stringify ( oAuth ) ;
70- navigator . clipboard . writeText ( json ) ;
71- this . desktopData = json ;
67+ // DO NOT assign this.desktopData until AFTER you update the clipboard successfully.
68+ // The absence of a value on this.desktopData is what tells the application we haven't logged in yet.
69+ const json = JSON . stringify ( oAuth ) ;
70+ navigator . clipboard . writeText ( json ) ;
71+ this . desktopData = json ;
7272
73- this . loading = false ;
74- this . timer = interval ( 1000 )
75- . subscribe ( {
76- next : _ => {
77- this . runCheckForLogin ( ) ;
78- } ,
79- error : e => {
80- console . error ( e ) ;
81- }
82- } ) ;
73+ this . loading = false ;
74+ this . timer = interval ( 1000 )
75+ . subscribe ( {
76+ next : _ => {
77+ this . runCheckForLogin ( ) ;
8378 } ,
84- error : ( _ : HttpErrorResponse ) => {
85- this . onLoginFailed ( ) ;
79+ error : e => {
80+ console . error ( e ) ;
8681 }
87- } ) ;
88- }
82+ } ) ;
83+ } ,
84+ error : ( _ : HttpErrorResponse ) => {
85+ this . onLoginFailed ( ) ;
86+ }
87+ } ) ;
88+ }
8989
90- private runCheckForLogin ( ) {
91- try {
92- navigator . clipboard . readText ( ) . then ( text => {
93- // If the text matches what we put on the clipboard then we aren't signed in yet.
94- if ( undefined === this . desktopData || text === this . desktopData ) {
95- return ;
96- }
90+ private runCheckForLogin ( ) {
91+ try {
92+ navigator . clipboard . readText ( ) . then ( text => {
93+ // If the text matches what we put on the clipboard then we aren't signed in yet.
94+ if ( undefined === this . desktopData || text === this . desktopData ) {
95+ return ;
96+ }
9797
98- // If the text does match, we are signed in on the desktop app. Maybe...kinda....might be...you never know...
99- // Don't judge me. -.-
100- this . timer ?. unsubscribe ( ) ;
101- this . loggedIn = true ;
102- } )
103- } catch {
104- // Do nothing, just don't crash.
105- }
98+ // If the text does match, we are signed in on the desktop app. Maybe...kinda....might be...you never know...
99+ // Don't judge me. -.-
100+ this . timer ?. unsubscribe ( ) ;
101+ this . loggedIn = true ;
102+ } )
103+ } catch {
104+ // Do nothing, just don't crash.
106105 }
106+ }
107107
108- onLoginFailed ( message = ':( Failed to login, please try again' ) : void {
109- this . error = message ;
110- this . loading = false ;
111- }
108+ onLoginFailed ( message = ':( Failed to login, please try again' ) : void {
109+ this . error = message ;
110+ this . loading = false ;
111+ }
112112
113- protected readonly JSON = JSON ;
114- protected readonly window = window ;
113+ protected readonly JSON = JSON ;
114+ protected readonly window = window ;
115115}
0 commit comments