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: read config json from documents dir #478

Merged
merged 15 commits into from
Oct 14, 2024
555 changes: 553 additions & 2 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/renderer/components/AddonSection/Configure/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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;
Expand Down Expand Up @@ -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
7 changes: 6 additions & 1 deletion src/renderer/components/AddonSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,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 @@ -464,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
19 changes: 15 additions & 4 deletions src/renderer/components/LocalApiConfigEditUI/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { PromptModal, useModals } from '../Modal';
import { Button, ButtonType } from '../Button';
import fs from 'fs';
import path from 'path';
import { Directories } from 'renderer/utils/Directories';
import { Toggle } from '../Toggle';
import { app } from '@electron/remote';
import { Directories } from 'renderer/utils/Directories';

const SIMBRIDGE_DIRECTORY = 'flybywire-externaltools-simbridge';
const LEGACY_SIMBRIDGE_DIRECTORY = 'flybywire-externaltools-simbridge';
const SIMBRIDGE_DIRECTORY = '/FlyByWireSim/Simbridge';

interface LocalApiConfiguration {
server: {
Expand Down Expand Up @@ -36,12 +38,21 @@ const localApiDefaultConfiguration: LocalApiConfiguration = {
};

class LocalApiConfigurationHandler {
private static get legacySimbridgeDirectory(): string {
return path.join(Directories.inInstallLocation(LEGACY_SIMBRIDGE_DIRECTORY));
}

private static get simbridgeDirectory(): string {
return path.join(Directories.inInstallLocation(SIMBRIDGE_DIRECTORY));
return path.join(app.getPath('documents'), SIMBRIDGE_DIRECTORY);
}

private static get simbridgeConfigPath(): string {
return path.join(this.simbridgeDirectory, 'resources', 'properties.json');
const configPath = path.join(this.simbridgeDirectory, 'resources', 'properties.json');
if (fs.existsSync(configPath)) {
return configPath;
}
// TODO remove this after a while once simbridge is released
return path.join(this.legacySimbridgeDirectory, 'resources', 'properties.json');
}

static getConfiguration(): LocalApiConfiguration {
Expand Down
7 changes: 3 additions & 4 deletions src/renderer/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@ export const defaultConfiguration: Configuration = {
},
url: 'https://cdn.flybywiresim.com/addons/simbridge/release/',
isExperimental: false,
description:
'SimBridge is an external app that enables FlyByWire Simulations aircraft to communicate outside your simulator. From remote displays to external terrain display rendering, it is used for a variety of optional features.',
description: `<b><span class="text-utility-amber">&#9888; Note: Starting with version 0.6.0 custom resources like PDF Charts and Company Routes need to be located inside the Documents folder. Please refer to the documentation.</span></b> \n\n SimBridge is an external app that enables FlyByWire Simulations aircraft to communicate outside your simulator. From remote displays to external terrain display rendering, it is used for a variety of optional features.`,
},
],
disallowedRunningExternalApps: ['@/simbridge-app'],
Expand All @@ -363,8 +362,8 @@ export const defaultConfiguration: Configuration = {
directories: [
{
location: {
in: 'package',
path: 'resources',
in: 'documents',
path: 'FlyByWireSim/Simbridge/resources',
},
title: 'Resources',
},
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/utils/Directories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,8 @@ export class Directories {
return false;
}
}

static inDocumentsFolder(targetDir: string): string {
return path.join(app.getPath('documents'), this.sanitize(targetDir));
}
}
2 changes: 1 addition & 1 deletion src/renderer/utils/InstallerConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface ExternalLink {

export interface DirectoryDefinition {
location: {
in: 'community' | 'packageCache' | 'package';
in: 'community' | 'packageCache' | 'package' | 'documents';
path: string;
};
}
Expand Down
Loading