1
- import { Component , OnInit , inject } from '@angular/core' ;
1
+ import { Component , inject , OnInit } from '@angular/core' ;
2
2
import { ActivatedRoute , ParamMap } from "@angular/router" ;
3
3
import { Errors } from "../login-landing/errors" ;
4
4
import { HttpErrorResponse } from "@angular/common/http" ;
@@ -10,106 +10,106 @@ import {CdkCopyToClipboard} from "@angular/cdk/clipboard";
10
10
import { interval , Subscription } from "rxjs" ;
11
11
12
12
@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'
22
22
} )
23
23
export 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 ;
27
27
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 ;
32
32
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
+ }
46
46
47
- return ;
48
- }
47
+ return ;
48
+ }
49
49
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
+ } ;
55
55
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
+ }
60
60
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
+ } ;
66
66
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 ;
72
72
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 ( ) ;
83
78
} ,
84
- error : ( _ : HttpErrorResponse ) => {
85
- this . onLoginFailed ( ) ;
79
+ error : e => {
80
+ console . error ( e ) ;
86
81
}
87
- } ) ;
88
- }
82
+ } ) ;
83
+ } ,
84
+ error : ( _ : HttpErrorResponse ) => {
85
+ this . onLoginFailed ( ) ;
86
+ }
87
+ } ) ;
88
+ }
89
89
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
+ }
97
97
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.
106
105
}
106
+ }
107
107
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
+ }
112
112
113
- protected readonly JSON = JSON ;
114
- protected readonly window = window ;
113
+ protected readonly JSON = JSON ;
114
+ protected readonly window = window ;
115
115
}
0 commit comments