Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjozork committed Jul 17, 2023
1 parent f261d15 commit 72e7629
Show file tree
Hide file tree
Showing 22 changed files with 667 additions and 487 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2021-2023 FlyByWire Simulations
//
// SPDX-License-Identifier: GPL-3.0

function translateAtsuMessageType(type) {
switch (type) {
case AtsuCommon.AtsuMessageType.Freetext:
Expand Down Expand Up @@ -38,18 +42,18 @@ const lbsToKg = (value) => {
* @param {() => void} updateView
*/
const getSimBriefOfp = (mcdu, updateView, callback = () => {}) => {
const simBriefUserId = NXDataStore.get("CONFIG_SIMBRIEF_USERID", "");
const navigraphUsername = NXDataStore.get("NAVIGRAPH_USERNAME", "");

if (!simBriefUserId) {
mcdu.setScratchpadMessage(NXFictionalMessages.noSimBriefUser);
throw new Error("No SimBrief pilot ID provided");
if (!navigraphUsername) {
mcdu.setScratchpadMessage(NXFictionalMessages.noNavigraphUser);
throw new Error("No Navigraph username provided");
}

mcdu.simbrief["sendStatus"] = "REQUESTING";

updateView();

return SimBriefApi.getSimBriefOfp(simBriefUserId)
return SimBriefApi.getSimBriefOfp(navigraphUsername)
.then(data => {
mcdu.simbrief["units"] = data.params.units;
mcdu.simbrief["route"] = data.general.route;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2021-2023 FlyByWire Simulations
//
// SPDX-License-Identifier: GPL-3.0

class McduMessage {
constructor(text, isAmber = false, replace = "") {
this.text = text;
Expand Down Expand Up @@ -102,7 +106,7 @@ const NXSystemMessages = {
};

const NXFictionalMessages = {
noSimBriefUser: new TypeIMessage("NO SIMBRIEF USER"),
noNavigraphUser: new TypeIMessage("NO NAVIGRAPH USER"),
noAirportSpecified: new TypeIMessage("NO AIRPORT SPECIFIED"),
fltNbrInUse: new TypeIMessage("FLT NBR IN USE"),
fltNbrMissing: new TypeIMessage("ENTER ATC FLT NBR"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright (c) 2021-2023 FlyByWire Simulations
//
// SPDX-License-Identifier: GPL-3.0

class SimBriefApi {
static getSimBriefOfp(userId) {
if (userId) {
return fetch(`${SimBriefApi.url}&userid=${userId}`)
return fetch(`${SimBriefApi.url}&username=${userId}`)
.then((response) => {
if (!response.ok) {
throw new HttpError(response.status);
Expand All @@ -10,7 +14,7 @@ class SimBriefApi {
return response.json();
});
} else {
throw new Error("No SimBrief pilot ID provided");
throw new Error("No Navigraph username provided");
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions fbw-a32nx/src/localization/flypad/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@
},
"Navigraph": {
"AirportDoesNotExist": "Airport Does Not Exist",
"GoToThirdPartyOptions": {
"Title": "Go to 3rd Party Options to link Navigraph account",
"Button": "3rd Party Options"
},
"AuthenticateWithNavigraph": "Authenticate with Navigraph",
"InsufficientEnv": "Insufficient .env File",
"IntoYourBrowserAndEnterTheCodeBelow": "into your browser and enter the code below\n",
Expand Down Expand Up @@ -574,6 +578,23 @@
"inHg": "inHg"
},
"ThirdPartyOptions": {
"TT": {
"OverrideSimBriefUserID": "Alternative SimBrief user ID to use instead of the linked Navigraph Account"
},
"NavigraphAccountLink": {
"SettingTitle": "Navigraph Account Link",
"Connected": "Connected",
"Link": "Link Account",
"Unlink": "Unlink Account",
"SubscriptionStatus": {
"None": "None",
"Unlimited": "Navigraph Unlimited"
},
"LoginPage": {
"Title": "Navigraph Account Login"
}
},
"OverrideSimBriefUserID": "Override SimBrief User ID",
"GsxFuelEnabled": "GSX Fueling Synchronization",
"GsxPayloadEnabled": "GSX Payload Synchronization",
"Title": "3rd Party Options"
Expand Down
2 changes: 1 addition & 1 deletion fbw-a32nx/src/systems/extras-host/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const isProductionBuild = process.env.A32NX_PRODUCTION_BUILD === '1';
esbuild.build({
absWorkingDir: __dirname,

define: { DEBUG: 'false' },
define: { 'DEBUG': 'false', 'process.env.CLIENT_ID': `'${process.env.CLIENT_ID}'`, 'process.env.CLIENT_SECRET': `'${process.env.CLIENT_SECRET}'` },

entryPoints: ['./index.ts'],
bundle: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,42 @@ import React, { useEffect, useState } from 'react';
import { CloudArrowDown, ShieldLock } from 'react-bootstrap-icons';
import { toast } from 'react-toastify';
import QRCode from 'qrcode.react';
import { usePersistentProperty } from '@flybywiresim/fbw-sdk';
import { NavigraphClient, NavigraphSubscriptionStatus, usePersistentProperty } from '@flybywiresim/fbw-sdk';
import { useHistory } from 'react-router-dom';
import { t } from '../../../translation';
import NavigraphClient, { useNavigraph } from '../Navigraph';
import { useNavigraph } from '../Navigraph';

export type NavigraphAuthInfo = {
loggedIn: false,
} | {
loggedIn: true,

username: string,

subscriptionStatus: NavigraphSubscriptionStatus,
}

export const useNavigraphAuthInfo = (): NavigraphAuthInfo => {
const navigraph = useNavigraph();

const [tokenAvail, setTokenAvail] = useState(false);
const [subscriptionStatus, setSubscriptionStatus] = useState<NavigraphSubscriptionStatus>(NavigraphSubscriptionStatus.None);

useInterval(() => {
if ((tokenAvail !== navigraph.hasToken) && navigraph.hasToken) {
navigraph.subscriptionStatus().then(setSubscriptionStatus);
} else if (!navigraph.hasToken) {
setSubscriptionStatus(NavigraphSubscriptionStatus.None);
}

setTokenAvail(navigraph.hasToken);
}, 1000, { runOnStart: true });

if (tokenAvail) {
return { loggedIn: tokenAvail, username: navigraph.userName, subscriptionStatus };
}
return { loggedIn: false };
};

const Loading = () => {
const navigraph = useNavigraph();
Expand Down Expand Up @@ -86,7 +119,7 @@ export const NavigraphAuthUI = () => {
}, []);

return (
<div className="flex overflow-x-hidden justify-center items-center p-6 w-full h-content-section-reduced bg-theme-accent rounded-lg">
<div className="flex overflow-x-hidden justify-center items-center p-6 w-full h-full bg-theme-accent rounded-lg">
<div className="flex flex-col justify-center items-center">
<ShieldLock className="mr-2" size={40} />

Expand Down Expand Up @@ -126,29 +159,70 @@ export const NavigraphAuthUI = () => {
);
};

export const NavigraphAuthUIWrapper = (props) => {
const { children } = props;
export interface NavigraphAuthUIWrapperProps {
showLogin: boolean,
onSuccessfulLogin?: () => void,
}

export const NavigraphAuthUIWrapper: React.FC<NavigraphAuthUIWrapperProps> = ({ showLogin, onSuccessfulLogin, children }) => {
const [tokenAvail, setTokenAvail] = useState(false);

const navigraph = useNavigraph();

useInterval(() => {
if (!tokenAvail && navigraph.hasToken) {
onSuccessfulLogin?.();
}

setTokenAvail(navigraph.hasToken);
}, 1000, { runOnStart: true });

let ui: React.ReactNode;
if (tokenAvail) {
ui = children;
} else if (showLogin) {
ui = <NavigraphAuthUI />;
} else {
ui = <NavigraphAuthRedirectUI />;
}

return (
NavigraphClient.hasSufficientEnv
? (
<>
{tokenAvail
? children
: <NavigraphAuthUI />}
{ui}
</>
)
: (
<div className="flex overflow-x-hidden justify-center items-center mr-4 w-full h-content-section-reduced rounded-lg bh-theme-secondard">
<p className="pt-6 mb-6 text-3xl">Insufficient .env file</p>
<div className="flex overflow-x-hidden justify-center items-center mr-4 w-full h-content-section-reduced">
<p className="pt-6 mb-6 text-3xl">{t('NavigationAndCharts.Navigraph.InsufficientEnv')}</p>
</div>
)
);
};

export const NavigraphAuthRedirectUI = () => {
const history = useHistory();

const handleGoToThirdPArtySettings = () => {
history.push('/settings/3rd-party-options');
};

return (
<div className="flex justify-center items-center h-content-section-reduced rounded-lg border-2 border-theme-accent">
<div className="flex flex-col justify-center items-center space-y-4">
<h1>{t('NavigationAndCharts.Navigraph.GoToThirdPartyOptions.Title')}</h1>

<button
type="button"
className="flex justify-center items-center py-2 space-x-4 w-52 text-theme-body
hover:text-theme-highlight bg-theme-highlight hover:bg-theme-body rounded-md border-2
border-theme-highlight transition duration-100"
onClick={handleGoToThirdPArtySettings}
>
{t('NavigationAndCharts.Navigraph.GoToThirdPartyOptions.Button')}
</button>
</div>
</div>
);
};
Loading

0 comments on commit 72e7629

Please sign in to comment.