Skip to content

Commit a015459

Browse files
Merge pull request #100 from nullinside-development-group/feat/login
feat: making desktop login less confusing
2 parents a5f8f46 + b7e4cc6 commit a015459

File tree

3 files changed

+60
-25
lines changed

3 files changed

+60
-25
lines changed
Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
<div class="centered-box">
2-
<div class="centered-box_logo-container">
3-
<app-logo/>
4-
</div>
5-
<div class="centered-box_content-container">
6-
@if (loading) {
7-
<app-loading-icon fontSize="24px" height="35px" width="35px">Logging in</app-loading-icon>
2+
<div class="centered-box_logo-container">
3+
<app-logo/>
4+
</div>
5+
<div class="centered-box_content-container">
6+
@if (loggedIn) {
7+
<h2>LOGGED IN SUCCESSFULLY!</h2>
8+
<p>Please return to the desktop application...</p>
9+
} @else if (loading) {
10+
<app-loading-icon fontSize="24px" height="35px" width="35px">Logging in</app-loading-icon>
11+
} @else {
12+
@if (error !== '') {
13+
<div class="error-banner">{{ error }}</div>
14+
} @else {
15+
@if (null !== oAuth) {
16+
<h2>DO NOT SHOW ON STREAM</h2>
17+
<button mat-stroked-button color="primary" [cdkCopyToClipboard]="JSON.stringify(oAuth)">Copy to
18+
Clipboard
19+
</button>
820
} @else {
9-
@if (error !== '') {
10-
<div class="error-banner">{{ error }}</div>
11-
} @else {
12-
@if (null !== oAuth) {
13-
<h2>DO NOT SHOW ON STREAM</h2>
14-
<button mat-stroked-button color="primary" [cdkCopyToClipboard]="JSON.stringify(oAuth)">Copy to
15-
Clipboard
16-
</button>
17-
} @else {
18-
<div class="error-banner">Failed to get you authenticated, please try again</div>
19-
}
20-
}
21+
<div class="error-banner">Failed to get you authenticated, please try again</div>
2122
}
22-
</div>
23+
}
24+
}
25+
</div>
2326
</div>

src/src/app/view/login-landing-desktop/login-landing-desktop.component.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Component, OnInit, inject } from '@angular/core';
2-
import {NullinsideService} from "../../service/nullinside.service";
32
import {ActivatedRoute, ParamMap} from "@angular/router";
43
import {Errors} from "../login-landing/errors";
54
import {HttpErrorResponse} from "@angular/common/http";
@@ -8,6 +7,7 @@ import {LogoComponent} from "../../common/components/logo/logo.component";
87
import {OAuth} from "../../common/interface/oauth";
98
import {MatButton} from "@angular/material/button";
109
import {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
})
2323
export 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;

src/src/app/view/vm-manager/vm-manager.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import {ActionableDockerResource} from './interface/ActionableDockerResource';
1818
templateUrl: './vm-manager.component.html',
1919
styleUrl: './vm-manager.component.scss'
2020
})
21-
export class VmManagerComponent implements OnInit, OnDestroy {
22-
private api = inject(NullinsideService);
21+
export class VmManagerComponent implements OnInit, OnDestroy {
22+
private api = inject(NullinsideService);
2323

2424
public vms: ActionableDockerResource[] | null = null;
2525
public error: string | null = null;
@@ -36,7 +36,7 @@ export class VmManagerComponent implements OnInit, OnDestroy {
3636
error: _ => {
3737
this.error = "Failed to refresh the list, the server may be down...";
3838
}
39-
})
39+
});
4040
}
4141

4242
ngOnDestroy(): void {

0 commit comments

Comments
 (0)