Skip to content

Commit 06825a2

Browse files
committed
feat: optional config
1 parent afd924c commit 06825a2

File tree

9 files changed

+76
-11
lines changed

9 files changed

+76
-11
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
The Navigraph Navigation Data Interface enables developers to download and integrate navigation data from Navigraph directly into add-on aircraft in MSFS.
44

5-
65
## Key Features
6+
77
- Navigraph DFD Format: Leverage specialized support for Navigraph's DFD format, based on SQLite, which includes an SQL interface on the commbus for efficient data handling.
88
- Javascript and WASM support: The navdata interface is accessible from both Javascript (Coherent) and WASM, providing flexibility for developers.
99
- Supports updating of custom data formats.
@@ -29,22 +29,36 @@ Here's an overview on the structure of this repository, which is designed to be
2929
1. You'll need to either build the WASM module yourself (not recommended, but documented further down) or download it from [the latest release](https://github.com/Navigraph/msfs-navigation-data-interface/releases) (alternatively you can download it off of a commit by looking at the uploaded artifacts).
3030
2. Add the WASM module into your `panel` folder in `PackageSources`
3131
3. Add the following entry into `panel.cfg` (make sure to replace `NN` with the proper `VCockpit` ID):
32+
3233
```
3334
[VCockpitNN]
3435
size_mm=0,0
3536
pixel_size=0,0
3637
texture=NO_TEXTURE
3738
htmlgauge00=WasmInstrument/WasmInstrument.html?wasm_module=msfs_navigation_data_interface.wasm&wasm_gauge=navigation_data_interface,0,0,1,1
3839
```
40+
3941
- 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
42+
4. **Optional**: Create a `Navigraph/config.json` file to assist with Sentry reports. This info will be reported to us should any error occur in the library. We will use this to directly reach out to you (the developer) for these errors.
43+
44+
- The file must look like
45+
46+
```json
47+
{
48+
"addon": {
49+
"developer": "Navigraph",
50+
"product": "Sample Aircraft"
51+
}
52+
}
53+
```
4054

4155
## Dealing with Bundled Navigation Data
4256

43-
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/)
57+
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 `Navigraph/BundledData` directory in `PackageSources`. You can see an example [here](examples/aircraft/PackageSources/Navigraph/BundledData/)
4458

4559
## Where is the Navigation Data Stored?
4660

47-
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)
61+
The default location for navigation data is `work/NavigationData`.
4862

4963
## Building the Sample Aircraft
5064

examples/aircraft/PackageDefinitions/navigraph-aircraft-navigation-data-interface-sample.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
<AssetDir>PackageSources\Data\</AssetDir>
2828
<OutputDir>Data\</OutputDir>
2929
</AssetGroup>
30-
<AssetGroup Name="NavigationData">
30+
<AssetGroup Name="Navigraph">
3131
<Type>Copy</Type>
3232
<Flags>
3333
<FSXCompatibility>false</FSXCompatibility>
3434
</Flags>
35-
<AssetDir>PackageSources\NavigationData\</AssetDir>
36-
<OutputDir>NavigationData\</OutputDir>
35+
<AssetDir>PackageSources\Navigraph\</AssetDir>
36+
<OutputDir>Navigraph\</OutputDir>
3737
</AssetGroup>
3838
<AssetGroup Name="SimObject">
3939
<Type>SimObject</Type>
@@ -53,4 +53,3 @@
5353
</AssetGroup>
5454
</AssetGroups>
5555
</AssetPackage>
56-
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"addon": {
3+
"developer": "Navigraph",
4+
"product": "Sample Aircraft"
5+
}
6+
}

src/wasm/src/config.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use std::fs::File;
2+
3+
use anyhow::Result;
4+
use serde::Deserialize;
5+
6+
/// The path to an optional addon-specific config file containing data about the addon
7+
const ADDON_CONFIG_FILE: &str = ".\\Navigraph/config.json";
8+
9+
/// Information about the current addon
10+
#[derive(Deserialize)]
11+
pub struct Addon {
12+
pub developer: String,
13+
pub product: String,
14+
}
15+
16+
/// Configuration data provided by the developer
17+
#[derive(Deserialize)]
18+
pub struct Config {
19+
pub addon: Addon,
20+
}
21+
22+
impl Config {
23+
/// Try to get the config
24+
pub fn get_config() -> Result<Self> {
25+
let file = File::open(ADDON_CONFIG_FILE)?;
26+
27+
Ok(serde_json::from_reader(file)?)
28+
}
29+
}

src/wasm/src/database/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub const WORK_CYCLE_JSON_PATH: &str = "\\work/NavigationData/cycle.json";
4747
/// The path to the "master" SQLite DB
4848
pub const WORK_DB_PATH: &str = "\\work/NavigationData/db.s3db";
4949
/// The folder name for bundled navigation data
50-
pub const BUNDLED_FOLDER_NAME: &str = ".\\NavigationData";
50+
pub const BUNDLED_FOLDER_NAME: &str = ".\\Navigraph/BundledData";
5151

5252
/// The global exported database state
5353
pub static DATABASE_STATE: Lazy<Mutex<DatabaseState>> =
@@ -143,6 +143,8 @@ impl DatabaseState {
143143
fn new() -> Self {
144144
// Start out with a fresh instance
145145
let mut instance = Self::default();
146+
147+
// Try to load a DB
146148
match instance.try_load_db() {
147149
Ok(()) => {}
148150
Err(e) => {

src/wasm/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{cell::RefCell, collections::VecDeque, rc::Rc, time::Instant};
1+
use std::{cell::RefCell, collections::VecDeque, fs::File, rc::Rc, time::Instant};
22

33
use anyhow::{anyhow, Result};
44
use funcs::{InterfaceFunction, RunStatus};
@@ -7,9 +7,15 @@ use sentry::{integrations::anyhow::capture_anyhow, protocol::Context};
77
use sentry_gauge::{wrap_gauge_with_sentry, SentryGauge};
88
use serde::Serialize;
99

10+
/// Developer-configured values for interface
11+
mod config;
12+
/// SQLite mapping implementation
1013
mod database;
14+
/// Interface function definitions
1115
mod funcs;
16+
/// Futures implementations for use in interface functions
1217
mod futures;
18+
/// The sentry wrapper implementation around the MSFS gauge callbacks
1319
mod sentry_gauge;
1420

1521
/// Amount of MS between dispatches of the heartbeat commbus event

src/wasm/src/sentry_gauge.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
fs::{File, OpenOptions},
2+
fs::OpenOptions,
33
sync::{Arc, Mutex},
44
time::{Duration, Instant},
55
};
@@ -15,6 +15,8 @@ use sentry::integrations::anyhow::capture_anyhow;
1515
use serde::{Deserialize, Serialize};
1616
use uuid::Uuid;
1717

18+
use crate::config::Config;
19+
1820
/// The path to the sentry persistent state file
1921
const SENTRY_FILE: &str = "\\work/ng_sentry.json";
2022

@@ -246,12 +248,19 @@ where
246248
.user_id
247249
.to_string();
248250

249-
// Configure the sentry scope to report the user ID
251+
// Configure the sentry scope to report the user ID and sentry config (if present)
250252
sentry::configure_scope(|scope| {
251253
scope.set_user(Some(sentry::User {
252254
id: Some(user_id),
253255
..Default::default()
254256
}));
257+
258+
if let Ok(config) = Config::get_config() {
259+
scope.set_tag(
260+
"addon",
261+
format!("{}/{}", config.addon.developer, config.addon.product),
262+
);
263+
}
255264
});
256265

257266
// Drain any pending reports. We need to structure it like this as opposed to just a top level `let Ok(state) = ...`` due to the fact we should not be holding a MutexGuard across an await point

0 commit comments

Comments
 (0)