Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

cleanup + upgrade scap

Brendan Alland6aaef7bb661
diff --git a/Cargo.lock b/Cargo.lock
index 17444bee2..5ee0b83f4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5738,7 +5738,7 @@ dependencies = [
[[package]]
name = "scap"
version = "0.0.7"
-source = "git+https://github.com/CapSoftware/scap?rev=b1e140a3fe905c19b845dfea66b3b1aea02f0472#b1e140a3fe905c19b845dfea66b3b1aea02f0472"
+source = "git+https://github.com/CapSoftware/scap?rev=58d4410bf52f#58d4410bf52fb8033be99dcc62a27369a4cbaf32"
dependencies = [
"cocoa 0.25.0",
"core-graphics-helmer-fork",
diff --git a/Cargo.toml b/Cargo.toml
index 9a6e2099d..e77bd9b4f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,7 +20,7 @@ tokio = { version = "1.39.3", features = [
] }
tauri = { version = "2.0.0" }
specta = { version = "=2.0.0-rc.20" }
-scap = { git = "https://github.com/CapSoftware/scap", rev = "b1e140a3fe905c19b845dfea66b3b1aea02f0472" }
+scap = { git = "https://github.com/CapSoftware/scap", rev = "58d4410bf52f" }
nokhwa = { git = "https://github.com/CapSoftware/nokhwa", rev = "0d3d1f30a78b", features = [
"input-native",
"serialize",
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index e52957223..11ddbe30c 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -44,6 +44,7 @@ use specta::Type;
use std::fs::File;
use std::io::BufWriter;
use std::io::{BufReader, Write};
+use std::str::FromStr;
use std::time::{Instant, SystemTime, UNIX_EPOCH};
use std::{
collections::HashMap, marker::PhantomData, path::PathBuf, process::Command, sync::Arc,
@@ -2439,7 +2440,7 @@ pub async fn run() {
match event {
WindowEvent::Destroyed => {
- match CapWindowId::from_label(label) {
+ match CapWindowId::from_str(label).unwrap() {
CapWindowId::Main => {
if let Some(w) = CapWindowId::Camera.get(app) {
w.close().ok();
@@ -2461,10 +2462,9 @@ pub async fn run() {
if let Some(settings) = GeneralSettingsStore::get(app).unwrap_or(None) {
if settings.hide_dock_icon
- && app
- .webview_windows()
- .keys()
- .all(|label| !CapWindowId::from_label(label).activates_dock())
+ && app.webview_windows().keys().all(|label| {
+ !CapWindowId::from_str(label).unwrap().activates_dock()
+ })
{
#[cfg(target_os = "macos")]
app.set_activation_policy(tauri::ActivationPolicy::Accessory)
@@ -2473,7 +2473,7 @@ pub async fn run() {
}
}
WindowEvent::Focused(focused) if *focused => {
- if CapWindowId::from_label(label).activates_dock() {
+ if CapWindowId::from_str(label).unwrap().activates_dock() {
#[cfg(target_os = "macos")]
app.set_activation_policy(tauri::ActivationPolicy::Regular)
.ok();
diff --git a/apps/desktop/src-tauri/src/permissions.rs b/apps/desktop/src-tauri/src/permissions.rs
index d77357ac3..92ae3f99a 100644
--- a/apps/desktop/src-tauri/src/permissions.rs
+++ b/apps/desktop/src-tauri/src/permissions.rs
@@ -1,19 +1,11 @@
use serde::{Deserialize, Serialize};
-#[cfg(target_os = "macos")]
-use cap_media::platform::{AVAuthorizationStatus, AVMediaType};
-#[cfg(target_os = "macos")]
-use core_foundation::boolean::CFBoolean;
-#[cfg(target_os = "macos")]
-use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; // Import CFDictionaryRef
-#[cfg(target_os = "macos")]
-use core_foundation::string::CFString;
-
#[cfg(target_os = "macos")]
#[link(name = "ApplicationServices", kind = "framework")]
extern "C" {
fn AXIsProcessTrusted() -> bool;
- fn AXIsProcessTrustedWithOptions(options: CFDictionaryRef) -> bool;
+ fn AXIsProcessTrustedWithOptions(options: core_foundation::dictionary::CFDictionaryRef)
+ -> bool;
}
#[derive(Serialize, Deserialize, specta::Type)]
@@ -66,6 +58,8 @@ pub fn open_permission_settings(permission: OSPermission) {
pub async fn request_permission(permission: OSPermission) {
#[cfg(target_os = "macos")]
{
+ use cap_media::platform::AVMediaType;
+
match permission {
OSPermission::ScreenRecording => {
scap::request_permission();
@@ -78,7 +72,7 @@ pub async fn request_permission(permission: OSPermission) {
}
#[cfg(target_os = "macos")]
-fn request_av_permission(media_type: AVMediaType) {
+fn request_av_permission(media_type: cap_media::platform::AVMediaType) {
use objc::{runtime::*, *};
use tauri_nspanel::block::ConcreteBlock;
@@ -133,6 +127,22 @@ impl OSPermissionsCheck {
pub fn do_permissions_check(initial_check: bool) -> OSPermissionsCheck {
#[cfg(target_os = "macos")]
{
+ use cap_media::platform::AVMediaType;
+
+ fn check_av_permission(media_type: AVMediaType) -> OSPermissionStatus {
+ use cap_media::platform::AVAuthorizationStatus;
+ use objc::*;
+
+ let cls = objc::class!(AVCaptureDevice);
+ let status: AVAuthorizationStatus =
+ unsafe { msg_send![cls, authorizationStatusForMediaType:media_type.into_ns_str()] };
+ match status {
+ AVAuthorizationStatus::NotDetermined => OSPermissionStatus::Empty,
+ AVAuthorizationStatus::Authorized => OSPermissionStatus::Granted,
+ _ => OSPermissionStatus::Denied,
+ }
+ }
+
OSPermissionsCheck {
screen_recording: {
let result = scap::has_permission();
@@ -159,20 +169,6 @@ pub fn do_permissions_check(initial_check: bool) -> OSPermissionsCheck {
}
}
-#[cfg(target_os = "macos")]
-pub fn check_av_permission(media_type: AVMediaType) -> OSPermissionStatus {
- use objc::*;
-
- let cls = objc::class!(AVCaptureDevice);
- let status: AVAuthorizationStatus =
- unsafe { msg_send![cls, authorizationStatusForMediaType:media_type.into_ns_str()] };
- match status {
- AVAuthorizationStatus::NotDetermined => OSPermissionStatus::Empty,
- AVAuthorizationStatus::Authorized => OSPermissionStatus::Granted,
- _ => OSPermissionStatus::Denied,
- }
-}
-
pub fn check_accessibility_permission() -> OSPermissionStatus {
#[cfg(target_os = "macos")]
{
@@ -193,9 +189,11 @@ pub fn request_accessibility_permission() {
#[cfg(target_os = "macos")]
{
use core_foundation::base::TCFType;
+ use core_foundation::dictionary::CFDictionary; // Import CFDictionaryRef
+ use core_foundation::string::CFString;
let prompt_key = CFString::new("AXTrustedCheckOptionPrompt");
- let prompt_value = CFBoolean::true_value();
+ let prompt_value = core_foundation::boolean::CFBoolean::true_value();
let options =
CFDictionary::from_CFType_pairs(&[(prompt_key.as_CFType(), prompt_value.as_CFType())]);
diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rs
index 3e2a0bde1..bbf36b5af 100644
--- a/apps/desktop/src-tauri/src/windows.rs
+++ b/apps/desktop/src-tauri/src/windows.rs
@@ -1,5 +1,5 @@
#![allow(unused_mut)]
-use std::path::PathBuf;
+use std::{path::PathBuf, str::FromStr};
use tauri::{
AppHandle, LogicalPosition, Manager, WebviewUrl, WebviewWindow, WebviewWindowBuilder, Wry,
@@ -7,19 +7,6 @@ use tauri::{
const DEFAULT_TRAFFIC_LIGHTS_INSET: LogicalPosition<f64> = LogicalPosition::new(12.0, 12.0);
-#[derive(Clone)]
-pub enum ShowCapWindow {
- Setup,
- Main,
- Settings { page: Option<String> },
- Editor { project_id: String },
- PrevRecordings,
- WindowCaptureOccluder,
- Camera { ws_port: u16 },
- InProgressRecording { position: Option<(f64, f64)> },
- Upgrade,
-}
-
#[derive(Clone)]
pub enum CapWindowId {
// Contains onboarding + permissions
@@ -34,9 +21,11 @@ pub enum CapWindowId {
Upgrade,
}
-impl CapWindowId {
- pub fn from_label(label: &str) -> Self {
- match label {
+impl FromStr for CapWindowId {
+ type Err = String;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ Ok(match s {
"setup" => Self::Setup,
"main" => Self::Main,
"settings" => Self::Settings,
@@ -48,23 +37,31 @@ impl CapWindowId {
s if s.starts_with("editor-") => Self::Editor {
project_id: s.replace("editor-", ""),
},
- _ => unreachable!("unknown window label: {}", label),
- }
+ _ => return Err(format!("unknown window label: {}", s)),
+ })
}
+}
- pub fn label(&self) -> String {
+impl std::fmt::Display for CapWindowId {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
- Self::Setup => "setup".to_string(),
- Self::Main => "main".to_string(),
- Self::Settings => "settings".to_string(),
- Self::Camera => "camera".to_string(),
- Self::WindowCaptureOccluder => "window-capture-occluder".to_string(),
- Self::InProgressRecording => "in-progress-recording".to_string(),
- Self::PrevRecordings => "prev-recordings".to_string(),
- Self::Upgrade => "upgrade".to_string(),
- Self::Editor { project_id } => format!("editor-{}", project_id),
+ Self::Setup => write!(f, "setup"),
+ Self::Main => write!(f, "main"),
+ Self::Settings => write!(f, "settings"),
+ Self::Camera => write!(f, "camera"),
+ Self::WindowCaptureOccluder => write!(f, "window-capture-occluder"),
+ Self::InProgressRecording => write!(f, "in-progress-recording"),
+ Self::PrevRecordings => write!(f, "prev-recordings"),
+ Self::Upgrade => write!(f, "upgrade"),
+ Self::Editor { project_id } => write!(f, "editor-{}", project_id),
}
}
+}
+
+impl CapWindowId {
+ pub fn label(&self) -> String {
+ self.to_string()
+ }
pub fn title(&self) -> String {
match self {
@@ -101,6 +98,19 @@ impl CapWindowId {
}
}
+#[derive(Clone)]
+pub enum ShowCapWindow {
+ Setup,
+ Main,
+ Settings { page: Option<String> },
+ Editor { project_id: String },
+ PrevRecordings,
+ WindowCaptureOccluder,
+ Camera { ws_port: u16 },
+ InProgressRecording { position: Option<(f64, f64)> },
+ Upgrade,
+}
+
impl ShowCapWindow {
pub fn show(&self, app: &AppHandle<Wry>) -> tauri::Result<WebviewWindow> {
if let Some(window) = self.id().get(app) {
@@ -317,6 +327,7 @@ impl ShowCapWindow {
}
};
+ #[cfg(target_os = "macos")]
if let Some(position) = id.traffic_lights_position() {
add_traffic_lights(&window, position);
}
@@ -372,35 +383,34 @@ impl ShowCapWindow {
}
}
}
-fn add_traffic_lights(window: &WebviewWindow<Wry>, controls_inset: Option<LogicalPosition<f64>>) {
- #[cfg(target_os = "macos")]
- {
- use crate::platform::delegates;
-
- let target_window = window.clone();
- window
- .run_on_main_thread(move || {
- delegates::setup(
- target_window.as_ref().window(),
- controls_inset.unwrap_or(DEFAULT_TRAFFIC_LIGHTS_INSET),
- );
- let c_win = target_window.clone();
- target_window.on_window_event(move |event| {
- if let tauri::WindowEvent::ThemeChanged(..) = event {
- delegates::position_window_controls(
- delegates::UnsafeWindowHandle(
- c_win
- .ns_window()
- .expect("Failed to get native window handle"),
- ),
- &controls_inset.unwrap_or(DEFAULT_TRAFFIC_LIGHTS_INSET),
- );
- }
- });
- })
- .ok();
- }
+#[cfg(target_os = "macos")]
+fn add_traffic_lights(window: &WebviewWindow<Wry>, controls_inset: Option<LogicalPosition<f64>>) {
+ use crate::platform::delegates;
+
+ let target_window = window.clone();
+ window
+ .run_on_main_thread(move || {
+ delegates::setup(
+ target_window.as_ref().window(),
+ controls_inset.unwrap_or(DEFAULT_TRAFFIC_LIGHTS_INSET),
+ );
+
+ let c_win = target_window.clone();
+ target_window.on_window_event(move |event| {
+ if let tauri::WindowEvent::ThemeChanged(..) = event {
+ delegates::position_window_controls(
+ delegates::UnsafeWindowHandle(
+ c_win
+ .ns_window()
+ .expect("Failed to get native window handle"),
+ ),
+ &controls_inset.unwrap_or(DEFAULT_TRAFFIC_LIGHTS_INSET),
+ );
+ }
+ });
+ })
+ .ok();
}
#[tauri::command]