From 265bd8383c98ed63d45b461296a2bc8bc473b0b9 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sun, 19 Nov 2023 07:16:45 -0600 Subject: [PATCH] a lot of attempts to make obs work. the setting never finishes By setting the log level to tracing, I can find that obs isn't responding to obws or something. Need to figure out why... --- src/rust/obs.rs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/rust/obs.rs b/src/rust/obs.rs index 870a17b..4a954f9 100644 --- a/src/rust/obs.rs +++ b/src/rust/obs.rs @@ -1,5 +1,6 @@ use core::fmt; use std::error::Error; +use std::thread::sleep; use std::time::Duration; use obws::responses::scenes::Scenes; @@ -71,14 +72,25 @@ impl Obs { debug!("Starting function"); if self.client.is_some() { debug!("Starting to set"); - let runtime = tokio::runtime::Runtime::new().unwrap(); - runtime.block_on(async move { + let runtime = + tokio::runtime::Builder::new_current_thread() + .thread_keep_alive(Duration::from_secs(1)) + .enable_all() + .build() + .unwrap(); + let client = make_client(); + let handle = runtime.spawn(async move { debug!(scene, "working in thread"); - self.client - .unwrap() - .scenes() - .set_current_program_scene(&scene).await - })?; + client.scenes() + .set_current_program_scene(&scene) + .await + }); + loop { + sleep(Duration::from_millis(100)); + if handle.is_finished() { + break; + } + } Ok(()) } else { Err("There is no client".to_owned())? @@ -118,10 +130,11 @@ mod obs_model { obs: Option, } - impl qobject::ObsModel { #[qinvokable] - pub fn update_scenes(mut self: Pin<&mut Self>) -> QStringList { + pub fn update_scenes( + mut self: Pin<&mut Self>, + ) -> QStringList { debug!("updating scenes"); let mut scenes_list = QList_QString::default(); if let Some(obs) = self.obs() { @@ -150,11 +163,11 @@ mod obs_model { self.as_mut().set_connected(true); self.as_mut().set_obs(Some(o)); self.as_mut().update_scenes(); - }, + } Err(e) => { error!(e); self.as_mut().set_connected(false); - }, + } } });