Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
reimplement permission check with scap
PJ63473ffd33dd
diff --git a/Cargo.lock b/Cargo.lockindex cc2f33403..fb436e70c 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -520,6 +520,7 @@ dependencies = ["bytemuck","byteorder","bytes",+ "capture","chrono","cpal","dotenvy_macro",@@ -3998,7 +3999,6 @@ dependencies = [[[package]]name = "scap"version = "0.0.5"-source = "git+https://github.com/CapSoftware/scap?rev=1b7c70df754ee9c2c4e040266f45d16354367bd7#1b7c70df754ee9c2c4e040266f45d16354367bd7"dependencies = ["apple-sys-helmer-fork","cocoa 0.25.0",diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.tomlindex 7ed8cdfb6..fb9eedc93 100644--- a/apps/desktop/src-tauri/Cargo.toml+++ b/apps/desktop/src-tauri/Cargo.toml@@ -64,7 +64,9 @@ dotenvy_macro = "0.15.7"byteorder = "1.4.3"bytemuck = "1.14.3"regex = "1"-scap = { git = "https://github.com/CapSoftware/scap", rev = "1b7c70df754ee9c2c4e040266f45d16354367bd7" }+# scap = { git = "https://github.com/CapSoftware/scap", rev = "1b7c70df754ee9c2c4e040266f45d16354367bd7" }+capture = { path = "../../../crates/capture" }+scap = { path = "../../../../scap" }image = { version = "0.24.9", features = ["jpeg", "png", "webp"] }sentry = "0.32.2"fix-path-env = { git = "https://github.com/tauri-apps/fix-path-env-rs" }diff --git a/apps/desktop/src-tauri/src/app/commands.rs b/apps/desktop/src-tauri/src/app/commands.rsnew file mode 100644index 000000000..ef2b9b750--- /dev/null+++ b/apps/desktop/src-tauri/src/app/commands.rs@@ -0,0 +1,95 @@+use tauri::Window;+use tauri_plugin_oauth::start;++macro_rules! generate_handler {+ ($($command:ident),*) => {{+ #[cfg(debug_assertions)]+ tauri_specta::ts::export(+ specta::collect_types![$($command),*],+ "../../src/utils/commands.ts"+ ).unwrap();++ tauri::generate_handler![$($command),*]+ }}+}++#[tauri::command]+#[specta::specta]+pub async fn start_server(window: Window) -> Result<u16, String> {+ start(move |url| {+ let _ = window.emit("redirect_uri", url);+ })+ .map_err(|err| err.to_string())+}++#[tauri::command]+#[specta::specta]+pub fn has_screen_capture_access() -> bool {+ scap::has_permission()+}++#[tauri::command]+#[specta::specta]+pub fn open_screen_capture_preferences() {+ #[cfg(target_os = "macos")]+ std::process::Command::new("open")+ .arg("x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture")+ .spawn()+ .expect("failed to open system preferences");+}++#[tauri::command]+#[specta::specta]+pub fn open_mic_preferences() {+ #[cfg(target_os = "macos")]+ std::process::Command::new("open")+ .arg("x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone")+ .spawn()+ .expect("failed to open system preferences");+}++#[tauri::command]+#[specta::specta]+pub fn open_camera_preferences() {+ #[cfg(target_os = "macos")]+ std::process::Command::new("open")+ .arg("x-apple.systempreferences:com.apple.preference.security?Privacy_Camera")+ .spawn()+ .expect("failed to open system preferences");+}++#[tauri::command]+#[specta::specta]+pub fn reset_screen_permissions() {+ #[cfg(target_os = "macos")]+ std::process::Command::new("tccutil")+ .arg("reset")+ .arg("ScreenCapture")+ .arg("so.cap.desktop")+ .spawn()+ .expect("failed to reset screen permissions");+}++#[tauri::command]+#[specta::specta]+pub fn reset_microphone_permissions() {+ #[cfg(target_os = "macos")]+ std::process::Command::new("tccutil")+ .arg("reset")+ .arg("Microphone")+ .arg("so.cap.desktop")+ .spawn()+ .expect("failed to reset microphone permissions");+}++#[tauri::command]+#[specta::specta]+pub fn reset_camera_permissions() {+ #[cfg(target_os = "macos")]+ std::process::Command::new("tccutil")+ .arg("reset")+ .arg("Camera")+ .arg("so.cap.desktop")+ .spawn()+ .expect("failed to reset camera permissions");+}diff --git a/apps/desktop/src-tauri/src/app/mod.rs b/apps/desktop/src-tauri/src/app/mod.rsindex 4e5652649..e695941b8 100644--- a/apps/desktop/src-tauri/src/app/mod.rs+++ b/apps/desktop/src-tauri/src/app/mod.rs@@ -7,6 +7,8 @@ use std::{use tauri::{Assets, Context};use tracing_appender::rolling::RollingFileAppender;+#[macro_use]+pub mod commands;pub mod config;pub fn panic_hook(info: &PanicInfo) {diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rsindex 47f2fe747..5cd4e83f6 100644--- a/apps/desktop/src-tauri/src/main.rs+++ b/apps/desktop/src-tauri/src/main.rs@@ -1,17 +1,14 @@#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]-use cpal::Devices;use regex::Regex;use sentry_tracing::EventFilter;-use std::collections::LinkedList;use std::path::PathBuf;use std::sync::atomic::AtomicBool;use std::sync::Arc;use std::vec;use tauri::{- CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTraySubmenu, Window,+ CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTraySubmenu,};-use tauri_plugin_oauth::start;use tauri_plugin_positioner::{Position, WindowExt};use tokio::sync::Mutex;use tracing::Level;@@ -19,15 +16,16 @@ use tracing_subscriber::prelude::*;use window_shadows::set_shadow;use window_vibrancy::{apply_blur, apply_vibrancy, NSVisualEffectMaterial};+#[macro_use]mod app;mod media;mod recording;mod upload;mod utils;+use app::commands::*;use media::enumerate_audio_devices;use recording::{start_dual_recording, stop_all_recordings, RecordingState};-use utils::has_screen_capture_access;use ffmpeg_sidecar::{command::ffmpeg_is_installed,@@ -39,18 +37,6 @@ use ffmpeg_sidecar::{use winit::monitor::{MonitorHandle, VideoMode};-macro_rules! generate_handler {- ($($command:ident),*) => {{- #[cfg(debug_assertions)]- tauri_specta::ts::export(- specta::collect_types![$($command),*],- "../src/utils/commands.ts"- ).unwrap();-- tauri::generate_handler![$($command),*]- }}-}-fn main() {let _ = fix_path_env::fix();@@ -119,81 +105,6 @@ fn main() {handle_ffmpeg_installation().expect("Failed to install FFmpeg");- #[tauri::command]- #[specta::specta]- async fn start_server(window: Window) -> Result<u16, String> {- start(move |url| {- let _ = window.emit("redirect_uri", url);- })- .map_err(|err| err.to_string())- }-- #[tauri::command]- #[specta::specta]- fn open_screen_capture_preferences() {- #[cfg(target_os = "macos")]- std::process::Command::new("open")- .arg("x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture")- .spawn()- .expect("failed to open system preferences");- }-- #[tauri::command]- #[specta::specta]- fn open_mic_preferences() {- #[cfg(target_os = "macos")]- std::process::Command::new("open")- .arg("x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone")- .spawn()- .expect("failed to open system preferences");- }-- #[tauri::command]- #[specta::specta]- fn open_camera_preferences() {- #[cfg(target_os = "macos")]- std::process::Command::new("open")- .arg("x-apple.systempreferences:com.apple.preference.security?Privacy_Camera")- .spawn()- .expect("failed to open system preferences");- }-- #[tauri::command]- #[specta::specta]- fn reset_screen_permissions() {- #[cfg(target_os = "macos")]- std::process::Command::new("tccutil")- .arg("reset")- .arg("ScreenCapture")- .arg("so.cap.desktop")- .spawn()- .expect("failed to reset screen permissions");- }-- #[tauri::command]- #[specta::specta]- fn reset_microphone_permissions() {- #[cfg(target_os = "macos")]- std::process::Command::new("tccutil")- .arg("reset")- .arg("Microphone")- .arg("so.cap.desktop")- .spawn()- .expect("failed to reset microphone permissions");- }-- #[tauri::command]- #[specta::specta]- fn reset_camera_permissions() {- #[cfg(target_os = "macos")]- std::process::Command::new("tccutil")- .arg("reset")- .arg("Camera")- .arg("so.cap.desktop")- .spawn()- .expect("failed to reset camera permissions");- }-let event_loop = winit::event_loop::EventLoop::new().expect("Failed to create event loop");let monitor: MonitorHandle = event_loop.primary_monitor()@@ -383,7 +294,7 @@ fn main() {if !window.is_focused().unwrap_or(false) {window.set_focus().expect("Error while trying to set focus on main window");}- if(window.is_minimized().unwrap_or(false)) {+ if window.is_minimized().unwrap_or(false) {window.unminimize().expect("Error while trying to unminimize main window");}}diff --git a/apps/desktop/src-tauri/src/utils.rs b/apps/desktop/src-tauri/src/utils.rsindex c49373452..d1061131b 100644--- a/apps/desktop/src-tauri/src/utils.rs+++ b/apps/desktop/src-tauri/src/utils.rs@@ -1,73 +1,6 @@-use capture::{Capturer, Display};use ffmpeg_sidecar::paths::sidecar_dir;-use std::io::ErrorKind::WouldBlock;-use std::panic;use std::path::Path;use std::process::Command;-use std::thread;-use std::time::{Duration, Instant};--#[tauri::command]-#[specta::specta]-pub fn has_screen_capture_access() -> bool {- let display = match Display::primary() {- Ok(display) => display,- Err(_) => return false,- };-- let width = display.width();- let height = display.height();- let one_second = Duration::new(1, 0);- let one_frame = one_second / 60;-- tracing::debug!("width: {}", width);- tracing::debug!("height: {}", height);-- let result = panic::catch_unwind(|| {- let mut capturer = match Capturer::new(display, width, height) {- Ok(capturer) => {- tracing::debug!("Capturer created");- capturer- }- Err(e) => {- tracing::error!("Capturer not created: {}", e);- return false;- }- };-- let start = Instant::now();-- loop {- if start.elapsed() > Duration::from_secs(2) {- tracing::debug!("Loop exited");- return false;- }-- match capturer.frame() {- Ok(_frame) => {- tracing::debug!("Frame captured");- return true;- }- Err(error) => {- if error.kind() == WouldBlock {- thread::sleep(one_frame);- continue;- } else {- tracing::error!("Error: {}", error);- return false;- }- }- };- }- });-- tracing::debug!("Result: {:?}", result);-- match result {- Ok(val) => val,- Err(_) => false,- }-}pub fn run_command(command: &str, args: Vec<&str>) -> Result<(String, String), String> {let output = Command::new(command)