1- import { ComponentProps , DisplayComponent , FSComponent , Subscribable , VNode } from "@microsoft/msfs-sdk"
1+ import { ComponentProps , DisplayComponent , FSComponent , Subscribable , VNode } from "@microsoft/msfs-sdk" ;
22import {
33 DownloadProgressPhase ,
44 NavigationDataStatus ,
55 NavigraphEventType ,
66 NavigraphNavigationDataInterface ,
7- } from "@navigraph/msfs-navigation-data-interface"
8- import { CancelToken } from "navigraph/auth"
9- import { packages } from "../../../Lib/navigraph"
10- import { AuthService } from "../../../Services/AuthService"
11- import { Dropdown } from "../../Dropdown"
7+ } from "@navigraph/msfs-navigation-data-interface" ;
8+ import { CancelToken } from "navigraph/auth" ;
9+ import { packages } from "../../../Lib/navigraph" ;
10+ import { AuthService } from "../../../Services/AuthService" ;
11+ import { Dropdown } from "../../Dropdown" ;
1212
1313interface AuthPageProps extends ComponentProps {
14- setDatabaseInfo : ( value : NavigationDataStatus ) => void
15- navigationDataInterface : NavigraphNavigationDataInterface
14+ setDatabaseInfo : ( value : NavigationDataStatus ) => void ;
15+ navigationDataInterface : NavigraphNavigationDataInterface ;
1616}
1717
1818export class AuthPage extends DisplayComponent < AuthPageProps > {
19- private readonly textRef = FSComponent . createRef < HTMLDivElement > ( )
20- private readonly loginButtonRef = FSComponent . createRef < HTMLButtonElement > ( )
21- private readonly navigationDataTextRef = FSComponent . createRef < HTMLDivElement > ( )
22- private readonly qrCodeRef = FSComponent . createRef < HTMLImageElement > ( )
23- private readonly dropdownRef = FSComponent . createRef < Dropdown > ( )
24- private readonly downloadButtonRef = FSComponent . createRef < HTMLButtonElement > ( )
19+ private readonly textRef = FSComponent . createRef < HTMLDivElement > ( ) ;
20+ private readonly loginButtonRef = FSComponent . createRef < HTMLButtonElement > ( ) ;
21+ private readonly navigationDataTextRef = FSComponent . createRef < HTMLDivElement > ( ) ;
22+ private readonly qrCodeRef = FSComponent . createRef < HTMLImageElement > ( ) ;
23+ private readonly dropdownRef = FSComponent . createRef < Dropdown > ( ) ;
24+ private readonly downloadButtonRef = FSComponent . createRef < HTMLButtonElement > ( ) ;
2525
26- private cancelSource = CancelToken . source ( )
26+ private cancelSource = CancelToken . source ( ) ;
2727
2828 constructor ( props : AuthPageProps ) {
29- super ( props )
29+ super ( props ) ;
3030
3131 this . props . navigationDataInterface . onEvent ( NavigraphEventType . DownloadProgress , data => {
3232 switch ( data . phase ) {
3333 case DownloadProgressPhase . Downloading :
34- this . displayMessage ( "Downloading navigation data..." )
35- break
34+ this . displayMessage ( "Downloading navigation data..." ) ;
35+ break ;
3636 case DownloadProgressPhase . Cleaning :
37- if ( ! data . deleted ) return
38- this . displayMessage ( `Cleaning destination directory. ${ data . deleted } files deleted so far` )
39- break
37+ if ( ! data . deleted ) return ;
38+ this . displayMessage ( `Cleaning destination directory. ${ data . deleted } files deleted so far` ) ;
39+ break ;
4040 case DownloadProgressPhase . Extracting : {
4141 // Ensure non-null
42- if ( ! data . unzipped || ! data . total_to_unzip ) return
43- const percent = Math . round ( ( data . unzipped / data . total_to_unzip ) * 100 )
44- this . displayMessage ( `Unzipping files... ${ percent } % complete` )
45- break
42+ if ( ! data . unzipped || ! data . total_to_unzip ) return ;
43+ const percent = Math . round ( ( data . unzipped / data . total_to_unzip ) * 100 ) ;
44+ this . displayMessage ( `Unzipping files... ${ percent } % complete` ) ;
45+ break ;
4646 }
4747 }
48- } )
48+ } ) ;
4949 }
5050
5151 onAfterRender ( node : VNode ) : void {
52- super . onAfterRender ( node )
52+ super . onAfterRender ( node ) ;
5353
54- this . loginButtonRef . instance . addEventListener ( "click" , ( ) => this . handleClick ( ) )
55- this . downloadButtonRef . instance . addEventListener ( "click" , ( ) => this . handleDownloadClick ( ) )
54+ this . loginButtonRef . instance . addEventListener ( "click" , ( ) => this . handleClick ( ) ) ;
55+ this . downloadButtonRef . instance . addEventListener ( "click" , ( ) => this . handleDownloadClick ( ) ) ;
5656
5757 AuthService . user . sub ( user => {
5858 if ( user ) {
59- this . qrCodeRef . instance . src = ""
60- this . qrCodeRef . instance . style . display = "none"
61- this . loginButtonRef . instance . textContent = "Log out"
62- this . textRef . instance . textContent = `Welcome, ${ user . preferred_username } `
63- this . displayMessage ( "" )
59+ this . qrCodeRef . instance . src = "" ;
60+ this . qrCodeRef . instance . style . display = "none" ;
61+ this . loginButtonRef . instance . textContent = "Log out" ;
62+ this . textRef . instance . textContent = `Welcome, ${ user . preferred_username } ` ;
63+ this . displayMessage ( "" ) ;
6464
65- this . handleLogin ( )
65+ this . handleLogin ( ) ;
6666 } else {
67- this . loginButtonRef . instance . textContent = "Sign in"
68- this . textRef . instance . textContent = "Not logged in"
67+ this . loginButtonRef . instance . textContent = "Sign in" ;
68+ this . textRef . instance . textContent = "Not logged in" ;
6969 }
70- } , true )
70+ } , true ) ;
7171 }
7272
7373 private async handleClick ( ) {
7474 try {
7575 if ( AuthService . getUser ( ) ) {
76- await AuthService . signOut ( )
76+ await AuthService . signOut ( ) ;
7777 } else {
78- this . cancelSource = CancelToken . source ( ) // Reset any previous cancellations
79- this . displayMessage ( "Authenticating.. Scan code (or click it) to sign in" )
78+ this . cancelSource = CancelToken . source ( ) ; // Reset any previous cancellations
79+ this . displayMessage ( "Authenticating.. Scan code (or click it) to sign in" ) ;
8080 await AuthService . signIn ( p => {
8181 if ( p ) {
82- this . qrCodeRef . instance . src = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${ p . verification_uri_complete } `
83- this . qrCodeRef . instance . style . display = "block"
82+ this . qrCodeRef . instance . src = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${ p . verification_uri_complete } ` ;
83+ this . qrCodeRef . instance . style . display = "block" ;
8484 this . qrCodeRef . instance . onclick = ( ) => {
85- OpenBrowser ( p . verification_uri_complete )
86- }
85+ OpenBrowser ( p . verification_uri_complete ) ;
86+ } ;
8787 }
88- } , this . cancelSource . token )
88+ } , this . cancelSource . token ) ;
8989 }
9090 } catch ( err ) {
91- this . qrCodeRef . instance . style . display = "none"
92- if ( err instanceof Error ) this . displayError ( err . message )
93- else this . displayError ( `Unknown error: ${ String ( err ) } ` )
91+ this . qrCodeRef . instance . style . display = "none" ;
92+ if ( err instanceof Error ) this . displayError ( err . message ) ;
93+ else this . displayError ( `Unknown error: ${ String ( err ) } ` ) ;
9494 }
9595 }
9696
@@ -100,44 +100,44 @@ export class AuthPage extends DisplayComponent<AuthPageProps> {
100100 . listPackages ( )
101101 . then ( pkgs => {
102102 for ( const pkg of pkgs ) {
103- this . dropdownRef . instance . addDropdownItem ( pkg . format , pkg . format )
103+ this . dropdownRef . instance . addDropdownItem ( pkg . format , pkg . format ) ;
104104 }
105105 } )
106- . catch ( e => console . error ( e ) )
106+ . catch ( e => console . error ( e ) ) ;
107107 }
108108
109109 private async handleDownloadClick ( ) {
110110 try {
111111 if ( ! this . props . navigationDataInterface . getIsInitialized ( ) )
112- throw new Error ( "Navigation data interface not initialized" )
112+ throw new Error ( "Navigation data interface not initialized" ) ;
113113
114- const format = this . dropdownRef . instance . getNavigationDataFormat ( )
115- if ( ! format ) throw new Error ( "Unable to fetch package: No navigation data format has been selected" )
114+ const format = this . dropdownRef . instance . getNavigationDataFormat ( ) ;
115+ if ( ! format ) throw new Error ( "Unable to fetch package: No navigation data format has been selected" ) ;
116116
117117 // Get default package for client
118- const pkg = await packages . getPackage ( format )
118+ const pkg = await packages . getPackage ( format ) ;
119119
120120 // Download navigation data to work dir and set active
121- await this . props . navigationDataInterface . download_navigation_data ( pkg . file . url )
121+ await this . props . navigationDataInterface . download_navigation_data ( pkg . file . url ) ;
122122
123123 // Update navigation data status
124- this . props . setDatabaseInfo ( await this . props . navigationDataInterface . get_navigation_data_install_status ( ) )
124+ this . props . setDatabaseInfo ( await this . props . navigationDataInterface . get_navigation_data_install_status ( ) ) ;
125125
126- this . displayMessage ( "Navigation data downloaded" )
126+ this . displayMessage ( "Navigation data downloaded" ) ;
127127 } catch ( err ) {
128- if ( err instanceof Error ) this . displayError ( err . message )
129- else this . displayError ( `Unknown error: ${ String ( err ) } ` )
128+ if ( err instanceof Error ) this . displayError ( err . message ) ;
129+ else this . displayError ( `Unknown error: ${ String ( err ) } ` ) ;
130130 }
131131 }
132132
133133 private displayMessage ( message : string ) {
134- this . navigationDataTextRef . instance . textContent = message
135- this . navigationDataTextRef . instance . style . color = "white"
134+ this . navigationDataTextRef . instance . textContent = message ;
135+ this . navigationDataTextRef . instance . style . color = "white" ;
136136 }
137137
138138 private displayError ( error : string ) {
139- this . navigationDataTextRef . instance . textContent = error
140- this . navigationDataTextRef . instance . style . color = "red"
139+ this . navigationDataTextRef . instance . textContent = error ;
140+ this . navigationDataTextRef . instance . style . color = "red" ;
141141 }
142142
143143 render ( ) : VNode {
@@ -161,6 +161,6 @@ export class AuthPage extends DisplayComponent<AuthPageProps> {
161161 </ div >
162162 </ div >
163163 </ div >
164- )
164+ ) ;
165165 }
166166}
0 commit comments