Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

WIP for image capture

Richie McIlroyb3b5ea86960b
diff --git a/apps/desktop/src-tauri/.taurignore b/apps/desktop/src-tauri/.taurignore
new file mode 100644
index 000000000..d14744a2b
--- /dev/null
+++ b/apps/desktop/src-tauri/.taurignore
@@ -0,0 +1,2 @@
+/frames
+/frames/*
\ No newline at end of file
diff --git a/apps/desktop/src-tauri/Cargo.lock b/apps/desktop/src-tauri/Cargo.lock
index 0c27feaa2..77374b020 100644
--- a/apps/desktop/src-tauri/Cargo.lock
+++ b/apps/desktop/src-tauri/Cargo.lock
@@ -6,6 +6,8 @@ version = 3
name = "Cap"
version = "0.0.0"
dependencies = [
+ "image",
+ "scrap",
"serde",
"serde_json",
"tauri",
@@ -129,7 +131,7 @@ checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af"
dependencies = [
"async-lock",
"autocfg",
- "cfg-if",
+ "cfg-if 1.0.0",
"concurrent-queue",
"futures-lite",
"log",
@@ -148,7 +150,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10da8f3146014722c89e7859e1d7bb97873125d7346d10ca642ffab794355828"
dependencies = [
"async-lock",
- "cfg-if",
+ "cfg-if 1.0.0",
"concurrent-queue",
"futures-io",
"futures-lite",
@@ -180,7 +182,7 @@ dependencies = [
"async-lock",
"async-signal",
"blocking",
- "cfg-if",
+ "cfg-if 1.0.0",
"event-listener 3.0.1",
"futures-lite",
"rustix 0.38.20",
@@ -207,7 +209,7 @@ dependencies = [
"async-io 2.1.0",
"async-lock",
"atomic-waker",
- "cfg-if",
+ "cfg-if 1.0.0",
"futures-core",
"futures-io",
"rustix 0.38.20",
@@ -277,7 +279,7 @@ checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
dependencies = [
"addr2line",
"cc",
- "cfg-if",
+ "cfg-if 1.0.0",
"libc",
"miniz_oxide",
"object",
@@ -482,6 +484,12 @@ dependencies = [
"target-lexicon",
]
+[[package]]
+name = "cfg-if"
+version = "0.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -617,7 +625,7 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
]
[[package]]
@@ -626,7 +634,7 @@ version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"crossbeam-utils",
]
@@ -636,7 +644,7 @@ version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"crossbeam-epoch",
"crossbeam-utils",
]
@@ -648,7 +656,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
dependencies = [
"autocfg",
- "cfg-if",
+ "cfg-if 1.0.0",
"crossbeam-utils",
"memoffset 0.9.0",
"scopeguard",
@@ -660,7 +668,7 @@ version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
]
[[package]]
@@ -801,7 +809,7 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"dirs-sys-next",
]
@@ -813,7 +821,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -874,7 +882,7 @@ version = "0.8.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
]
[[package]]
@@ -987,7 +995,7 @@ version = "0.2.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4029edd3e734da6fe05b6cd7bd2960760a616bd2ddd0d59a0124746d6272af0"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"libc",
"redox_syscall 0.3.5",
"windows-sys 0.48.0",
@@ -1263,7 +1271,7 @@ version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"libc",
"wasi 0.9.0+wasi-snapshot-preview1",
]
@@ -1274,7 +1282,7 @@ version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
]
@@ -1322,7 +1330,7 @@ dependencies = [
"gobject-sys",
"libc",
"system-deps 6.1.2",
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -1749,7 +1757,7 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
]
[[package]]
@@ -1927,8 +1935,8 @@ version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
dependencies = [
- "cfg-if",
- "winapi",
+ "cfg-if 1.0.0",
+ "winapi 0.3.9",
]
[[package]]
@@ -1974,7 +1982,7 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"generator",
"scoped-tls",
"serde",
@@ -2164,7 +2172,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
dependencies = [
"bitflags 1.3.2",
- "cfg-if",
+ "cfg-if 1.0.0",
"libc",
"memoffset 0.7.1",
]
@@ -2195,7 +2203,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -2330,7 +2338,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9dfc0783362704e97ef3bd24261995a699468440099ef95d869b4d9732f829a"
dependencies = [
"bitflags 2.4.1",
- "cfg-if",
+ "cfg-if 1.0.0",
"foreign-types",
"libc",
"once_cell",
@@ -2385,7 +2393,7 @@ checksum = "006e42d5b888366f1880eda20371fedde764ed2213dc8496f49622fa0c99cd5e"
dependencies = [
"log",
"serde",
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -2451,7 +2459,7 @@ version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"libc",
"redox_syscall 0.4.1",
"smallvec",
@@ -2642,7 +2650,7 @@ checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce"
dependencies = [
"autocfg",
"bitflags 1.3.2",
- "cfg-if",
+ "cfg-if 1.0.0",
"concurrent-queue",
"libc",
"log",
@@ -2656,7 +2664,7 @@ version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e53b6af1f60f36f8c2ac2aad5459d75a5a9b4be1e8cdd40264f315d78193e531"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"concurrent-queue",
"pin-project-lite",
"rustix 0.38.20",
@@ -3101,6 +3109,18 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
+[[package]]
+name = "scrap"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "04f3e5e5b3bd8d65b04de768fe0bdbd1e2da0831be9f117e1cc1d71785c9126c"
+dependencies = [
+ "block",
+ "cfg-if 0.1.10",
+ "libc",
+ "winapi 0.2.8",
+]
+
[[package]]
name = "security-framework"
version = "2.9.2"
@@ -3283,7 +3303,7 @@ version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"cpufeatures",
"digest",
]
@@ -3294,7 +3314,7 @@ version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"cpufeatures",
"digest",
]
@@ -3315,7 +3335,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef"
dependencies = [
"libc",
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -3361,7 +3381,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d"
dependencies = [
"libc",
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -3751,7 +3771,7 @@ dependencies = [
"objc",
"serde",
"tauri",
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -3863,7 +3883,7 @@ version = "3.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"fastrand 2.0.1",
"redox_syscall 0.3.5",
"rustix 0.38.20",
@@ -3913,7 +3933,7 @@ version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"once_cell",
]
@@ -4175,7 +4195,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce65604324d3cce9b966701489fbd0cf318cb1f7bd9dd07ac9a4ee6fb791930d"
dependencies = [
"tempfile",
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -4325,7 +4345,7 @@ version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"wasm-bindgen-macro",
]
@@ -4350,7 +4370,7 @@ version = "0.4.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"js-sys",
"wasm-bindgen",
"web-sys",
@@ -4499,6 +4519,12 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
+[[package]]
+name = "winapi"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
+
[[package]]
name = "winapi"
version = "0.3.9"
@@ -4521,7 +4547,7 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
dependencies = [
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -4839,7 +4865,7 @@ version = "0.50.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"windows-sys 0.48.0",
]
@@ -4849,7 +4875,7 @@ version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "937f3df7948156640f46aacef17a70db0de5917bda9c92b0f751f3a955b588fc"
dependencies = [
- "cfg-if",
+ "cfg-if 1.0.0",
"windows-sys 0.48.0",
]
@@ -4928,7 +4954,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2769203cd13a0c6015d515be729c526d041e9cf2c0cc478d57faee85f40c6dcd"
dependencies = [
"nix",
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -4965,7 +4991,7 @@ dependencies = [
"static_assertions",
"tracing",
"uds_windows",
- "winapi",
+ "winapi 0.3.9",
"xdg-home",
"zbus_macros",
"zbus_names",
diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml
index ae1542f3c..99d99614f 100644
--- a/apps/desktop/src-tauri/Cargo.toml
+++ b/apps/desktop/src-tauri/Cargo.toml
@@ -18,6 +18,8 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri-plugin-context-menu = "0.5.0"
tauri-plugin-positioner = { version = "1.0", features = ["system-tray"] }
+scrap = "0.5.0"
+image = "0.24.7"
[features]
# this feature is used for production builds or when `devPath` points to the filesystem
diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs
index ada8c877b..c274335ed 100644
--- a/apps/desktop/src-tauri/src/main.rs
+++ b/apps/desktop/src-tauri/src/main.rs
@@ -1,11 +1,81 @@
-// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
+extern crate scrap;
+
+use scrap::{Capturer, Display};
+use std::io::ErrorKind::WouldBlock;
+use std::thread;
+use std::time::Duration;
+use std::path::Path;
+use std::fs;
+use tauri::Manager;
+use image::{ImageBuffer, RgbaImage, Pixel, Rgba};
+
+// Define a command that can be invoked from the frontend
+#[tauri::command]
+fn take_screenshot() -> Result<(), String> {
+ let frames_dir = Path::new("frames");
+ if let Err(e) = fs::create_dir_all(&frames_dir) {
+ return Err(format!("Failed to create frames directory: {}", e));
+ }
+
+ let one_frame = Duration::from_nanos(16666667); // Approx. 1/60 second
+
+ let display = Display::primary().map_err(|e| format!("Couldn't find primary display: {}", e))?;
+ let mut capturer = Capturer::new(display).map_err(|e| format!("Couldn't begin capture: {}", e))?;
+ let (w, h) = (capturer.width(), capturer.height());
+
+ // Log width and height
+ println!("Width: {}, Height: {}", w, h);
+
+ // Attempt to capture a frame, retrying if needed
+ let buffer = loop {
+ match capturer.frame() {
+ Ok(buffer) => break buffer,
+ Err(error) if error.kind() == WouldBlock => {
+ thread::sleep(one_frame);
+ continue;
+ },
+ Err(e) => return Err(format!("Error capturing frame: {}", e)),
+ }
+ };
+
+ println!("Captured! Processing...");
+
+ // Convert BGRA to RGBA
+ let mut rgba_buffer = Vec::with_capacity(buffer.len());
+ for chunk in buffer.chunks_exact(4) {
+ let bgra = [chunk[0], chunk[1], chunk[2], chunk[3]];
+ let rgba = Rgba::from_channels(bgra[2], bgra[1], bgra[0], bgra[3]);
+ rgba_buffer.extend_from_slice(&rgba.0);
+ }
+
+ // Attempt to create an RgbaImage from the converted buffer.
+ let image: RgbaImage = ImageBuffer::from_vec(w as u32, h as u32, rgba_buffer)
+ .ok_or_else(|| "Creating the image buffer failed".to_string())?;
+
+ let scaled_width = (w as f32 * 0.5) as u32; // Reducing width to 50%
+ let scaled_height = (h as f32 * 0.5) as u32; // Reducing height to 50%
+ let resized_image = image::imageops::resize(
+ &image,
+ scaled_width,
+ scaled_height,
+ image::imageops::FilterType::Lanczos3, // High-quality filter
+ );
+
+ // Save the image
+ let image_path = frames_dir.join("screenshot.png");
+ resized_image.save(&image_path)
+ .map_err(|e| format!("Failed to save screenshot: {}", e))?;
+
+ println!("Image saved as `screenshot.png`.");
+ Ok(())
+}
+
fn main() {
tauri::Builder::default()
- .plugin(tauri_plugin_context_menu::init())
+ .plugin(tauri_plugin_context_menu::init()) // Ensure you have this plugin in your dependencies
+ .invoke_handler(tauri::generate_handler![take_screenshot])
.run(tauri::generate_context!())
- .expect("error while running tauri application");
-}
-
-
+ .expect("Failed to run Tauri application");
+}
\ No newline at end of file
diff --git a/apps/desktop/src/components/FloatingOptions.tsx b/apps/desktop/src/components/FloatingOptions.tsx
index c16f5cf9d..392485545 100644
--- a/apps/desktop/src/components/FloatingOptions.tsx
+++ b/apps/desktop/src/components/FloatingOptions.tsx
@@ -1,29 +1,29 @@
import { useEffect, useState } from "react";
import {
ReactMediaRecorder,
- useDisplayRecorder,
+ // useDisplayRecorder,
} from "@/utils/recording/client";
import { useMediaDevices } from "@/utils/recording/MediaDeviceContext";
import { Video } from "@/components/icons/Video";
import { Microphone } from "@/components/icons/Microphone";
-import { Screen } from "@/components/icons/Screen";
-import { Window } from "@/components/icons/Window";
+// import { Screen } from "@/components/icons/Screen";
+// import { Window } from "@/components/icons/Window";
import { ActionButton } from "@/components/recording/ActionButton";
import { Button } from "@/components/Button";
import { Logo } from "@/components/icons/Logo";
import { emit } from "@tauri-apps/api/event";
import { showMenu } from "tauri-plugin-context-menu";
+import { invoke } from "@tauri-apps/api/tauri";
-type DisplayType = {
- label: string;
- track: MediaStreamTrack;
- type: string;
-} | null;
+// type DisplayType = {
+// label: string;
+// track: MediaStreamTrack;
+// type: string;
+// } | null;
export const FloatingOptions = () => {
const [foundDevices, setFoundDevices] = useState<MediaDeviceInfo[]>([]);
const { selectedVideoDevice, selectedAudioDevice } = useMediaDevices();
- const [selectedDisplay, setSelectedDisplay] = useState<DisplayType>(null);
useEffect(() => {
const fetchAndEmitDevices = async () => {
@@ -80,75 +80,68 @@ export const FloatingOptions = () => {
fetchAndEmitDevices();
}, []);
- // Helper function to handle "Screen" or "Window" selection
- const selectScreenOrWindow = async (sourceType: string) => {
- try {
- // Use the getDisplayMedia API for screen capture options
- const stream = (await navigator.mediaDevices.getDisplayMedia({
- video: true,
- audio: false,
- })) as MediaStream;
-
- if (stream.getVideoTracks().length === 0) {
- return;
- }
- // Now you should have access to the id, label and other properties of the chosen screen or window
- const track = stream.getVideoTracks()[0];
- const label = track ? track.label : "No Label";
-
- // After selection, save it in the state
- setSelectedDisplay({ label, track, type: sourceType });
-
- // stream.getTracks().forEach((t) => t.stop()); // Stop the stream if you don't need it running
- } catch (error) {
- console.error("Failed to select screen or window:", error);
- }
- };
+ // // Helper function to handle "Screen" or "Window" selection
+ // const selectScreenOrWindow = async (sourceType: string) => {
+ // try {
+ // // Use the getDisplayMedia API for screen capture options
+ // const stream = (await navigator.mediaDevices.getDisplayMedia({
+ // video: {
+ // displaySurface: "monitor",
+ // },
+ // audio: false,
+ // })) as MediaStream;
+
+ // if (stream.getVideoTracks().length === 0) {
+ // return;
+ // }
+ // // Now you should have access to the id, label and other properties of the chosen screen or window
+ // const track = stream.getVideoTracks()[0];
+ // const label = track ? track.label : "No Label";
+
+ // // After selection, save it in the state
+ // setSelectedDisplay({ label, track, type: sourceType });
+
+ // // stream.getTracks().forEach((t) => t.stop()); // Stop the stream if you don't need it running
+ // } catch (error) {
+ // console.error("Failed to select screen or window:", error);
+ // }
+ // };
const handleContextClick = async (option: string) => {
- if (option === "screen" || option === "window") {
- // Call the selectScreenOrWindow function when "Screen" or "Window" is clicked
- selectScreenOrWindow(option);
- } else {
- // The existing logic to handle selection of video or audio devices
- const filteredDevices = foundDevices
- .filter((device) =>
+ const filteredDevices = foundDevices
+ .filter((device) =>
+ option === "video"
+ ? device.kind === "videoinput"
+ : device.kind === "audioinput"
+ )
+ .map((device) => ({
+ label: device.label,
+ disabled:
option === "video"
- ? device.kind === "videoinput"
- : device.kind === "audioinput"
- )
- .map((device) => ({
- label: device.label,
- disabled:
- option === "video"
- ? device.deviceId === selectedVideoDevice?.deviceId
- : device.deviceId === selectedAudioDevice?.deviceId,
- event: async () => {
- try {
- await emit("change-device", { type: option, device });
- } catch (error) {
- console.error("Failed to emit change-device event:", error);
- }
+ ? device.deviceId === selectedVideoDevice?.deviceId
+ : device.deviceId === selectedAudioDevice?.deviceId,
+ event: async () => {
+ try {
+ await emit("change-device", { type: option, device });
+ } catch (error) {
+ console.error("Failed to emit change-device event:", error);
+ }
+ },
+ }));
+
+ // Show a context menu or dialog with the filtered devices
+ showMenu({
+ items: [...filteredDevices],
+ ...(filteredDevices.length === 0 && {
+ items: [
+ {
+ label: "Nothing found.",
},
- }));
-
- // Show a context menu or dialog with the filtered devices
- showMenu({
- items: [...filteredDevices],
- ...(filteredDevices.length === 0 && {
- items: [
- {
- label: "Nothing found.",
- },
- ],
- }),
- });
- }
+ ],
+ }),
+ });
};
- console.log("selectedisplayinnner: ");
- console.log(selectedDisplay);
-
return (
<ReactMediaRecorder
video={
@@ -162,25 +155,15 @@ export const FloatingOptions = () => {
: undefined
}
render={({ status, startRecording, stopRecording }) => {
- const {
- startRecording: startDisplayRecording,
- stopRecording: stopDisplayRecording,
- screenBlobUrl,
- } = useDisplayRecorder(
- selectedDisplay?.track
- ? new MediaStream([selectedDisplay.track])
- : null
- );
-
- const handleStartAllRecordings = () => {
+ const handleStartAllRecordings = async () => {
startRecording(); // Starts webcam recording
- startDisplayRecording(); // Starts display recording
+ await invoke("take_screenshot");
};
// Similarly, for stopping all recordings
const handleStopAllRecordings = () => {
stopRecording(); // Stops webcam recording
- stopDisplayRecording(); // Stops display recording
+ // stopDisplayRecording(); // Stops display recording
};
return (
@@ -204,7 +187,7 @@ export const FloatingOptions = () => {
</div> */}
</div>
<div className="space-y-4 w-full">
- <div>
+ {/* <div>
<label className="text-sm font-medium">
Display Settings
</label>
@@ -229,7 +212,7 @@ export const FloatingOptions = () => {
}
/>
</div>
- </div>
+ </div> */}
<div>
<label className="text-sm font-medium">Webcam Settings</label>
<div className="space-y-1">
@@ -260,9 +243,6 @@ export const FloatingOptions = () => {
label="Start Recording"
/>
)}
- {screenBlobUrl !== null && (
- <video src={screenBlobUrl} controls />
- )}
</div>
</div>
</div>