Skip to content

Commit 48a7fe2

Browse files
authored
remove old scap and add permission check to scap-avfoundation (#1337)
* remove old scap and add permission check to scap-avfoundation * remove cfg
1 parent 65deca5 commit 48a7fe2

File tree

12 files changed

+232
-2741
lines changed

12 files changed

+232
-2741
lines changed

Cargo.lock

Lines changed: 21 additions & 295 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ specta = { version = "=2.0.0-rc.20", features = [
2525
] }
2626
serde = { version = "1", features = ["derive"] }
2727

28-
scap = { git = "https://github.com/CapSoftware/scap", rev = "3cefe71561ff" }
2928
nokhwa = { git = "https://github.com/CapSoftware/nokhwa", rev = "b9c8079e82e2", features = [
3029
"input-native",
3130
"serialize",

apps/desktop/src-tauri/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ tauri-plugin-deep-link = "2.2.0"
4545
tauri-plugin-clipboard-manager = "2.2.1"
4646
tauri-plugin-opener = "2.2.6"
4747

48-
scap = { workspace = true }
4948
serde = { workspace = true }
5049
serde_json = "1.0.111"
5150
specta.workspace = true

apps/desktop/src-tauri/src/audio.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ fn play_audio(bytes: &'static [u8]) {
1818
pub enum AppSounds {
1919
StartRecording,
2020
StopRecording,
21-
Screenshot,
2221
Notification,
2322
}
2423

@@ -32,7 +31,6 @@ impl AppSounds {
3231
match self {
3332
AppSounds::StartRecording => include_bytes!("../sounds/start-recording.ogg"),
3433
AppSounds::StopRecording => include_bytes!("../sounds/stop-recording.ogg"),
35-
AppSounds::Screenshot => include_bytes!("../sounds/screenshot.ogg"),
3634
AppSounds::Notification => include_bytes!("../sounds/action.ogg"),
3735
}
3836
}

apps/desktop/src-tauri/src/lib.rs

Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,14 @@ use ffmpeg::ffi::AV_TIME_BASE;
5555
use general_settings::GeneralSettingsStore;
5656
use kameo::{Actor, actor::ActorRef};
5757
use notifications::NotificationType;
58-
use png::{ColorType, Encoder};
5958
use recording::InProgressRecording;
60-
use relative_path::RelativePathBuf;
61-
use scap::{
62-
capturer::Capturer,
63-
frame::{Frame, VideoFrame},
64-
};
6559
use scap_targets::{Display, DisplayId, WindowId, bounds::LogicalBounds};
6660
use serde::{Deserialize, Serialize};
6761
use serde_json::json;
6862
use specta::Type;
6963
use std::{
7064
collections::BTreeMap,
71-
fs::File,
7265
future::Future,
73-
io::BufWriter,
7466
marker::PhantomData,
7567
path::{Path, PathBuf},
7668
process::Command,
@@ -309,9 +301,6 @@ pub struct RequestStartRecording {
309301
pub mode: RecordingMode,
310302
}
311303

312-
#[derive(Deserialize, specta::Type, Serialize, tauri_specta::Event, Debug, Clone)]
313-
pub struct RequestNewScreenshot;
314-
315304
#[derive(Deserialize, specta::Type, Serialize, tauri_specta::Event, Debug, Clone)]
316305
pub struct RequestOpenRecordingPicker {
317306
pub target_mode: Option<RecordingTargetMode>,
@@ -1250,135 +1239,6 @@ async fn upload_screenshot(
12501239
Ok(UploadResult::Success(share_link))
12511240
}
12521241

1253-
#[tauri::command]
1254-
#[specta::specta]
1255-
#[instrument(skip(app, _state))]
1256-
async fn take_screenshot(app: AppHandle, _state: MutableState<'_, App>) -> Result<(), String> {
1257-
let id = uuid::Uuid::new_v4().to_string();
1258-
1259-
let recording_dir = app
1260-
.path()
1261-
.app_data_dir()
1262-
.unwrap()
1263-
.join("screenshots")
1264-
.join(format!("{id}.cap"));
1265-
1266-
std::fs::create_dir_all(&recording_dir).map_err(|e| e.to_string())?;
1267-
1268-
let (width, height, bgra_data) = {
1269-
let options = scap::capturer::Options {
1270-
fps: 1,
1271-
output_type: scap::frame::FrameType::BGRAFrame,
1272-
show_highlight: false,
1273-
..Default::default()
1274-
};
1275-
1276-
if let Some(window) = CapWindowId::Main.get(&app) {
1277-
let _ = window.hide();
1278-
}
1279-
1280-
let mut capturer =
1281-
Capturer::build(options).map_err(|e| format!("Failed to construct error: {e}"))?;
1282-
capturer.start_capture();
1283-
let frame = capturer
1284-
.get_next_frame()
1285-
.map_err(|e| format!("Failed to get frame: {e}"))?;
1286-
capturer.stop_capture();
1287-
1288-
if let Some(window) = CapWindowId::Main.get(&app) {
1289-
let _ = window.show();
1290-
}
1291-
1292-
match frame {
1293-
Frame::Video(VideoFrame::BGRA(bgra_frame)) => Ok((
1294-
bgra_frame.width as u32,
1295-
bgra_frame.height as u32,
1296-
bgra_frame.data,
1297-
)),
1298-
_ => Err("Unexpected frame type".to_string()),
1299-
}
1300-
}?;
1301-
1302-
let now = chrono::Local::now();
1303-
let screenshot_name = format!(
1304-
"Cap {} at {}.png",
1305-
now.format("%Y-%m-%d"),
1306-
now.format("%H.%M.%S")
1307-
);
1308-
let screenshot_path = recording_dir.join(&screenshot_name);
1309-
1310-
let app_handle = app.clone();
1311-
let recording_dir = recording_dir.clone();
1312-
tokio::task::spawn_blocking(move || -> Result<(), String> {
1313-
let mut rgba_data = vec![0; bgra_data.len()];
1314-
for (bgra, rgba) in bgra_data.chunks_exact(4).zip(rgba_data.chunks_exact_mut(4)) {
1315-
rgba[0] = bgra[2];
1316-
rgba[1] = bgra[1];
1317-
rgba[2] = bgra[0];
1318-
rgba[3] = bgra[3];
1319-
}
1320-
1321-
let file = File::create(&screenshot_path).map_err(|e| e.to_string())?;
1322-
let w = &mut BufWriter::new(file);
1323-
1324-
let mut encoder = Encoder::new(w, width, height);
1325-
encoder.set_color(ColorType::Rgba);
1326-
encoder.set_compression(png::Compression::Fast);
1327-
let mut writer = encoder.write_header().map_err(|e| e.to_string())?;
1328-
1329-
writer
1330-
.write_image_data(&rgba_data)
1331-
.map_err(|e| e.to_string())?;
1332-
1333-
AppSounds::Screenshot.play();
1334-
1335-
let now = chrono::Local::now();
1336-
let screenshot_name = format!(
1337-
"Cap {} at {}.png",
1338-
now.format("%Y-%m-%d"),
1339-
now.format("%H.%M.%S")
1340-
);
1341-
1342-
use cap_project::*;
1343-
RecordingMeta {
1344-
platform: Some(Platform::default()),
1345-
project_path: recording_dir.clone(),
1346-
sharing: None,
1347-
pretty_name: screenshot_name,
1348-
inner: RecordingMetaInner::Studio(cap_project::StudioRecordingMeta::SingleSegment {
1349-
segment: cap_project::SingleSegment {
1350-
display: VideoMeta {
1351-
path: RelativePathBuf::from_path(
1352-
screenshot_path.strip_prefix(&recording_dir).unwrap(),
1353-
)
1354-
.unwrap(),
1355-
fps: 0,
1356-
start_time: None,
1357-
},
1358-
camera: None,
1359-
audio: None,
1360-
cursor: None,
1361-
},
1362-
}),
1363-
upload: None,
1364-
}
1365-
.save_for_project()
1366-
.unwrap();
1367-
1368-
NewScreenshotAdded {
1369-
path: screenshot_path,
1370-
}
1371-
.emit(&app_handle)
1372-
.ok();
1373-
1374-
Ok(())
1375-
})
1376-
.await
1377-
.map_err(|e| format!("Task join error: {e}"))??;
1378-
1379-
Ok(())
1380-
}
1381-
13821242
#[tauri::command]
13831243
#[specta::specta]
13841244
#[instrument(skip(app))]
@@ -1970,7 +1830,6 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
19701830
recording::list_windows_with_thumbnails,
19711831
windows::refresh_window_content_protection,
19721832
general_settings::get_default_excluded_windows,
1973-
take_screenshot,
19741833
list_audio_devices,
19751834
close_recordings_overlay_window,
19761835
fake_window::set_fake_window_bounds,
@@ -2050,7 +1909,6 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
20501909
RecordingStopped,
20511910
RequestStartRecording,
20521911
RequestOpenRecordingPicker,
2053-
RequestNewScreenshot,
20541912
RequestOpenSettings,
20551913
RequestScreenCapturePrewarm,
20561914
NewNotification,

apps/desktop/src-tauri/src/permissions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ pub async fn request_permission(_permission: OSPermission) {
7171

7272
match _permission {
7373
OSPermission::ScreenRecording => {
74-
scap::request_permission();
74+
#[cfg(target_os = "macos")]
75+
scap_screencapturekit::request_permission();
7576
}
7677
OSPermission::Camera => {
7778
thread::spawn(|| {
@@ -163,7 +164,7 @@ pub fn do_permissions_check(_initial_check: bool) -> OSPermissionsCheck {
163164

164165
OSPermissionsCheck {
165166
screen_recording: {
166-
let result = scap::has_permission();
167+
let result = scap_screencapturekit::has_permission();
167168
match (result, _initial_check) {
168169
(true, _) => OSPermissionStatus::Granted,
169170
(false, true) => OSPermissionStatus::Empty,

apps/desktop/src-tauri/src/tray.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::windows::ShowCapWindow;
2-
use crate::{
3-
RecordingStarted, RecordingStopped, RequestNewScreenshot, RequestOpenSettings, recording,
4-
};
2+
use crate::{RecordingStarted, RecordingStopped, RequestOpenSettings, recording};
53

64
use std::sync::{
75
Arc,
@@ -20,7 +18,6 @@ use tauri_specta::Event;
2018

2119
pub enum TrayItem {
2220
OpenCap,
23-
TakeScreenshot,
2421
PreviousRecordings,
2522
PreviousScreenshots,
2623
OpenSettings,
@@ -32,7 +29,6 @@ impl From<TrayItem> for MenuId {
3229
fn from(value: TrayItem) -> Self {
3330
match value {
3431
TrayItem::OpenCap => "open_cap",
35-
TrayItem::TakeScreenshot => "take_screenshot",
3632
TrayItem::PreviousRecordings => "previous_recordings",
3733
TrayItem::PreviousScreenshots => "previous_screenshots",
3834
TrayItem::OpenSettings => "open_settings",
@@ -49,7 +45,6 @@ impl TryFrom<MenuId> for TrayItem {
4945
fn try_from(value: MenuId) -> Result<Self, Self::Error> {
5046
match value.0.as_str() {
5147
"open_cap" => Ok(TrayItem::OpenCap),
52-
"take_screenshot" => Ok(TrayItem::TakeScreenshot),
5348
"previous_recordings" => Ok(TrayItem::PreviousRecordings),
5449
"previous_screenshots" => Ok(TrayItem::PreviousScreenshots),
5550
"open_settings" => Ok(TrayItem::OpenSettings),
@@ -114,9 +109,6 @@ pub fn create_tray(app: &AppHandle) -> tauri::Result<()> {
114109
.await;
115110
});
116111
}
117-
Ok(TrayItem::TakeScreenshot) => {
118-
let _ = RequestNewScreenshot.emit(&app_handle);
119-
}
120112
Ok(TrayItem::PreviousRecordings) => {
121113
let _ = RequestOpenSettings {
122114
page: "recordings".to_string(),

apps/desktop/src/routes/(window-chrome)/settings/hotkeys.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const ACTION_TEXT = {
2525
startInstantRecording: "Start instant recording",
2626
restartRecording: "Restart recording",
2727
stopRecording: "Stop recording",
28-
// takeScreenshot: "Take Screenshot",
2928
openRecordingPicker: "Open recording picker",
3029
openRecordingPickerDisplay: "Record display",
3130
openRecordingPickerWindow: "Record window",

apps/desktop/src/utils/tauri.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ async refreshWindowContentProtection() : Promise<null> {
5353
async getDefaultExcludedWindows() : Promise<WindowExclusion[]> {
5454
return await TAURI_INVOKE("get_default_excluded_windows");
5555
},
56-
async takeScreenshot() : Promise<null> {
57-
return await TAURI_INVOKE("take_screenshot");
58-
},
5956
async listAudioDevices() : Promise<string[]> {
6057
return await TAURI_INVOKE("list_audio_devices");
6158
},
@@ -346,7 +343,7 @@ export type AspectRatio = "wide" | "vertical" | "square" | "classic" | "tall"
346343
export type Audio = { duration: number; sample_rate: number; channels: number; start_time: number }
347344
export type AudioConfiguration = { mute: boolean; improve: boolean; micVolumeDb?: number; micStereoMode?: StereoMode; systemVolumeDb?: number }
348345
export type AudioInputLevelChange = number
349-
export type AudioMeta = { path: string;
346+
export type AudioMeta = { path: string;
350347
/**
351348
* unix time of the first frame
352349
*/
@@ -398,11 +395,11 @@ export type Flags = { captions: boolean }
398395
export type FramesRendered = { renderedCount: number; totalFrames: number; type: "FramesRendered" }
399396
export type GeneralSettingsStore = { instanceId?: string; uploadIndividualFiles?: boolean; hideDockIcon?: boolean; hapticsEnabled?: boolean; autoCreateShareableLink?: boolean; enableNotifications?: boolean; disableAutoOpenLinks?: boolean; hasCompletedStartup?: boolean; theme?: AppTheme; commercialLicense?: CommercialLicense | null; lastVersion?: string | null; windowTransparency?: boolean; postStudioRecordingBehaviour?: PostStudioRecordingBehaviour; mainWindowRecordingStartBehaviour?: MainWindowRecordingStartBehaviour; custom_cursor_capture2?: boolean; serverUrl?: string; recordingCountdown?: number | null; enableNativeCameraPreview: boolean; autoZoomOnClicks?: boolean; enableNewRecordingFlow: boolean; postDeletionBehaviour?: PostDeletionBehaviour; excludedWindows?: WindowExclusion[]; deleteInstantRecordingsAfterUpload?: boolean; instantModeMaxResolution?: number }
400397
export type GifExportSettings = { fps: number; resolution_base: XY<number>; quality: GifQuality | null }
401-
export type GifQuality = {
398+
export type GifQuality = {
402399
/**
403400
* Encoding quality from 1-100 (default: 90)
404401
*/
405-
quality: number | null;
402+
quality: number | null;
406403
/**
407404
* Whether to prioritize speed over quality (default: false)
408405
*/
@@ -480,7 +477,7 @@ export type UploadProgress = { progress: number }
480477
export type UploadProgressEvent = { video_id: string; uploaded: string; total: string }
481478
export type UploadResult = { Success: string } | "NotAuthenticated" | "PlanCheckFailed" | "UpgradeRequired"
482479
export type Video = { duration: number; width: number; height: number; fps: number; start_time: number }
483-
export type VideoMeta = { path: string; fps?: number;
480+
export type VideoMeta = { path: string; fps?: number;
484481
/**
485482
* unix time of the first frame
486483
*/

crates/scap-screencapturekit/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
mod capture;
44
mod config;
5+
mod permission;
56

67
pub use capture::{AudioFrame, Capturer, CapturerBuilder, Frame, VideoFrame};
78
pub use config::StreamCfgBuilder;
9+
pub use permission::{has_permission, request_permission};

0 commit comments

Comments
 (0)