Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remote displays app and PR CI #114

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
implement instrument closing
  • Loading branch information
Benjozork committed May 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 66bff9c790f745a5b825026453c11cb5aefd9ced
32 changes: 16 additions & 16 deletions apps/remote/src/FlightStatusBar.tsx
Original file line number Diff line number Diff line change
@@ -15,24 +15,10 @@ export const FlightStatusBar: React.FC<FlightStatusProps> = ({ dropdownOpen, onT

return (
<div
className={`w-full sm:w-[420px] h-12 bg-navy border-2 border-t-0 border-navy-light sm:rounded-b-md text-white mx-auto px-5 flex flex-row items-center gap-x-2.5 transition-all duration-300`}
className={`w-full sm:w-[440px] h-12 bg-navy border-2 border-t-0 border-navy-light sm:rounded-b-md text-white mx-auto px-5 flex flex-row items-center gap-x-2.5 transition-all duration-300`}
>
<span className="w-48 flex-grow flex flex-row items-center gap-x-2 overflow-hidden">
<span className="font-manrope">{flightStatus.airframe.name}</span>
<span className="font-manrope">{flightStatus.airframe.livery}</span>
</span>

<span
className={
'w-20 bg-navy-lightest hover:bg-navy-lighter self-stretch flex flex-col justify-center items-center transition-colors duration-300 cursor-pointer'
}
onClick={onToggleDropdown}
>
<ChevronDown size={22} className={`transition-transform duration-300 ${dropdownOpen ? 'rotate-180' : ''}`} />
</span>

<span
className={`w-48 flex-grow flex justify-end items-center gap-x-1.5 ${
className={`w-52 flex-grow flex items-center gap-x-1.5 ${
connectionState.connected === ConnectionPhase.ConnectedToAircraft
? 'text-green-500 animate-pulse'
: connectionState.connected === ConnectionPhase.ConnectedToBridge
@@ -48,6 +34,20 @@ export const FlightStatusBar: React.FC<FlightStatusProps> = ({ dropdownOpen, onT
? 'Waiting on aircraft'
: 'Not connected'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: 'Not connected'}
: 'Simbridge Connection Lost'}

</span>

<span
className={
'w-20 bg-navy-lightest hover:bg-navy-lighter self-stretch flex flex-col justify-center items-center transition-colors duration-300 cursor-pointer'
}
onClick={onToggleDropdown}
>
<ChevronDown size={22} className={`transition-transform duration-300 ${dropdownOpen ? 'rotate-180' : ''}`} />
</span>

<span className="w-52 flex-grow flex flex-row justify-center items-center gap-x-2 overflow-hidden">
<span className="font-manrope">{flightStatus.airframe.name}</span>
<span className="font-manrope">{flightStatus.airframe.livery}</span>
</span>
</div>
);
};
46 changes: 34 additions & 12 deletions apps/remote/src/MainView.tsx
Original file line number Diff line number Diff line change
@@ -104,6 +104,9 @@ const MainView: React.FC<MainViewProps> = ({ client }) => {
return;
}

iframeRef.current.style.width = '0px';
iframeRef.current.style.height = '0px';

const iframeWindow = iframeRef.current.contentWindow!;

iframeWindow.location.reload();
@@ -222,7 +225,7 @@ const MainView: React.FC<MainViewProps> = ({ client }) => {
}, [resizeIframe, loadedInstrument]);

const handleLoadInstrument = useCallback(
async (instrument: protocolV0.InstrumentMetadata) => {
async (instrument: protocolV0.InstrumentMetadata | null) => {
await resetIframe();

dispatch(clearSimVars());
@@ -233,16 +236,21 @@ const MainView: React.FC<MainViewProps> = ({ client }) => {
client.cancelSubscriptionGroup(currentSubscriptionGroupID);
}

const jsData = await client.downloadFile(instrument.gauges[0].bundles.js);
const cssData = await client.downloadFile(instrument.gauges[0].bundles.css);
if (instrument) {
const jsData = await client.downloadFile(instrument.gauges[0].bundles.js);
const cssData = await client.downloadFile(instrument.gauges[0].bundles.css);

const jsText = new TextDecoder('utf8').decode(jsData);
const cssText = new TextDecoder('utf8').decode(cssData);
const jsText = new TextDecoder('utf8').decode(jsData);
const cssText = new TextDecoder('utf8').decode(cssData);

dispatch(setLoadedInstrument(instrument));
dispatch(setCurrentSubscriptionGroupID(v4()));
dispatch(setLoadedInstrument(instrument));
dispatch(setCurrentSubscriptionGroupID(v4()));

runCodeInIframe(jsText, cssText, instrument.dimensions.width, instrument.dimensions.height);
runCodeInIframe(jsText, cssText, instrument.dimensions.width, instrument.dimensions.height);
} else {
dispatch(setLoadedInstrument(null));
dispatch(setCurrentSubscriptionGroupID(null));
}
},
[client, dispatch, runCodeInIframe],
);
@@ -288,7 +296,6 @@ const MainView: React.FC<MainViewProps> = ({ client }) => {
onFullScreenToggled={() => setFullScreenOpened((old) => !old)}
handleLoadInstrument={handleLoadInstrument}
/>
{/*<MessagesPanel />*/}
</div>
);
};
@@ -325,7 +332,7 @@ const NoInstrumentLoadedOverlay: React.FC<NoInstrumentLoadedOverlayProps> = ({ o

interface InstrumentFrameProps {
onFullScreenToggled: () => void;
handleLoadInstrument: (instrument: protocolV0.InstrumentMetadata) => void;
handleLoadInstrument: (instrument: protocolV0.InstrumentMetadata | null) => void;
}

const InstrumentFrame = forwardRef<HTMLIFrameElement, InstrumentFrameProps>(
@@ -379,7 +386,17 @@ const InstrumentFrame = forwardRef<HTMLIFrameElement, InstrumentFrameProps>(
ref.current.style.transform = `scale(${
1 / Math.max(ref.current.clientWidth / window.innerWidth, ref.current.clientHeight / window.innerHeight)
})`;
// ref.current.style.margin = '0 auto';

// Evaluate this the next frame so that we get the fullscreen dimensions
setTimeout(() => {
if (!ref.current) {
return;
}

ref.current.style.marginLeft = `${
window.innerWidth / 2 - ref.current?.getBoundingClientRect().width / 2
}px`;
});
} else {
ref.current.style.transform = '';
ref.current.style.margin = '';
@@ -407,6 +424,10 @@ const InstrumentFrame = forwardRef<HTMLIFrameElement, InstrumentFrameProps>(
elm?.requestFullscreen();
};

const handleClearInstrument = () => {
handleLoadInstrument(null);
};

const connectionLost = connectionState === ConnectionPhase.ConnectedToBridge;

return (
@@ -416,7 +437,7 @@ const InstrumentFrame = forwardRef<HTMLIFrameElement, InstrumentFrameProps>(
<div className="absolute w-0 h-full -left-12">
<div className="h-full w-12 bg-navy px-3 py-4 flex flex-col items-center rounded-l-md">
<span className={`text-xl vertical-writing-lr rotate-180 ${!loadedInstrument ? 'opacity-40' : ''}`}>
-{loadedInstrument?.instrumentID ?? '-----'}
{loadedInstrument?.instrumentID ?? '-----'}
</span>

<Fullscreen
@@ -432,6 +453,7 @@ const InstrumentFrame = forwardRef<HTMLIFrameElement, InstrumentFrameProps>(
className={`mt-4 hover:text-cyan hover:cursor-pointer ${
!loadedInstrument ? 'opacity-40 pointer-events-none' : ''
}`}
onClick={handleClearInstrument}
/>
</div>
</div>
2 changes: 1 addition & 1 deletion apps/remote/src/store/connection.ts
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ export const connectionStateSlice = createSlice({
clientName !== undefined && (state.clientName = clientName);
bridgeName !== undefined && (state.bridgeName = bridgeName);
},
setCurrentSubscriptionGroupID: (state, action: PayloadAction<string>) => {
setCurrentSubscriptionGroupID: (state, action: PayloadAction<string | null>) => {
state.currentSubscriptionGroupID = action.payload;
},
},