Skip to content

Commit

Permalink
Merge branch 'master' into fix/dont-show-this-again-toggle-bug-460
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoOliveira85 authored Oct 23, 2024
2 parents fa9397e + bf58f63 commit 6fe91be
Show file tree
Hide file tree
Showing 17 changed files with 924 additions and 456 deletions.
575 changes: 563 additions & 12 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fbw-installer",
"productName": "FlyByWire Installer",
"version": "3.4.0-dev.1",
"version": "3.4.2-dev.1",
"description": "Desktop application to install and customize FlyByWire addons",
"configUrls": {
"production": "https://cdn.flybywiresim.com/installer/config/production.json",
Expand Down Expand Up @@ -103,7 +103,7 @@
"webpack-dev-server": "^4.4.0"
},
"dependencies": {
"@flybywiresim/fragmenter": "^0.7.4",
"@flybywiresim/fragmenter": "^0.8.0",
"@reduxjs/toolkit": "^1.7.1",
"@sentry/cli": "^2.31.0",
"@sentry/electron": "^4.23.0",
Expand All @@ -123,7 +123,7 @@
"js-yaml-loader": "^1.2.2",
"marked": "^2.0.0",
"nanoid": "^4.0.0",
"pdf-to-printer": "^5.3.0",
"pdf-to-printer": "5.3.0",
"raw-loader": "^4.0.2",
"react": "^17.0.1",
"react-bootstrap-icons": "^1.8.4",
Expand All @@ -137,6 +137,7 @@
"react-router-dom": "^5.2.0",
"react-windows-controls": "^1.1.1",
"redux": "^4.0.5",
"rehype-raw": "^7.0.0",
"remark-gfm": "^2.0.0",
"semver": "7.3.5",
"simplebar-react": "^3.2.4",
Expand Down
15 changes: 6 additions & 9 deletions src/renderer/components/AddonSection/Configure/TrackSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,25 @@ type TrackProps = {
};

export const Track: React.FC<TrackProps> = ({ isSelected, isInstalled, handleSelected, addon, track }) => {
const latestVersionName = useSelector<InstallerStore, string>(
(state) => state.latestVersionNames[addon.key]?.[track.key]?.name ?? '<unknown>',
const latestVersionName = useSelector<InstallerStore, string | undefined>(
(state) => state.latestVersionNames[addon.key]?.[track.key]?.name,
);

return (
<div
className={twMerge(
`relative flex w-60 cursor-pointer flex-row items-center rounded-sm-md border-2 border-transparent bg-navy-dark text-white transition-all duration-200 hover:border-navy-lightest hover:text-gray-300`,
`flex w-60 h-24 cursor-pointer flex-col rounded-sm-md border-2 border-transparent bg-navy-dark text-white transition-all duration-200 hover:border-navy-lightest hover:text-gray-300`,
isSelected && 'border-2 border-cyan text-cyan',
)}
onClick={() => handleSelected(track)}
>
<div
className={`h-12 w-1 rounded-r-xl transition-all duration-200${isSelected ? 'scale-y-100' : 'scale-y-50'}`}
/>
<div className="flex flex-col px-3 py-2.5">
<span className="text-xl text-current">{track.name}</span>
<span className="mt-0.5 font-manrope text-3xl font-medium tracking-wider text-current">
{latestVersionName}
<span className="mt-0.5 flex justify-between font-manrope text-3xl font-medium tracking-wider text-current">
{latestVersionName ?? <span className="mt-1.5 block h-7 w-32 animate-pulse bg-navy-light"></span>}
{isInstalled && <Check className={`-mt-3.5 stroke-current text-cyan`} strokeWidth={3} />}
</span>
</div>
{isInstalled && <Check className={`absolute right-4 stroke-current text-cyan`} strokeWidth={3} />}
</div>
);
};
14 changes: 8 additions & 6 deletions src/renderer/components/AddonSection/Configure/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { Track, Tracks } from './TrackSelector';
import { ConfigurationAspectDisplay } from 'renderer/components/AddonSection/Configure/ConfigurationAspectDisplay';

import './index.css';
import rehypeRaw from 'rehype-raw';

export interface ConfigureProps {
routeAspectKey: string;
selectedAddon: Addon;
selectedTrack: AddonTrack;
installedTrack: AddonTrack;
selectedTrack: AddonTrack | null;
installedTrack: AddonTrack | null;
onTrackSelection: (track: AddonTrack) => void;
}

Expand Down Expand Up @@ -40,8 +41,8 @@ export const Configure: FC<ConfigureProps> = ({
addon={selectedAddon}
key={track.key}
track={track}
isSelected={selectedTrack === track}
isInstalled={installedTrack === track}
isSelected={selectedTrack?.key === track.key}
isInstalled={installedTrack?.key === track.key}
handleSelected={() => onTrackSelection(track)}
/>
))}
Expand All @@ -57,8 +58,8 @@ export const Configure: FC<ConfigureProps> = ({
addon={selectedAddon}
key={track.key}
track={track}
isSelected={selectedTrack === track}
isInstalled={installedTrack === track}
isSelected={selectedTrack?.key === track.key}
isInstalled={installedTrack?.key === track.key}
handleSelected={() => onTrackSelection(track)}
/>
))}
Expand All @@ -76,6 +77,7 @@ export const Configure: FC<ConfigureProps> = ({
<ReactMarkdown
className="font-manrope text-xl font-light leading-relaxed text-white"
linkTarget={'_blank'}
rehypePlugins={[rehypeRaw]}
>
{selectedTrack.description}
</ReactMarkdown>
Expand Down
9 changes: 9 additions & 0 deletions src/renderer/components/AddonSection/MyInstall/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export const MyInstall: FC<MyInstallProps> = ({ addon }) => {
return Directories.inInstallPackage(addon, def.location.path);
case 'packageCache':
return Directories.inPackageCache(addon, def.location.path);
case 'documents': {
const documents = Directories.inDocumentsFolder(def.location.path);
if (fs.existsSync(documents)) {
return documents;
}
// fallback for simbridge installations prior to 0.6
// remove after transition period
return Directories.inInstallPackage(addon, 'resources');
}
}
};

Expand Down
102 changes: 17 additions & 85 deletions src/renderer/components/AddonSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ import React, { FC, useCallback, useEffect, useState } from 'react';
import { setupInstallPath } from 'renderer/actions/install-path.utils';
import { DownloadItem } from 'renderer/redux/types';
import { useSelector } from 'react-redux';
import { getCurrentInstall } from '@flybywiresim/fragmenter';
import { InstallerStore, useAppDispatch, useAppSelector } from '../../redux/store';
import { Addon, AddonCategoryDefinition, AddonTrack } from 'renderer/utils/InstallerConfiguration';
import { Directories } from 'renderer/utils/Directories';
import { NavLink, Redirect, Route, useHistory, useParams } from 'react-router-dom';
import { Gear, InfoCircle, JournalText, Sliders } from 'react-bootstrap-icons';
import settings, { useSetting } from 'renderer/rendererSettings';
import { ipcRenderer } from 'electron';
import { AddonBar, AddonBarItem } from '../App/AddonBar';
import { NoAvailableAddonsSection } from '../NoAvailableAddonsSection';
import { ReleaseNotes } from './ReleaseNotes';
import { setInstalledTrack } from 'renderer/redux/features/installedTrack';
import { InstallState, setInstallStatus } from 'renderer/redux/features/installStatus';
import { setSelectedTrack } from 'renderer/redux/features/selectedTrack';
import { PromptModal, useModals } from 'renderer/components/Modal';
import ReactMarkdown from 'react-markdown';
Expand All @@ -28,6 +24,7 @@ import { InstallManager } from 'renderer/utils/InstallManager';
import { StateSection } from 'renderer/components/AddonSection/StateSection';
import { ExternalApps } from 'renderer/utils/ExternalApps';
import { MyInstall } from 'renderer/components/AddonSection/MyInstall';
import rehypeRaw from 'rehype-raw';

const abortControllers = new Array<AbortController>(20);
abortControllers.fill(new AbortController());
Expand Down Expand Up @@ -128,13 +125,6 @@ export const AddonSection = (): JSX.Element => {

const installedTrack = (installedTracks[selectedAddon.key] as AddonTrack) ?? null;

const setCurrentlyInstalledTrack = useCallback(
(newInstalledTrack: AddonTrack) => {
dispatch(setInstalledTrack({ addonKey: selectedAddon.key, installedTrack: newInstalledTrack }));
},
[dispatch, selectedAddon.key],
);

const setCurrentlySelectedTrack = useCallback(
(newSelectedTrack: AddonTrack) => {
dispatch(setSelectedTrack({ addonKey: selectedAddon.key, track: newSelectedTrack }));
Expand All @@ -144,79 +134,12 @@ export const AddonSection = (): JSX.Element => {

const selectedTrack = (selectedTracks[selectedAddon.key] as AddonTrack) ?? null;

const selectAndSetTrack = useCallback(
(key: string) => {
const newTrack = selectedAddon.tracks.find((track) => track.key === key);
setCurrentlySelectedTrack(newTrack);
},
[selectedAddon.tracks, setCurrentlySelectedTrack],
);

const getCurrentInstallStatus = (): InstallState => {
try {
return installStates[selectedAddon.key];
} catch (e) {
setCurrentInstallStatus({ status: InstallStatus.Unknown });
return { status: InstallStatus.Unknown };
}
};

const setCurrentInstallStatus = useCallback(
(new_state: InstallState) => {
dispatch(setInstallStatus({ addonKey: selectedAddon.key, installState: new_state }));
},
[dispatch, selectedAddon.key],
);

const findInstalledTrack = useCallback((): AddonTrack => {
if (!Directories.isFragmenterInstall(selectedAddon)) {
console.log('Not installed');
if (selectedTrack) {
selectAndSetTrack(selectedTrack.key);
return selectedTrack;
} else {
setCurrentlySelectedTrack(selectedAddon.tracks[0]);
return selectedAddon.tracks[0];
}
}

try {
const manifest = getCurrentInstall(Directories.inInstallLocation(selectedAddon.targetDirectory));
console.log('Currently installed', manifest);

let track = selectedAddon.tracks.find((track) => track.url.includes(manifest.source));
if (!track) {
track = selectedAddon.tracks.find((track) => track.alternativeUrls?.includes(manifest.source));
}

console.log('Currently installed', track);
setCurrentlyInstalledTrack(track);
if (selectedTrack) {
selectAndSetTrack(selectedTrack.key);
return selectedTrack;
} else {
setCurrentlySelectedTrack(track);
return track;
}
} catch (e) {
console.error(e);
console.log('Not installed');
if (selectedTrack) {
selectAndSetTrack(selectedTrack.key);
return selectedTrack;
} else {
setCurrentlySelectedTrack(selectedAddon.tracks[0]);
return selectedAddon.tracks[0];
}
}
}, [selectAndSetTrack, selectedAddon, selectedTrack, setCurrentlyInstalledTrack, setCurrentlySelectedTrack]);

const download: DownloadItem = useSelector((state: InstallerStore) =>
state.downloads.find((download) => download.id === selectedAddon.key),
);

const isDownloading = download?.progress.totalPercent >= 0;
const status = getCurrentInstallStatus()?.status;
const status = installStates[selectedAddon.key]?.status;
const isInstalling = InstallStatusCategories.installing.includes(status);
const isFinishingDependencyInstall = status === InstallStatus.InstallingDependencyEnding;

Expand Down Expand Up @@ -254,11 +177,10 @@ export const AddonSection = (): JSX.Element => {
}, [dispatch, publisherData, selectedAddon]);

useEffect(() => {
findInstalledTrack();
if (!isInstalling) {
InstallManager.determineAddonInstallState(selectedAddon).then(setCurrentInstallStatus);
void InstallManager.refreshAddonInstallState(selectedAddon);
}
}, [findInstalledTrack, isInstalling, selectedAddon, setCurrentInstallStatus]);
}, [isInstalling, selectedAddon]);

useEffect(() => {
if (download && isDownloading) {
Expand Down Expand Up @@ -287,13 +209,19 @@ export const AddonSection = (): JSX.Element => {
bodyText={track.warningContent}
confirmColor={ButtonType.Caution}
onConfirm={() => {
selectAndSetTrack(track.key);
setCurrentlySelectedTrack(track);

// Update install state
void InstallManager.refreshAddonInstallState(selectedAddon);
}}
dontShowAgainSettingName="mainSettings.disableExperimentalWarning"
/>,
);
} else {
selectAndSetTrack(track.key);
setCurrentlySelectedTrack(track);

// Update install state
void InstallManager.refreshAddonInstallState(selectedAddon);
}
}
};
Expand Down Expand Up @@ -537,7 +465,11 @@ const About: FC<{ addon: Addon }> = ({ addon }) => (

<h2 className="text-white">{addon.aircraftName}</h2>
</div>
<ReactMarkdown className="font-manrope text-xl font-light leading-relaxed text-white" linkTarget={'_blank'}>
<ReactMarkdown
className="font-manrope text-xl font-light leading-relaxed text-white"
linkTarget={'_blank'}
rehypePlugins={[rehypeRaw]}
>
{addon.description}
</ReactMarkdown>

Expand Down
Loading

0 comments on commit 6fe91be

Please sign in to comment.