diff --git a/client/src-tauri/.gitignore b/client/src-tauri/.gitignore index aba21e2..62a7761 100644 --- a/client/src-tauri/.gitignore +++ b/client/src-tauri/.gitignore @@ -1,3 +1,3 @@ # Generated by Cargo # will have compiled files and executables -/target/ +/target/ \ No newline at end of file diff --git a/client/src-tauri/src/main.rs b/client/src-tauri/src/main.rs index 82fab0f..1d0aca9 100644 --- a/client/src-tauri/src/main.rs +++ b/client/src-tauri/src/main.rs @@ -3,6 +3,7 @@ use tauri::Manager; mod telemetry; +use tracing_subscriber::FmtSubscriber; #[derive(Clone, serde::Serialize)] struct Payload { @@ -15,6 +16,12 @@ const NTABLE_PORT: u16 = 5810; fn main() { let rt = tokio::runtime::Runtime::new().expect("Failed to create Tokio runtime"); + // set the environment variable RUST_LOG to debug in order to see debug messages + let subscriber = FmtSubscriber::builder() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .finish(); + tracing::subscriber::set_global_default(subscriber).unwrap(); + rt.block_on(async { tauri::Builder::default() .setup(|app| { diff --git a/client/src-tauri/src/telemetry/check_triggers.rs b/client/src-tauri/src/telemetry/check_triggers.rs new file mode 100644 index 0000000..499b116 --- /dev/null +++ b/client/src-tauri/src/telemetry/check_triggers.rs @@ -0,0 +1,23 @@ +use tauri::{AppHandle, Manager}; + +pub fn check_triggers( + app_handle: &AppHandle, + topic_name: &str, + data: &network_tables::Value, + previous_gpws: &bool, +) { + if topic_name == "gpws" { + match data { + network_tables::Value::Boolean(b) => { + if *b != *previous_gpws { + tracing::debug!("gpws: {}", b); + + app_handle + .emit_all("telemetry_gpws", b) + .expect("Failed to emit telemetry_gpws event"); + } + } + _ => {} + } + } +} diff --git a/client/src-tauri/src/telemetry/create_client.rs b/client/src-tauri/src/telemetry/create_client.rs index b1b1c90..4fc5691 100644 --- a/client/src-tauri/src/telemetry/create_client.rs +++ b/client/src-tauri/src/telemetry/create_client.rs @@ -37,9 +37,11 @@ pub async fn create_client( break client; // Exit the loop if the client is successfully created } Err(e) => { - if cfg!(debug_assertions) { - println!("Failed to create client: {}. Retrying in 3 seconds...", e); - } + tracing::debug!( + message = "Failed to create client. Retrying in 3 seconds...", + error = %e, + rate_limit = "3s", + ); app_handle .emit_all("telemetry_status", "disconnected") .expect("Failed to emit telemetry_status disconnected event"); diff --git a/client/src-tauri/src/telemetry/create_subscription.rs b/client/src-tauri/src/telemetry/create_subscription.rs index c9ab0b5..4fd29e4 100644 --- a/client/src-tauri/src/telemetry/create_subscription.rs +++ b/client/src-tauri/src/telemetry/create_subscription.rs @@ -32,9 +32,7 @@ pub async fn create_subscription(client: &Client) -> Result break Ok(subscription), Err(e) => { - if cfg!(debug_assertions) { - println!("Failed to create subscription: {}", e); - } + tracing::debug!("Failed to create subscription: {:?}", e); if attempts >= 50 { break Err(e); diff --git a/client/src-tauri/src/telemetry/mod.rs b/client/src-tauri/src/telemetry/mod.rs index a10ad42..206143e 100644 --- a/client/src-tauri/src/telemetry/mod.rs +++ b/client/src-tauri/src/telemetry/mod.rs @@ -1,10 +1,12 @@ use network_tables::v4::{MessageData, Subscription}; use serde_json::to_string; use tauri::{AppHandle, Manager}; +mod check_triggers; mod create_client; mod create_subscription; -use crate::telemetry::create_client::create_client; +use check_triggers::check_triggers; +use create_client::create_client; use create_subscription::create_subscription; /// Attempts to subscribe to NetworkTables topics and send the data to the frontend. @@ -19,6 +21,8 @@ pub async fn subscribe_topics( ntable_ip: (u8, u8, u8, u8), ntable_port: u16, ) { + let mut previous_gpws: bool = false; + loop { // I hope this doesn't lead to a catastrophic infinite loop failure let client = create_client(&app_handle, &ntable_ip, &ntable_port).await; @@ -41,7 +45,11 @@ pub async fn subscribe_topics( while let Some(mut message) = subscription.next().await { process_message(&mut message); - let json_message = to_string(&message).expect("Failed to serialize message"); + let json_message = match to_string(&message) { + Ok(json) => json, + Err(_) => continue, + }; + app_handle .emit_all("telemetry_data", json_message.clone()) .expect("Failed to send telemetry message"); diff --git a/client/src/App.svelte b/client/src/App.svelte index 2bd309b..5e7ab7a 100644 --- a/client/src/App.svelte +++ b/client/src/App.svelte @@ -76,17 +76,9 @@ } .infotainment-container { - background: #2c3e50; /* fallback for old browsers */ - background: -webkit-linear-gradient( - to right, - #2c3e50, - #fd746c - ); /* Chrome 10-25, Safari 5.1-6 */ - background: linear-gradient( - to right, - #2c3e50, - #fd746c - ); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */ + background-image: url('./assets/wallpaper.jpg'); + background-repeat: no-repeat; + background-size: cover; /* hide scrollbar */ -ms-overflow-style: none; scrollbar-width: none; diff --git a/client/src/assets/wallpaper.jpg b/client/src/assets/wallpaper.jpg new file mode 100644 index 0000000..d8691f5 Binary files /dev/null and b/client/src/assets/wallpaper.jpg differ diff --git a/client/src/lib/Loading/Loading.svelte b/client/src/lib/Loading/Loading.svelte index 4b9f059..4c78fff 100644 --- a/client/src/lib/Loading/Loading.svelte +++ b/client/src/lib/Loading/Loading.svelte @@ -1,7 +1,7 @@
.bg { - background: #2c3e50; /* fallback for old browsers */ - background: -webkit-linear-gradient( - to right, - #2c3e50, - #fd746c - ); /* Chrome 10-25, Safari 5.1-6 */ - background: linear-gradient( - to right, - #2c3e50, - #fd746c - ); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */ + background-image: url('../../assets/wallpaper.jpg'); + background-repeat: no-repeat; + background-size: cover; } diff --git a/client/src/lib/Sequences/sequences.ts b/client/src/lib/Sequences/sequences.ts index b3436f9..50d0fa8 100644 --- a/client/src/lib/Sequences/sequences.ts +++ b/client/src/lib/Sequences/sequences.ts @@ -430,3 +430,13 @@ export const modeLudicrousSequence = async () => { Notifications.playAudio(getVoicePath('set-acceleration-profile-ludicrous')) } + +export const gpwsTriggeredSequence = async () => { + if (get(settingsStore).disableAnnoyances) return + await tick() + + Notifications.error('Terrain, pull up!', { + withAudio: true, + src: getVoicePath('terrain-pull-up'), + }) +} diff --git a/client/src/lib/utils/initializeTelemetry.ts b/client/src/lib/utils/initializeTelemetry.ts index 35fc723..35d34b3 100644 --- a/client/src/lib/utils/initializeTelemetry.ts +++ b/client/src/lib/utils/initializeTelemetry.ts @@ -1,3 +1,4 @@ +import { gpwsTriggeredSequence } from '../Sequences/sequences' import { telemetryStore } from '../stores/telemetryStore' import { listen } from '@tauri-apps/api/event' @@ -24,8 +25,6 @@ export const initializeTelemetry = async () => { telemetryStore.set(data['topic_name'], data['data']) }) -<<<<<<< HEAD -======= const unlistenGPWS = await listen('telemetry_gpws', event => { const data = JSON.parse(event.payload as string) as boolean if (data) { @@ -33,10 +32,10 @@ export const initializeTelemetry = async () => { } }) ->>>>>>> cffa594 (fix: detect connectivity properly) const unlistenAll = () => { unlistenStatus() unlistenTelemetry() + unlistenGPWS() } return unlistenAll