11import { Component , OnInit , inject } from '@angular/core' ;
2- import { NullinsideService } from "../../service/nullinside.service" ;
32import { ActivatedRoute , ParamMap } from "@angular/router" ;
43import { Errors } from "../login-landing/errors" ;
54import { HttpErrorResponse } from "@angular/common/http" ;
@@ -8,6 +7,7 @@ import {LogoComponent} from "../../common/components/logo/logo.component";
87import { OAuth } from "../../common/interface/oauth" ;
98import { MatButton } from "@angular/material/button" ;
109import { CdkCopyToClipboard } from "@angular/cdk/clipboard" ;
10+ import { interval , Subscription } from "rxjs" ;
1111
1212@Component ( {
1313 selector : 'app-login-landing-desktop' ,
@@ -21,9 +21,11 @@ import {CdkCopyToClipboard} from "@angular/cdk/clipboard";
2121 styleUrl : './login-landing-desktop.component.scss'
2222} )
2323export class LoginLandingDesktopComponent implements OnInit {
24- private api = inject ( NullinsideService ) ;
2524 private route = inject ( ActivatedRoute ) ;
25+ private timer : Subscription | undefined ;
26+ private desktopData : string | undefined ;
2627
28+ loggedIn : boolean = false ;
2729 error : string = '' ;
2830 oAuth : OAuth | null = null ;
2931 loading : boolean = true ;
@@ -62,15 +64,45 @@ export class LoginLandingDesktopComponent implements OnInit {
6264 expiresUtc : oAuth . expiresUtc
6365 } ;
6466
65- navigator . clipboard . writeText ( JSON . stringify ( oAuth ) ) ;
67+ this . desktopData = JSON . stringify ( oAuth ) ;
68+ navigator . clipboard . writeText ( this . desktopData ) ;
6669 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+ } ) ;
6781 } ,
6882 error : ( _ : HttpErrorResponse ) => {
6983 this . onLoginFailed ( ) ;
7084 }
7185 } ) ;
7286 }
7387
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+
74106 onLoginFailed ( message = ':( Failed to login, please try again' ) : void {
75107 this . error = message ;
76108 this . loading = false ;
0 commit comments