Skip to content

Commit

Permalink
refactor: remove getAircraftType redundant function and clean up 'a32…
Browse files Browse the repository at this point in the history
…nx' to use environ
  • Loading branch information
2hwk committed Mar 31, 2024
1 parent ab80852 commit 1c15838
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 43 deletions.
4 changes: 2 additions & 2 deletions fbw-a32nx/src/systems/extras-host/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class ExtrasHost extends BaseInstrument {
this.notificationManager = new NotificationManager();

this.pushbuttonCheck = new PushbuttonCheck(this.bus, this.notificationManager);
this.versionCheck = new VersionCheck(this.bus);
this.keyInterceptor = new KeyInterceptor(this.bus, this.notificationManager);
this.aircraftSync = new AircraftSync(this.bus);
this.versionCheck = new VersionCheck(process.env.AIRCRAFT_PROJECT_PREFIX, this.bus);
this.aircraftSync = new AircraftSync(process.env.AIRCRAFT_PROJECT_PREFIX, this.bus);

console.log('A32NX_EXTRASHOST: Created');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EventBus } from '@microsoft/msfs-sdk';
export class AircraftSync {
public xmlConfig: Document

constructor(private readonly bus: EventBus) {
constructor(private readonly aircraftProjectPrefix: string, private readonly bus: EventBus) {
console.log('AircraftSync: Created');
}

Expand All @@ -22,6 +22,8 @@ export class AircraftSync {
this.xmlConfig = xmlConfig;
}

// TODO: Remove this sync when VFS config is done.
// Replace with new function for commbus implementation to sync VFS markup config to WASM
public startPublish(): void {
console.log('AicraftSync: startPublish()');

Expand All @@ -33,10 +35,8 @@ export class AircraftSync {
aircraftType = AircraftType.A380_842;
break;
case 'A320_251N':
aircraftType = AircraftType.A320_251N;
break;
default:
aircraftType = AircraftType.Unknown;
aircraftType = AircraftType.A320_251N;
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// SPDX-License-Identifier: GPL-3.0

import { EventBus } from '@microsoft/msfs-sdk';
import { AircraftVersionChecker } from '@fbw-common/shared/AircraftVersionChecker';
import { AircraftGithubVersionChecker } from '@fbw-common/shared/AircraftGithubVersionChecker';

/**
* This class is used to check the version of the aircraft and display a warning if it is too old.
*/
export class VersionCheck {
constructor(private readonly bus: EventBus) {
constructor(private readonly aircraftProjectPrefix: string, private readonly bus: EventBus) {
console.log('VersionCheck: Created');
}

Expand All @@ -18,7 +18,7 @@ export class VersionCheck {

public startPublish(): void {
console.log('VersionCheck: startPublish()');
AircraftVersionChecker.checkVersion('a32nx');
AircraftGithubVersionChecker.checkVersion(this.aircraftProjectPrefix);
}

public update(): void {
Expand Down
2 changes: 1 addition & 1 deletion fbw-a32nx/src/systems/instruments/src/Common/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const render = (Slot: React.ReactElement, enableSentryTracing = false, se
const doRender = () => {
new FbwAircraftSentryClient().onInstrumentLoaded({
dsn: process.env.SENTRY_DSN,
buildInfoFilePrefix: 'a32nx',
buildInfoFilePrefix: process.env.AIRCRAFT_PROJECT_PREFIX,
enableTracing: enableSentryTracing,
root: sentryRootClient,
});
Expand Down
2 changes: 1 addition & 1 deletion fbw-a32nx/src/systems/sentry-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare const process: any;

new FbwAircraftSentryClient().onInstrumentLoaded({
dsn: process.env.SENTRY_DSN,
buildInfoFilePrefix: 'a32nx',
buildInfoFilePrefix: process.env.AIRCRAFT_PROJECT_PREFIX,
root: false,
enableTracing: false,
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023-2024 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0

import { AircraftVersionChecker, getAircraftType } from '@flybywiresim/fbw-sdk';
import { AircraftGithubVersionChecker } from '@flybywiresim/fbw-sdk';
import { ISimbriefData } from './simbriefInterface';

const SIMBRIEF_BASE_URL = 'https://www.simbrief.com/api/xml.fetcher.php';
Expand Down Expand Up @@ -30,7 +30,7 @@ export const getSimbriefData = async (navigraphUsername: string, overrideSimbrie
// will throw an error - if this is fixed (build_info for a380x is readable from the flyPad for the A380X) then
// this try/catch could be removed, but it doesn't hurt to have it here even then as an extra safety measure
try {
const versionInfo = await AircraftVersionChecker.getBuildInfo(getAircraftType());
const versionInfo = await AircraftGithubVersionChecker.getBuildInfo(process.env.AIRCRAFT_PROJECT_PREFIX);
simbriefApiParams.append('client', `fbw-${versionInfo.version}`);
} catch (e) {
console.error('Error getting build info', e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0

import React, { useEffect, useState } from 'react';
import { usePersistentProperty, useSessionStorage, AircraftVersionChecker, BuildInfo, SentryConsentState, SENTRY_CONSENT_KEY, useSimVar, AircraftInfo } from '@flybywiresim/fbw-sdk';
import { usePersistentProperty, useSessionStorage, AircraftGithubVersionChecker, BuildInfo, SentryConsentState, SENTRY_CONSENT_KEY, useSimVar, AircraftInfo } from '@flybywiresim/fbw-sdk';
import { t } from '@flybywiresim/flypad';
import { SettingsPage } from '../Settings';
// @ts-ignore
Expand Down Expand Up @@ -49,6 +49,7 @@ export const AboutPage = () => {
const [sessionId] = usePersistentProperty('A32NX_SENTRY_SESSION_ID');
const [version, setVersion] = useSessionStorage('SIM_VERSION', '');
const [sentryEnabled] = usePersistentProperty(SENTRY_CONSENT_KEY, SentryConsentState.Refused);
const [aircraftInfo, setAircraftInfo] = useState<AircraftInfo | undefined>(undefined);

// Callback function to set sBuildVersion from the community panel
const onSetPlayerData = (data: CommunityPanelPlayerData) => {
Expand All @@ -59,7 +60,7 @@ export const AboutPage = () => {
useViewListenerEvent('JS_LISTENER_COMMUNITY', 'SetGamercardInfo', onSetPlayerData);

useEffect(() => {
AircraftVersionChecker.getBuildInfo(
AircraftGithubVersionChecker.getBuildInfo(
process.env.AIRCRAFT_PROJECT_PREFIX,
).then((info) => setBuildInfo(info));
}, [process.env.AIRCRAFT_PROJECT_PREFIX]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export enum KnowBranchNames {
* Provides functions to the check the version of the aircraft against the
* published GitHub version
*/
export class AircraftVersionChecker {
export class AircraftGithubVersionChecker {
private static notification: NotificationManager;

private static versionChecked = false;
Expand All @@ -69,7 +69,7 @@ export class AircraftVersionChecker {
* @returns true if the aircraft version has been checked, false if no check has been commenced.
*/
public static async checkVersion(aircraft: string): Promise<boolean> {
console.log('Checking aircraft version');
console.log(`Checking aircraft version for A/C project: ${aircraft}`);

this.notification = new NotificationManager();

Expand All @@ -90,9 +90,9 @@ export class AircraftVersionChecker {
const versionInfo = this.getVersionInfo(this.buildInfo.version);
if (this.checkOutdated(versionInfo)) {
this.setOutdatedVersionFlag(true);
console.log('Aircraft version outdated');
console.log(`Aircraft ${aircraft} - version outdated`);
} else {
console.log('Aircraft version ok');
console.log(`Aircraft ${aircraft} - version ok`);
}
this.versionChecked = true;
} catch (error) {
Expand Down Expand Up @@ -176,7 +176,7 @@ export class AircraftVersionChecker {
this.releaseInfo = await GitVersions.getReleases('flybywiresim', aircraft, false, 0, 1);
this.newestCommit = await GitVersions.getNewestCommit('flybywiresim', aircraft, 'master');
this.newestExpCommit = await GitVersions.getNewestCommit('flybywiresim', aircraft, 'experimental');
this.buildInfo = await AircraftVersionChecker.getBuildInfo(aircraft);
this.buildInfo = await AircraftGithubVersionChecker.getBuildInfo(aircraft);
}

/**
Expand Down
23 changes: 0 additions & 23 deletions fbw-common/src/systems/shared/src/aircraftTypeCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,3 @@ export enum AircraftType {
A320_251N = 1,
A380_842 = 2
}

/**
* Determine the aircraft type using the Aircraft Title SimVar.
* @returns {string} - the aircraft type (a32nx, a380x, other)
*/
export function getAircraftType(): string {
const aircraftType: AircraftType = SimVar.GetSimVarValue('L:A32NX_AIRCRAFT_TYPE', 'enum');
let aircraft: string;

switch (aircraftType) {
case AircraftType.A320_251N:
aircraft = 'a32nx';
break;
case AircraftType.A380_842:
aircraft = 'a380x';
break;
case AircraftType.Unknown:
default:
aircraft = 'other';
}

return aircraft;
}

0 comments on commit 1c15838

Please sign in to comment.