Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions apps/desktop-gpui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions apps/desktop-gpui/src/editor_sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ pub enum ColorPickerDrag {
/// The sidebar's own state -- everything `ConfigSidebar`'s signals hold that is
/// not in the project config.
pub struct SidebarState {
pub audio_enhancement_default: bool,
pub audio_enhancement_error: Option<String>,
pub(crate) style_target: Option<(usize, StyleGroup)>,
pub(crate) image_import_error: Option<String>,
pub(crate) image_asset_status: Option<(String, bool)>,
Expand Down Expand Up @@ -877,6 +879,11 @@ pub struct SidebarState {
impl SidebarState {
pub fn new(config: &ProjectConfiguration) -> Self {
Self {
audio_enhancement_default: crate::store::store_section("audio_enhancement")
.get("enabledByDefault")
.and_then(serde_json::Value::as_bool)
.unwrap_or(false),
audio_enhancement_error: None,
style_target: None,
image_import_error: None,
image_asset_status: None,
Expand Down
50 changes: 50 additions & 0 deletions apps/desktop-gpui/src/editor_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,7 @@ impl EditorWindow {
pub(crate) fn render_audio_tab(&self, cx: &mut Context<Self>) -> AnyElement {
let theme = self.theme;
let audio = &self.project.audio;
let enabled_by_default = self.sidebar.audio_enhancement_default;
let summary = self.summary();
let muted = audio.mute;
let has_microphone = summary.is_some_and(|summary| summary.has_microphone);
Expand Down Expand Up @@ -1586,6 +1587,55 @@ impl EditorWindow {
})),
),
)
.children(has_microphone.then(|| {
div()
.flex()
.flex_col()
.gap(px(8.))
.child(ui::Subfield::plain(&theme, "Studio Sound").child(
ui::Toggle::plain(&theme, "audio-improve", audio.improve).on_click(
cx.listener(|this, _, window, cx| {
this.edit_project("audio-improve", window, cx, |project| {
project.audio.improve = !project.audio.improve;
true
});
}),
),
))
.child(
div()
.text_size(px(12.))
.text_color(theme.gray_10)
.child("Reduce background noise and bring your voice into focus."),
)
.into_any_element()
}))
.child(
ui::Subfield::plain(&theme, "Studio Sound for new recordings").child(
ui::Toggle::plain(&theme, "audio-improve-default", enabled_by_default)
.on_click(cx.listener(move |this, _, _, cx| {
if !store::set_store_setting(
"audio_enhancement",
"enabledByDefault",
serde_json::json!(!enabled_by_default),
) {
this.sidebar.audio_enhancement_error =
Some("Could not save the Studio Sound default".into());
} else {
this.sidebar.audio_enhancement_default = !enabled_by_default;
this.sidebar.audio_enhancement_error = None;
}
cx.notify();
})),
),
)
.children(self.sidebar.audio_enhancement_error.as_ref().map(|error| {
div()
.text_size(px(12.))
.text_color(theme.gray_10)
.child(error.clone())
.into_any_element()
}))
.children(has_microphone.then(|| {
self.slider_field_disabled(
"Microphone Volume",
Expand Down
36 changes: 36 additions & 0 deletions apps/desktop-gpui/src/recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,14 @@ async fn finalize_studio(
))
.unwrap_or_default();
apply_animated_gradient_to_project_config(&project_path, &capture_target, &library);
if crate::store::store_section("audio_enhancement")
.get("enabledByDefault")
.and_then(serde_json::Value::as_bool)
.unwrap_or(false)
&& let Err(error) = enable_studio_sound(&project_path)
{
tracing::warn!(%error, "Could not apply the Studio Sound default");
}
})
.await
.context("studio post-finalize task")?;
Expand Down Expand Up @@ -1461,6 +1469,34 @@ fn blur_mode_json(blur: crate::store::BlurMode) -> &'static str {
}
}

fn enable_studio_sound(project_path: &std::path::Path) -> std::io::Result<()> {
let path = project_path.join("project-config.json");
let mut config: serde_json::Value = serde_json::from_slice(&std::fs::read(&path)?)?;
let object = config.as_object_mut().ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Project configuration is not an object",
)
})?;
let audio = object
.entry("audio")
.or_insert_with(|| serde_json::json!({}));
let audio = audio.as_object_mut().ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Audio configuration is not an object",
)
})?;
audio.insert("improve".into(), serde_json::Value::Bool(true));
let temp = path.with_extension(format!("studio-sound-{}.tmp", crate::store::new_uuid_v4()));
let result = std::fs::write(&temp, serde_json::to_vec_pretty(&config)?)
.and_then(|()| std::fs::rename(&temp, path));
if result.is_err() {
let _ = std::fs::remove_file(temp);
}
result
}

fn apply_animated_gradient_to_project_config(
project_dir: &std::path::Path,
capture_target: &ScreenCaptureTarget,
Expand Down
13 changes: 13 additions & 0 deletions apps/desktop/src-tauri/src/recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6407,6 +6407,19 @@ fn project_config_from_recording(

let using_default_config = default_config.is_none();
let mut config = default_config.unwrap_or_default();
if app
.store("store")
.ok()
.and_then(|store| store.get("audio_enhancement"))
.and_then(|value| {
value
.get("enabledByDefault")
.and_then(serde_json::Value::as_bool)
})
.unwrap_or(false)
{
config.audio.improve = true;
}
if using_default_config {
let library = app
.store("store")
Expand Down
Loading
Loading