doing dumb things for obs
This commit is contained in:
parent
4b489d4e45
commit
b07e59659d
4 changed files with 101 additions and 43 deletions
|
@ -1,5 +1,6 @@
|
|||
use core::fmt;
|
||||
use std::error::Error;
|
||||
use std::time::Duration;
|
||||
|
||||
use obws::responses::scenes::Scenes;
|
||||
use obws::Client;
|
||||
|
@ -67,22 +68,18 @@ impl Obs {
|
|||
self,
|
||||
scene: String,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
debug!("Starting function");
|
||||
if self.client.is_some() {
|
||||
if let Some(scene) = self
|
||||
.scenes
|
||||
.scenes
|
||||
.iter()
|
||||
.filter(|x| x.name == scene)
|
||||
.next()
|
||||
{
|
||||
debug!("Starting to set");
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
tokio::spawn(async move {
|
||||
debug!(scene, "working in thread");
|
||||
self.client
|
||||
.unwrap()
|
||||
.scenes()
|
||||
.set_current_program_scene(scene.name.as_str());
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Couldn't set the scene".to_owned())?
|
||||
}
|
||||
.set_current_program_scene(scene.as_str()).await
|
||||
});
|
||||
Ok(())
|
||||
} else {
|
||||
Err("There is no client".to_owned())?
|
||||
}
|
||||
|
@ -98,7 +95,7 @@ fn make_client() -> Client {
|
|||
|
||||
#[cxx_qt::bridge]
|
||||
mod obs_model {
|
||||
use tracing::debug;
|
||||
use tracing::{debug, error};
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!("cxx-qt-lib/qstring.h");
|
||||
|
@ -114,6 +111,10 @@ mod obs_model {
|
|||
pub struct ObsModel {
|
||||
#[qproperty]
|
||||
scenes: QStringList,
|
||||
#[qproperty]
|
||||
port: QString,
|
||||
#[qproperty]
|
||||
connected: bool,
|
||||
obs: Option<super::Obs>,
|
||||
}
|
||||
|
||||
|
@ -124,12 +125,53 @@ mod obs_model {
|
|||
debug!("updating scenes");
|
||||
let mut scenes_list = QList_QString::default();
|
||||
if let Some(obs) = self.obs() {
|
||||
obs.scenes.scenes.iter().map(|x| {
|
||||
debug!(?x);
|
||||
scenes_list.append(QString::from(&x.name))
|
||||
});
|
||||
debug!("found obs");
|
||||
for scene in obs.scenes.scenes.iter() {
|
||||
debug!(?scene);
|
||||
scenes_list.append(QString::from(&scene.name));
|
||||
}
|
||||
}
|
||||
for s in scenes_list.iter() {
|
||||
debug!(?s);
|
||||
}
|
||||
let list = QStringList::from(&scenes_list);
|
||||
debug!(?list);
|
||||
self.as_mut().set_scenes(list.clone());
|
||||
list
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn get_obs(mut self: Pin<&mut Self>) -> bool {
|
||||
debug!("getting obs");
|
||||
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
match super::Obs::new().await {
|
||||
Ok(o) => {
|
||||
self.as_mut().set_connected(true);
|
||||
self.as_mut().set_obs(Some(o));
|
||||
self.as_mut().update_scenes();
|
||||
},
|
||||
Err(e) => error!(e)
|
||||
}
|
||||
});
|
||||
|
||||
if let Some(_obs) = self.obs() {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn set_scene(mut self: Pin<&mut Self>, scene: QString) {
|
||||
let scene = scene.to_string();
|
||||
if let Some(obs) = self.obs_mut() {
|
||||
let obs = obs.clone();
|
||||
match obs.set_scene(scene) {
|
||||
Ok(()) => debug!("Successfully set scene"),
|
||||
Err(e) => error!(e),
|
||||
}
|
||||
}
|
||||
QStringList::from(&scenes_list)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue