Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Add recording sound effects + prev-recordings fix

Richie McIlroy7446121ea6ae
diff --git a/Cargo.lock b/Cargo.lock
index e560a703a..40d789c14 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -831,6 +831,12 @@ dependencies = [
"libloading 0.8.5",
]
+[[package]]
+name = "claxon"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4bfbf56724aa9eca8afa4fcfadeb479e722935bb2a0900c2d37e0cc477af0688"
+
[[package]]
name = "cocoa"
version = "0.20.2"
@@ -1429,6 +1435,7 @@ dependencies = [
"objc",
"objc2-app-kit",
"reqwest",
+ "rodio",
"scap",
"serde",
"serde_json",
@@ -2526,6 +2533,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
+[[package]]
+name = "hound"
+version = "3.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f"
+
[[package]]
name = "html5ever"
version = "0.26.0"
@@ -3004,6 +3017,17 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
+[[package]]
+name = "lewton"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "777b48df9aaab155475a83a7df3070395ea1ac6902f5cd062b8f2b028075c030"
+dependencies = [
+ "byteorder",
+ "ogg",
+ "tinyvec",
+]
+
[[package]]
name = "libappindicator"
version = "0.9.0"
@@ -3904,6 +3928,15 @@ dependencies = [
"cc",
]
+[[package]]
+name = "ogg"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6951b4e8bf21c8193da321bcce9c9dd2e13c858fe078bf9054a288b419ae5d6e"
+dependencies = [
+ "byteorder",
+]
+
[[package]]
name = "once_cell"
version = "1.19.0"
@@ -4855,6 +4888,20 @@ dependencies = [
"windows-sys 0.52.0",
]
+[[package]]
+name = "rodio"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6006a627c1a38d37f3d3a85c6575418cfe34a5392d60a686d0071e1c8d427acb"
+dependencies = [
+ "claxon",
+ "cpal",
+ "hound",
+ "lewton",
+ "symphonia",
+ "thiserror",
+]
+
[[package]]
name = "rustc-demangle"
version = "0.1.24"
@@ -5548,6 +5595,55 @@ dependencies = [
"serde_json",
]
+[[package]]
+name = "symphonia"
+version = "0.5.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "815c942ae7ee74737bb00f965fa5b5a2ac2ce7b6c01c0cc169bbeaf7abd5f5a9"
+dependencies = [
+ "lazy_static",
+ "symphonia-bundle-mp3",
+ "symphonia-core",
+ "symphonia-metadata",
+]
+
+[[package]]
+name = "symphonia-bundle-mp3"
+version = "0.5.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c01c2aae70f0f1fb096b6f0ff112a930b1fb3626178fba3ae68b09dce71706d4"
+dependencies = [
+ "lazy_static",
+ "log",
+ "symphonia-core",
+ "symphonia-metadata",
+]
+
+[[package]]
+name = "symphonia-core"
+version = "0.5.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "798306779e3dc7d5231bd5691f5a813496dc79d3f56bf82e25789f2094e022c3"
+dependencies = [
+ "arrayvec",
+ "bitflags 1.2.1",
+ "bytemuck",
+ "lazy_static",
+ "log",
+]
+
+[[package]]
+name = "symphonia-metadata"
+version = "0.5.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bc622b9841a10089c5b18e99eb904f4341615d5aa55bbf4eedde1be721a4023c"
+dependencies = [
+ "encoding_rs",
+ "lazy_static",
+ "log",
+ "symphonia-core",
+]
+
[[package]]
name = "syn"
version = "1.0.109"
diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml
index 23923807c..94ac09a7d 100644
--- a/apps/desktop/src-tauri/Cargo.toml
+++ b/apps/desktop/src-tauri/Cargo.toml
@@ -63,6 +63,7 @@ num-traits = "0.2.19"
tempfile = "3.12.0"
ffmpeg-next.workspace = true
chrono = "0.4.38"
+rodio = "0.19.0"
cap-utils = { path = "../../../crates/utils" }
cap-project = { path = "../../../crates/project" }
diff --git a/apps/desktop/src-tauri/sounds/start-recording.ogg b/apps/desktop/src-tauri/sounds/start-recording.ogg
new file mode 100644
index 000000000..3c2937567
Binary files /dev/null and b/apps/desktop/src-tauri/sounds/start-recording.ogg differ
diff --git a/apps/desktop/src-tauri/sounds/stop-recording.ogg b/apps/desktop/src-tauri/sounds/stop-recording.ogg
new file mode 100644
index 000000000..fb1728530
Binary files /dev/null and b/apps/desktop/src-tauri/sounds/stop-recording.ogg differ
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index c8e541c22..8a42fef9c 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -25,6 +25,7 @@ use num_traits::ToBytes;
use objc2_app_kit::NSScreenSaverWindowLevel;
use project_recordings::ProjectRecordings;
use recording::{DisplaySource, InProgressRecording};
+use rodio::{Decoder, OutputStream, Sink};
use serde::{Deserialize, Serialize};
use serde_json::json;
use specta::Type;
@@ -265,6 +266,14 @@ async fn start_recording(app: AppHandle, state: MutableState<'_, App>) -> Result
window.eval("window.location.reload()").unwrap();
window.show().unwrap();
+ if let Ok((_, stream)) = OutputStream::try_default() {
+ let file = std::fs::File::open("sounds/start-recording.ogg").unwrap();
+ let source = Decoder::new(BufReader::new(file)).unwrap();
+ let sink = Sink::try_new(&stream).unwrap();
+ sink.append(source);
+ sink.sleep_until_end();
+ }
+
RecordingStarted.emit(&app).ok();
Ok(())
@@ -367,6 +376,14 @@ async fn stop_recording(app: AppHandle, state: MutableState<'_, App>) -> Result<
.emit(&app)
.ok();
+ if let Ok((_, stream)) = OutputStream::try_default() {
+ let file = std::fs::File::open("sounds/stop-recording.ogg").unwrap();
+ let source = Decoder::new(BufReader::new(file)).unwrap();
+ let sink = Sink::try_new(&stream).unwrap();
+ sink.append(source);
+ sink.sleep_until_end();
+ }
+
Ok(())
}
diff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rs
index 2dd1a2f58..3d006115a 100644
--- a/apps/desktop/src-tauri/src/recording.rs
+++ b/apps/desktop/src-tauri/src/recording.rs
@@ -260,7 +260,7 @@ pub async fn start(
let ffmpeg_process = ffmpeg.start();
- tokio::time::sleep(Duration::from_millis(500)).await;
+ tokio::time::sleep(Duration::from_secs(1)).await;
println!("Starting writing to named pipes");
diff --git a/apps/desktop/src/routes/prev-recordings.tsx b/apps/desktop/src/routes/prev-recordings.tsx
index 71c669ff9..6d519031b 100644
--- a/apps/desktop/src/routes/prev-recordings.tsx
+++ b/apps/desktop/src/routes/prev-recordings.tsx
@@ -157,7 +157,9 @@ export default function () {
const [imageExists, setImageExists] = createSignal(true);
const isLoading = () =>
- copyVideo.isPending || saveVideo.isPending;
+ copyVideo.isPending ||
+ saveVideo.isPending ||
+ uploadVideo.isPending;
createFakeWindowBounds(ref, () => recording.path);
@@ -203,8 +205,9 @@ export default function () {
<div
class={cx(
"w-full h-full absolute inset-0 transition-all",
- isLoading() ||
- "opacity-0 group-hover:opacity-100",
+ isLoading()
+ ? "opacity-100"
+ : "opacity-0 group-hover:opacity-100",
"backdrop-blur bg-gray-500/80 text-white p-2"
)}
>
@@ -242,7 +245,9 @@ export default function () {
forceOpen={copyVideo.isPending}
tooltipPlacement="left"
onClick={() => copyVideo.mutate()}
- disabled={saveVideo.isPending}
+ disabled={
+ saveVideo.isPending || uploadVideo.isPending
+ }
>
<Switch
fallback={<IconCapCopy class="size-[1rem]" />}
@@ -276,7 +281,9 @@ export default function () {
forceOpen={uploadVideo.isPending}
tooltipPlacement="left"
onClick={() => uploadVideo.mutate()}
- disabled={uploadVideo.isPending}
+ disabled={
+ copyVideo.isPending || saveVideo.isPending
+ }
>
<Switch
fallback={
@@ -305,7 +312,9 @@ export default function () {
variant="secondary"
size="sm"
onClick={() => saveVideo.mutate()}
- disabled={copyVideo.isPending}
+ disabled={
+ copyVideo.isPending || uploadVideo.isPending
+ }
>
<Switch fallback="Save">
<Match when={saveVideo.isPending}>
@@ -333,8 +342,10 @@ export default function () {
<div
style={{ color: "white", "font-size": "14px" }}
class={cx(
- "absolute bottom-0 left-0 right-0 font-medium bg-gray-500 bg-opacity-40 backdrop-blur p-2 flex justify-between items-center pointer-events-none transition-all group-hover:opacity-0",
- isLoading() && "opacity-0"
+ "absolute bottom-0 left-0 right-0 font-medium bg-gray-500 bg-opacity-40 backdrop-blur p-2 flex justify-between items-center pointer-events-none transition-all",
+ isLoading()
+ ? "opacity-0"
+ : "group-hover:opacity-0"
)}
>
<p class="flex items-center">