Implement UI commands

v5-api
Dominik Nakamura 2 years ago
parent 7dc39a98ef
commit 21cbe828b1
No known key found for this signature in database
GPG Key ID: E4C6A749B2491910

@ -97,23 +97,4 @@ impl<'a> General<'a> {
})
.await
}
/// Gets whether studio is enabled.
pub async fn get_studio_mode_enabled(&self) -> Result<bool> {
self.client
.send_message::<responses::StudioModeEnabled>(RequestType::GetStudioModeEnabled)
.await
.map(|sme| sme.studio_mode_enabled)
}
/// Enables or disables studio mode.
///
/// - `studio_mode_enabled`: Enable or disable the studio mode.
pub async fn set_studio_mode_enabled(&self, studio_mode_enabled: bool) -> Result<()> {
self.client
.send_message(RequestType::SetStudioModeEnabled {
studio_mode_enabled,
})
.await
}
}

@ -31,7 +31,7 @@ use tracing::{debug, error, trace};
pub use self::{
config::Config, general::General, inputs::Inputs, media_inputs::MediaInputs, outputs::Outputs,
recording::Recording, scene_items::SceneItems, scenes::Scenes, sources::Sources,
streaming::Streaming, transitions::Transitions,
streaming::Streaming, transitions::Transitions, ui::Ui,
};
#[cfg(feature = "events")]
use crate::events::Event;
@ -52,6 +52,7 @@ mod scenes;
mod sources;
mod streaming;
mod transitions;
mod ui;
#[derive(Debug, thiserror::Error)]
enum InnerError {
@ -448,6 +449,11 @@ impl Client {
pub fn transitions(&self) -> Transitions<'_> {
Transitions { client: self }
}
/// Access API functions related to the user interface.
pub fn ui(&self) -> Ui<'_> {
Ui { client: self }
}
}
impl Drop for Client {

@ -0,0 +1,55 @@
use super::Client;
use crate::{requests::RequestType, responses, Result};
/// API functions related to the user interface.
pub struct Ui<'a> {
pub(super) client: &'a Client,
}
impl<'a> Ui<'a> {
/// Gets whether studio is enabled.
pub async fn get_studio_mode_enabled(&self) -> Result<bool> {
self.client
.send_message::<responses::StudioModeEnabled>(RequestType::GetStudioModeEnabled)
.await
.map(|sme| sme.studio_mode_enabled)
}
/// Enables or disables studio mode.
///
/// - `studio_mode_enabled`: Enable or disable the studio mode.
pub async fn set_studio_mode_enabled(&self, studio_mode_enabled: bool) -> Result<()> {
self.client
.send_message(RequestType::SetStudioModeEnabled {
studio_mode_enabled,
})
.await
}
/// Opens the properties dialog of an input.
///
/// - `input_name`: Name of the input to open the dialog of.
pub async fn open_input_properties_dialog(&self, input_name: &str) -> Result<()> {
self.client
.send_message(RequestType::OpenInputPropertiesDialog { input_name })
.await
}
/// Opens the filters dialog of an input.
///
/// - `input_name`: Name of the input to open the dialog of.
pub async fn open_input_filters_dialog(&self, input_name: &str) -> Result<()> {
self.client
.send_message(RequestType::OpenInputFiltersDialog { input_name })
.await
}
/// Opens the interact dialog of an input.
///
/// - `input_name`: Name of the input to open the dialog of.
pub async fn open_input_interact_dialog(&self, input_name: &str) -> Result<()> {
self.client
.send_message(RequestType::OpenInputInteractDialog { input_name })
.await
}
}

@ -251,6 +251,7 @@ pub(crate) enum RequestType<'a> {
/// Settings to apply to the service.
stream_service_settings: serde_json::Value,
},
GetRecordDirectory,
// --------------------------------
// General
// --------------------------------
@ -275,12 +276,6 @@ pub(crate) enum RequestType<'a> {
/// Object containing key modifiers to apply.
key_modifiers: KeyModifiers,
},
GetStudioModeEnabled,
#[serde(rename_all = "camelCase")]
SetStudioModeEnabled {
/// Enable or disable the studio mode.
studio_mode_enabled: bool,
},
// TODO: Sleep
// --------------------------------
// Inputs
@ -435,7 +430,6 @@ pub(crate) enum RequestType<'a> {
ToggleRecordPause,
PauseRecord,
ResumeRecord,
GetRecordDirectory,
// --------------------------------
// Scene items
// --------------------------------
@ -596,6 +590,30 @@ pub(crate) enum RequestType<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
release: Option<bool>,
},
// --------------------------------
// UI
// --------------------------------
GetStudioModeEnabled,
#[serde(rename_all = "camelCase")]
SetStudioModeEnabled {
/// Enable or disable the studio mode.
studio_mode_enabled: bool,
},
#[serde(rename_all = "camelCase")]
OpenInputPropertiesDialog {
/// Name of the input to open the dialog of.
input_name: &'a str,
},
#[serde(rename_all = "camelCase")]
OpenInputFiltersDialog {
/// Name of the input to open the dialog of.
input_name: &'a str,
},
#[serde(rename_all = "camelCase")]
OpenInputInteractDialog {
/// Name of the input to open the dialog of.
input_name: &'a str,
},
}
#[derive(Clone, Copy, Serialize)]

@ -105,7 +105,7 @@ async fn ensure_obs_setup(client: &Client) -> Result<()> {
TEST_PROFILE
);
let studio_mode_enabled = client.general().get_studio_mode_enabled().await?;
let studio_mode_enabled = client.ui().get_studio_mode_enabled().await?;
ensure!(
!studio_mode_enabled,
"studio mode enabled, required to be disabled for studio mode tests"

@ -25,10 +25,6 @@ async fn general() -> Result<()> {
.trigger_hotkey_by_key_sequence("OBS_KEY_P", KeyModifiers::default())
.await?;
let enabled = client.get_studio_mode_enabled().await?;
client.set_studio_mode_enabled(!enabled).await?;
client.set_studio_mode_enabled(enabled).await?;
Ok(())
}

@ -12,3 +12,4 @@ mod scenes;
mod sources;
mod streaming;
mod transitions;
mod ui;

@ -7,10 +7,10 @@ use crate::common::{self, TEST_SCENE, TEST_SCENE_CREATE, TEST_SCENE_RENAME, TEST
#[tokio::test]
async fn scenes() -> Result<()> {
let client = common::new_client().await?;
let general = client.general();
let ui = client.ui();
let client = client.scenes();
general.set_studio_mode_enabled(true).await?;
ui.set_studio_mode_enabled(true).await?;
let scenes = client.get_scene_list().await?.scenes;
client.get_group_list().await?;
@ -57,7 +57,7 @@ async fn scenes() -> Result<()> {
})
.await?;
general.set_studio_mode_enabled(false).await?;
ui.set_studio_mode_enabled(false).await?;
Ok(())
}

@ -5,7 +5,7 @@ use crate::common::{self, TEST_TRANSITION};
#[tokio::test]
async fn transitions() -> Result<()> {
let client = common::new_client().await?;
let general = client.general();
let ui = client.ui();
let client = client.transitions();
client.get_transition_kind_list().await?;
@ -22,12 +22,12 @@ async fn transitions() -> Result<()> {
.await?;
client.get_current_scene_transition_cursor().await?;
general.set_studio_mode_enabled(true).await?;
ui.set_studio_mode_enabled(true).await?;
client.trigger_studio_mode_transition().await?;
client.set_tbar_position(0.5, None).await?;
general.set_studio_mode_enabled(false).await?;
ui.set_studio_mode_enabled(false).await?;
Ok(())
}

@ -0,0 +1,15 @@
use anyhow::Result;
use crate::common;
#[tokio::test]
async fn ui() -> Result<()> {
let client = common::new_client().await?;
let client = client.ui();
let enabled = client.get_studio_mode_enabled().await?;
client.set_studio_mode_enabled(!enabled).await?;
client.set_studio_mode_enabled(enabled).await?;
Ok(())
}
Loading…
Cancel
Save