mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat(ui,engine): add runtime VR toggle and harden Nomad/GUI concurrency
This commit is contained in:
1 parent
e859d0e21c
commit
b8f2f00f09
4 files changed
+376
-106
No files matched your search
+119
-11
@@ -16,7 +16,7 @@ use image::{Frame, RgbaImage};
|
||||
use parking_lot::Mutex;
|
||||
use smallvec::smallvec;
|
||||
use std::process::Command;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
@@ -93,6 +93,8 @@ pub struct SteamFrameGpuiApp {
|
||||
mock_tracker: Option<NomadHeadTracker>,
|
||||
mock_last_send: Option<Instant>,
|
||||
mock_status_text: String,
|
||||
is_restarting: Arc<AtomicBool>,
|
||||
is_closing: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl SteamFrameGpuiApp {
|
||||
@@ -102,6 +104,7 @@ impl SteamFrameGpuiApp {
|
||||
engine: Arc<Mutex<FpvEngineController>>,
|
||||
controls: EngineControlHandle,
|
||||
engine_monitor: Arc<Mutex<RuntimeMonitor>>,
|
||||
is_closing: Arc<AtomicBool>,
|
||||
) -> Self {
|
||||
let log_revision = log_buffer.lock().revision.clone();
|
||||
let target_port_buf = cfg.nomad_port.to_string();
|
||||
@@ -147,6 +150,8 @@ impl SteamFrameGpuiApp {
|
||||
mock_tracker: None,
|
||||
mock_last_send: None,
|
||||
mock_status_text: String::new(),
|
||||
is_restarting: Arc::new(AtomicBool::new(false)),
|
||||
is_closing,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,6 +441,10 @@ impl SteamFrameGpuiApp {
|
||||
}
|
||||
|
||||
fn send_mock_manual(&mut self) {
|
||||
if self.target_edit_field == Some(TargetEditField::Port) {
|
||||
self.commit_port_buf();
|
||||
self.target_edit_field = None;
|
||||
}
|
||||
let protocol = NomadProtocol::from_str(&self.cfg.ht_protocol);
|
||||
if self.mock_tracker.is_none() {
|
||||
match NomadHeadTracker::new(
|
||||
@@ -485,10 +494,62 @@ impl SteamFrameGpuiApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn restart_engine_async(&mut self, reason: &'static str) {
|
||||
if self.target_edit_field == Some(TargetEditField::Port) {
|
||||
self.commit_port_buf();
|
||||
}
|
||||
self.target_edit_field = None;
|
||||
|
||||
if self.is_closing.load(Ordering::Acquire) {
|
||||
return;
|
||||
}
|
||||
if self
|
||||
.is_restarting
|
||||
.compare_exchange(false, true, Ordering::AcqRel, Ordering::Acquire)
|
||||
.is_err()
|
||||
{
|
||||
log::warn!("[Moteur FPV] Redémarrage déjà en cours, requête ignorée.");
|
||||
return;
|
||||
}
|
||||
|
||||
let engine_clone = Arc::clone(&self.engine);
|
||||
let cfg_clone = self.cfg.clone();
|
||||
let is_restarting = Arc::clone(&self.is_restarting);
|
||||
let is_closing = Arc::clone(&self.is_closing);
|
||||
std::thread::spawn(move || {
|
||||
{
|
||||
let mut eng = engine_clone.lock();
|
||||
if !is_closing.load(Ordering::Acquire) {
|
||||
log::info!("{}", reason);
|
||||
eng.start(cfg_clone);
|
||||
}
|
||||
}
|
||||
is_restarting.store(false, Ordering::Release);
|
||||
});
|
||||
}
|
||||
|
||||
fn set_vr_enabled(&mut self, enabled: bool) {
|
||||
let target_headless = !enabled;
|
||||
if self.cfg.headless == target_headless {
|
||||
return;
|
||||
}
|
||||
if self.is_restarting.load(Ordering::Acquire) {
|
||||
log::warn!("[Moteur FPV] Bascule VR ignorée pendant un redémarrage en cours.");
|
||||
return;
|
||||
}
|
||||
self.cfg.headless = target_headless;
|
||||
if enabled {
|
||||
self.restart_engine_async("[Action Utilisateur] Mode VR (OpenXR) réactivé, redémarrage du moteur FPV...");
|
||||
} else {
|
||||
self.restart_engine_async("[Action Utilisateur] Mode VR désactivé (Mode Bureau léger), redémarrage du moteur FPV...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for SteamFrameGpuiApp {
|
||||
fn drop(&mut self) {
|
||||
self.is_closing.store(true, Ordering::Release);
|
||||
log::info!("[SteamFrameGpuiApp] Fermeture de l'interface IHM, arrêt propre du moteur FPV...");
|
||||
self.engine.lock().stop();
|
||||
}
|
||||
@@ -591,6 +652,21 @@ impl SteamFrameGpuiApp {
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.id("toggle_vr_quick")
|
||||
.cursor_pointer()
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
let vr_on = this.cfg.headless;
|
||||
this.set_vr_enabled(vr_on);
|
||||
cx.notify();
|
||||
}))
|
||||
.child(self.render_toggle_pill(
|
||||
"🥽 VR",
|
||||
!self.cfg.headless,
|
||||
rgb(COLOR_CYAN),
|
||||
)),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.id("toggle_ht_quick")
|
||||
@@ -998,16 +1074,7 @@ impl SteamFrameGpuiApp {
|
||||
.font_weight(gpui::FontWeight::BOLD)
|
||||
.cursor_pointer()
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
let engine_clone = Arc::clone(&this.engine);
|
||||
let cfg_clone = this.cfg.clone();
|
||||
std::thread::spawn(move || {
|
||||
if let Some(mut eng) = engine_clone.try_lock() {
|
||||
log::info!("[Réglages] Application et redémarrage asynchrone du moteur FPV...");
|
||||
eng.start(cfg_clone);
|
||||
} else {
|
||||
log::warn!("[Réglages] Redémarrage déjà en cours, requête ignorée.");
|
||||
}
|
||||
});
|
||||
this.restart_engine_async("[Réglages] Application et redémarrage asynchrone du moteur FPV...");
|
||||
cx.notify();
|
||||
}))
|
||||
.child("🔄 Appliquer & Redémarrer"),
|
||||
@@ -1207,6 +1274,9 @@ impl SteamFrameGpuiApp {
|
||||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||||
.cursor_pointer()
|
||||
.on_click(cx.listener(|this, _, window, cx| {
|
||||
if this.target_edit_field == Some(TargetEditField::Port) {
|
||||
this.commit_port_buf();
|
||||
}
|
||||
this.target_edit_field = Some(TargetEditField::Ip);
|
||||
if let Some(fh) = &this.target_focus_handle {
|
||||
window.focus(fh);
|
||||
@@ -1369,8 +1439,17 @@ impl SteamFrameGpuiApp {
|
||||
},
|
||||
self.mock_continuous,
|
||||
cx.listener(|this, _, _, cx| {
|
||||
if this.target_edit_field == Some(TargetEditField::Port) {
|
||||
this.commit_port_buf();
|
||||
this.target_edit_field = None;
|
||||
}
|
||||
this.mock_continuous = !this.mock_continuous;
|
||||
this.mock_last_send = None;
|
||||
if this.mock_continuous && this.cfg.head_tracking_enabled {
|
||||
this.cfg.head_tracking_enabled = false;
|
||||
this.controls.set_head_tracking_enabled(false);
|
||||
log::info!("[Mock Manuel] Suivi de tête moteur désactivé automatiquement pour éviter une collision UDP.");
|
||||
}
|
||||
cx.notify();
|
||||
}),
|
||||
)),
|
||||
@@ -1435,6 +1514,31 @@ impl SteamFrameGpuiApp {
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap_3()
|
||||
// Activation / Désactivation du mode VR OpenXR
|
||||
.child(self.render_setting_row(
|
||||
"Affichage Casque VR (OpenXR)",
|
||||
div()
|
||||
.flex()
|
||||
.gap_2()
|
||||
.child(self.render_selectable_pill(
|
||||
"pill_vr_on",
|
||||
"🥽 Activé (Casque VR)",
|
||||
!self.cfg.headless,
|
||||
cx.listener(|this, _, _, cx| {
|
||||
this.set_vr_enabled(true);
|
||||
cx.notify();
|
||||
}),
|
||||
))
|
||||
.child(self.render_selectable_pill(
|
||||
"pill_vr_off",
|
||||
"🖥️ Désactivé (Mode Bureau léger)",
|
||||
self.cfg.headless,
|
||||
cx.listener(|this, _, _, cx| {
|
||||
this.set_vr_enabled(false);
|
||||
cx.notify();
|
||||
}),
|
||||
)),
|
||||
))
|
||||
// Mode de projection
|
||||
.child(self.render_setting_row(
|
||||
"Mode de Projection VR",
|
||||
@@ -2388,10 +2492,13 @@ pub fn run_gpui_app(cfg: AppConfig, log_buffer: Arc<Mutex<LogBuffer>>) -> Result
|
||||
let engine_monitor = Arc::clone(&engine.monitor);
|
||||
let engine = Arc::new(Mutex::new(engine));
|
||||
let engine_for_close = Arc::clone(&engine);
|
||||
let is_closing = Arc::new(AtomicBool::new(false));
|
||||
let is_closing_for_window = Arc::clone(&is_closing);
|
||||
|
||||
cx.on_window_closed(move |cx| {
|
||||
if cx.windows().is_empty() {
|
||||
log::info!("[GPUI] Dernière fenêtre fermée, arrêt propre et complet du moteur FPV...");
|
||||
is_closing_for_window.store(true, Ordering::Release);
|
||||
engine_for_close.lock().stop();
|
||||
cx.quit();
|
||||
}
|
||||
@@ -2415,6 +2522,7 @@ pub fn run_gpui_app(cfg: AppConfig, log_buffer: Arc<Mutex<LogBuffer>>) -> Result
|
||||
engine,
|
||||
controls,
|
||||
engine_monitor,
|
||||
is_closing,
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user