1
1
import { Component , OnInit , inject } from '@angular/core' ;
2
- import { NullinsideService } from "../../service/nullinside.service" ;
3
2
import { ActivatedRoute , ParamMap } from "@angular/router" ;
4
3
import { Errors } from "../login-landing/errors" ;
5
4
import { HttpErrorResponse } from "@angular/common/http" ;
@@ -8,6 +7,7 @@ import {LogoComponent} from "../../common/components/logo/logo.component";
8
7
import { OAuth } from "../../common/interface/oauth" ;
9
8
import { MatButton } from "@angular/material/button" ;
10
9
import { CdkCopyToClipboard } from "@angular/cdk/clipboard" ;
10
+ import { interval , Subscription } from "rxjs" ;
11
11
12
12
@Component ( {
13
13
selector : 'app-login-landing-desktop' ,
@@ -21,9 +21,11 @@ import {CdkCopyToClipboard} from "@angular/cdk/clipboard";
21
21
styleUrl : './login-landing-desktop.component.scss'
22
22
} )
23
23
export class LoginLandingDesktopComponent implements OnInit {
24
- private api = inject ( NullinsideService ) ;
25
24
private route = inject ( ActivatedRoute ) ;
25
+ private timer : Subscription | undefined ;
26
+ private desktopData : string | undefined ;
26
27
28
+ loggedIn : boolean = false ;
27
29
error : string = '' ;
28
30
oAuth : OAuth | null = null ;
29
31
loading : boolean = true ;
@@ -62,15 +64,45 @@ export class LoginLandingDesktopComponent implements OnInit {
62
64
expiresUtc : oAuth . expiresUtc
63
65
} ;
64
66
65
- navigator . clipboard . writeText ( JSON . stringify ( oAuth ) ) ;
67
+ this . desktopData = JSON . stringify ( oAuth ) ;
68
+ navigator . clipboard . writeText ( this . desktopData ) ;
66
69
this . loading = false ;
70
+ this . timer ?. unsubscribe ( ) ;
71
+
72
+ this . timer = interval ( 1000 )
73
+ . subscribe ( {
74
+ next : _ => {
75
+ this . runCheckForLogin ( ) ;
76
+ } ,
77
+ error : e => {
78
+ console . error ( e ) ;
79
+ }
80
+ } ) ;
67
81
} ,
68
82
error : ( _ : HttpErrorResponse ) => {
69
83
this . onLoginFailed ( ) ;
70
84
}
71
85
} ) ;
72
86
}
73
87
88
+ private runCheckForLogin ( ) {
89
+ try {
90
+ navigator . clipboard . readText ( ) . then ( text => {
91
+ // If the text matches what we put on the clipboard then we aren't signed in yet.
92
+ if ( text === this . desktopData ) {
93
+ return ;
94
+ }
95
+
96
+ // If the text does match, we are signed in on the desktop app. Maybe...kinda....might be...you never know...
97
+ // Don't judge me. -.-
98
+ this . timer ?. unsubscribe ( ) ;
99
+ this . loggedIn = true ;
100
+ } )
101
+ } catch {
102
+ // Do nothing, just don't crash.
103
+ }
104
+ }
105
+
74
106
onLoginFailed ( message = ':( Failed to login, please try again' ) : void {
75
107
this . error = message ;
76
108
this . loading = false ;
0 commit comments