Skip to content

Commit 2d8906f

Browse files
authored
Merge pull request #3 from Navigraph/bundled-navigation-data
2 parents 401b2ce + 312d3e1 commit 2d8906f

27 files changed

+763
-196
lines changed

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
run: npm ci
4747

4848
- name: Run linting
49-
run: npm run lint:js -- -- --max-warnings 0
49+
run: npm run lint:js -- --max-warnings 0
5050

5151
build-test:
5252
name: Build & test 🛠️

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ Here's an overview on the structure of this repository, which is designed to be
3030
```
3131
- Note that if you already have a `VCockpit` with `NO_TEXTURE` you can just add another `htmlgauge` to it, while making sure to increase the index
3232

33+
## Dealing with Bundled Navigation Data
34+
35+
If you bundle outdated navigation data in your aircraft and you want this module to handle updating it for users with subscriptions, place the navigation data into the `NavigationData` directory in `PackageSources`. You can see an example [here](examples/aircraft/PackageSources/NavigationData/)
36+
37+
## Where is the Navigation Data Stored?
38+
39+
The default location for navigation data is `work/NavigationData`. If you have bundled navigation data, its located in the `NavigationData` folder in the root of your project. (although it gets copied into the `work` directory at runtime)
40+
3341
## Building the Sample Aircraft
3442

3543
Before building, make sure you have properly created and set an `.env` file in `examples/gauge`! An example can be found in the `.env.example` file in that directory. Replace with your credentials
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project Version="2" Name="NavigationDataInterfaceAircraftProject" FolderName="Packages" PublishingGroupFolderName="PublishingGroupsContent" MetadataFolderName="PackagesMetadata" PublishingGroupMetadataFolderName="PublishingGroupsMetadata">
3-
<OutputDirectory>.</OutputDirectory>
4-
<TemporaryOutputDirectory>_PackageInt</TemporaryOutputDirectory>
5-
<PublishingGroupTemporaryOutputDirectory>_PublishingGroupInt</PublishingGroupTemporaryOutputDirectory>
6-
<Packages>
7-
<Package>PackageDefinitions\navigraph-aircraft-navigation-data-interface-sample.xml</Package>
8-
</Packages>
9-
<PublishingGroups/>
10-
</Project>
11-
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Version="2" Name="NavigationDataInterfaceAircraftProject" FolderName="Packages" PublishingGroupFolderName="PublishingGroupsContent" MetadataFolderName="PackagesMetadata" PublishingGroupMetadataFolderName="PublishingGroupsMetadata">
3+
<OutputDirectory>.</OutputDirectory>
4+
<TemporaryOutputDirectory>_PackageInt</TemporaryOutputDirectory>
5+
<PublishingGroupTemporaryOutputDirectory>_PublishingGroupInt</PublishingGroupTemporaryOutputDirectory>
6+
<Packages>
7+
<Package>PackageDefinitions\navigraph-aircraft-navigation-data-interface-sample.xml</Package>
8+
</Packages>
9+
<PublishingGroups/>
10+
</Project>
11+
Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,56 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<AssetPackage Version="0.1.0">
3-
<ItemSettings>
4-
<ContentType>AIRCRAFT</ContentType>
5-
<Title>Navigraph Navigation Data Interface Sample Aircraft</Title>
6-
<Manufacturer>My Manufacturer</Manufacturer>
7-
<Creator>Navigraph</Creator>
8-
</ItemSettings>
9-
<Flags>
10-
<VisibleInStore>true</VisibleInStore>
11-
<CanBeReferenced>true</CanBeReferenced>
12-
</Flags>
13-
<AssetGroups>
14-
<AssetGroup Name="ContentInfo">
15-
<Type>Copy</Type>
16-
<Flags>
17-
<FSXCompatibility>false</FSXCompatibility>
18-
</Flags>
19-
<AssetDir>PackageDefinitions\navigraph-aircraft-navigation-data-interface-sample\ContentInfo\</AssetDir>
20-
<OutputDir>ContentInfo\navigraph-aircraft-navigation-data-interface-sample\</OutputDir>
21-
</AssetGroup>
22-
<AssetGroup Name="Data">
23-
<Type>Copy</Type>
24-
<Flags>
25-
<FSXCompatibility>false</FSXCompatibility>
26-
</Flags>
27-
<AssetDir>PackageSources\Data\</AssetDir>
28-
<OutputDir>Data\</OutputDir>
29-
</AssetGroup>
30-
<AssetGroup Name="SimObject">
31-
<Type>SimObject</Type>
32-
<Flags>
33-
<FSXCompatibility>false</FSXCompatibility>
34-
</Flags>
35-
<AssetDir>PackageSources\SimObjects\Airplanes\Navigraph_Navigation_Data_Interface_Aircraft\</AssetDir>
36-
<OutputDir>SimObjects\Airplanes\Navigraph_Navigation_Data_Interface_Aircraft\</OutputDir>
37-
</AssetGroup>
38-
<AssetGroup Name="html_ui">
39-
<Type>Copy</Type>
40-
<Flags>
41-
<FSXCompatibility>false</FSXCompatibility>
42-
</Flags>
43-
<AssetDir>PackageSources\html_ui\</AssetDir>
44-
<OutputDir>html_ui\</OutputDir>
45-
</AssetGroup>
46-
</AssetGroups>
47-
</AssetPackage>
48-
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<AssetPackage Version="0.1.0">
3+
<ItemSettings>
4+
<ContentType>AIRCRAFT</ContentType>
5+
<Title>Navigraph Navigation Data Interface Sample Aircraft</Title>
6+
<Manufacturer>My Manufacturer</Manufacturer>
7+
<Creator>Navigraph</Creator>
8+
</ItemSettings>
9+
<Flags>
10+
<VisibleInStore>true</VisibleInStore>
11+
<CanBeReferenced>true</CanBeReferenced>
12+
</Flags>
13+
<AssetGroups>
14+
<AssetGroup Name="ContentInfo">
15+
<Type>Copy</Type>
16+
<Flags>
17+
<FSXCompatibility>false</FSXCompatibility>
18+
</Flags>
19+
<AssetDir>PackageDefinitions\navigraph-aircraft-navigation-data-interface-sample\ContentInfo\</AssetDir>
20+
<OutputDir>ContentInfo\navigraph-aircraft-navigation-data-interface-sample\</OutputDir>
21+
</AssetGroup>
22+
<AssetGroup Name="Data">
23+
<Type>Copy</Type>
24+
<Flags>
25+
<FSXCompatibility>false</FSXCompatibility>
26+
</Flags>
27+
<AssetDir>PackageSources\Data\</AssetDir>
28+
<OutputDir>Data\</OutputDir>
29+
</AssetGroup>
30+
<AssetGroup Name="NavigationData">
31+
<Type>Copy</Type>
32+
<Flags>
33+
<FSXCompatibility>false</FSXCompatibility>
34+
</Flags>
35+
<AssetDir>PackageSources\NavigationData\</AssetDir>
36+
<OutputDir>NavigationData\</OutputDir>
37+
</AssetGroup>
38+
<AssetGroup Name="SimObject">
39+
<Type>SimObject</Type>
40+
<Flags>
41+
<FSXCompatibility>false</FSXCompatibility>
42+
</Flags>
43+
<AssetDir>PackageSources\SimObjects\Airplanes\Navigraph_Navigation_Data_Interface_Aircraft\</AssetDir>
44+
<OutputDir>SimObjects\Airplanes\Navigraph_Navigation_Data_Interface_Aircraft\</OutputDir>
45+
</AssetGroup>
46+
<AssetGroup Name="html_ui">
47+
<Type>Copy</Type>
48+
<Flags>
49+
<FSXCompatibility>false</FSXCompatibility>
50+
</Flags>
51+
<AssetDir>PackageSources\html_ui\</AssetDir>
52+
<OutputDir>html_ui\</OutputDir>
53+
</AssetGroup>
54+
</AssetGroups>
55+
</AssetPackage>
56+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"cycle":"2101","revision":"1","name":"Navigraph Avionics", "format": "dfd", "validityPeriod": "2021-01-25/2021-02-20"}
Binary file not shown.

examples/gauge/Components/InterfaceSample.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
2222
private readonly dropdownRef = FSComponent.createRef<Dropdown>()
2323
private readonly downloadButtonRef = FSComponent.createRef<HTMLButtonElement>()
2424
private readonly executeButtonRef = FSComponent.createRef<HTMLButtonElement>()
25-
private readonly setActiveButtonRef = FSComponent.createRef<HTMLButtonElement>()
2625
private readonly inputRef = FSComponent.createRef<HTMLInputElement>()
2726

2827
private cancelSource = CancelToken.source()
@@ -69,9 +68,6 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
6968
<div ref={this.downloadButtonRef} class="button">
7069
Download
7170
</div>
72-
<div ref={this.setActiveButtonRef} class="button">
73-
Set as Active
74-
</div>
7571
<input ref={this.inputRef} type="text" id="sql" name="sql" value="ESSA" class="text-field" />
7672
<div ref={this.executeButtonRef} class="button">
7773
Execute SQL
@@ -103,16 +99,6 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
10399
.catch(e => console.error(e))
104100
})
105101

106-
this.setActiveButtonRef.instance.addEventListener("click", () => {
107-
const format = this.dropdownRef.instance.getNavigationDataFormat()
108-
if (!format) return
109-
// This will only work if the database specified is a SQLite database
110-
this.navigationDataInterface
111-
.set_active_database(format)
112-
.then(() => console.info("WASM set active database"))
113-
.catch(err => this.displayError(String(err)))
114-
})
115-
116102
AuthService.user.sub(user => {
117103
if (user) {
118104
this.qrCodeRef.instance.src = ""
@@ -173,7 +159,7 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
173159
const pkg = await packages.getPackage(format)
174160

175161
// Download navigation data to work dir
176-
await this.navigationDataInterface.download_navigation_data(pkg.file.url, pkg.format)
162+
await this.navigationDataInterface.download_navigation_data(pkg.file.url)
177163
this.displayMessage("Navigation data downloaded")
178164
} catch (err) {
179165
if (err instanceof Error) this.displayError(err.message)

package-lock.json

Lines changed: 29 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626
"eslint-plugin-prettier": "^5.0.1",
2727
"jest": "^29.7.0",
2828
"prettier": "^3.0.3",
29-
"random-bigint": "^0.0.1",
3029
"ts-jest": "^29.1.1",
3130
"ts-node": "^10.9.2",
3231
"tsup": "^8.0.1",
3332
"typescript": "^5.2.2",
3433
"uuid": "^9.0.1"
3534
}
36-
}
35+
}

src/database/src/database.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,53 @@ use crate::{
2727
vhf_navaid::VhfNavaid,
2828
waypoint::Waypoint,
2929
},
30-
sql_structs::{self},
31-
util,
30+
sql_structs, util,
3231
};
3332

3433
pub struct Database {
3534
database: Option<Connection>,
35+
pub path: Option<String>,
3636
}
3737

3838
#[derive(Debug)]
3939
struct NoDatabaseOpen;
4040

4141
impl Display for NoDatabaseOpen {
42-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "No database open") }
42+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
43+
write!(f, "No database open")
44+
}
4345
}
4446

4547
impl Error for NoDatabaseOpen {}
4648

4749
impl Database {
48-
pub fn new() -> Self { Database { database: None } }
50+
pub fn new() -> Self {
51+
Database {
52+
database: None,
53+
path: None,
54+
}
55+
}
4956

50-
fn get_database(&self) -> Result<&Connection, NoDatabaseOpen> { self.database.as_ref().ok_or(NoDatabaseOpen) }
57+
fn get_database(&self) -> Result<&Connection, NoDatabaseOpen> {
58+
self.database.as_ref().ok_or(NoDatabaseOpen)
59+
}
5160

52-
pub fn set_active_database(&mut self, mut path: String) -> Result<(), Box<dyn Error>> {
53-
// Check if the path is a directory and if it is, search for a sqlite file
54-
let formatted_path = format!("\\work/{}", path);
55-
if util::get_path_type(std::path::Path::new(&formatted_path)) == util::PathType::Directory {
56-
path = util::find_sqlite_file(&formatted_path)?;
61+
pub fn set_active_database(&mut self, path: String) -> Result<(), Box<dyn Error>> {
62+
let path = match util::find_sqlite_file(&path) {
63+
Ok(new_path) => new_path,
64+
Err(_) => path,
65+
};
66+
println!("[NAVIGRAPH] Setting active database to {}", path);
67+
self.close_connection();
68+
if util::is_sqlite_file(&path)? {
69+
self.open_connection(path.clone())?;
5770
}
71+
self.path = Some(path);
5872

73+
Ok(())
74+
}
75+
76+
pub fn open_connection(&mut self, path: String) -> Result<(), Box<dyn Error>> {
5977
// We have to open with flags because the SQLITE_OPEN_CREATE flag with the default open causes the file to
6078
// be overwritten
6179
let flags = OpenFlags::SQLITE_OPEN_READ_ONLY | OpenFlags::SQLITE_OPEN_URI | OpenFlags::SQLITE_OPEN_NO_MUTEX;
@@ -541,5 +559,7 @@ impl Database {
541559
Ok(data)
542560
}
543561

544-
pub fn close_connection(&mut self) { self.database = None; }
562+
pub fn close_connection(&mut self) {
563+
self.database = None;
564+
}
545565
}

src/database/src/math.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ pub type Minutes = f64;
1010
pub type KiloHertz = f64;
1111
pub type MegaHertz = f64;
1212

13-
pub(crate) fn feet_to_meters(metres: Meters) -> Feet { metres / 3.28084 }
13+
pub(crate) fn feet_to_meters(metres: Meters) -> Feet {
14+
metres / 3.28084
15+
}
1416

1517
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
1618
pub struct Coordinates {

0 commit comments

Comments
 (0)