Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

recording permissions

Brendan Allanaed6ef96e1d9
diff --git a/Cargo.lock b/Cargo.lock
index 6589d8a95..a5dd411d7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1560,6 +1560,7 @@ dependencies = [
"tauri-plugin-dialog",
"tauri-plugin-fs",
"tauri-plugin-os",
+ "tauri-plugin-process",
"tauri-plugin-shell",
"tauri-plugin-store",
"tauri-specta",
@@ -5725,6 +5726,16 @@ dependencies = [
"thiserror",
]
+[[package]]
+name = "tauri-plugin-process"
+version = "2.0.0-rc.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "96d3663df0cd3e96feb37d46aad5d499d2edfcca5c62548ad34f1684e0019168"
+dependencies = [
+ "tauri",
+ "tauri-plugin",
+]
+
[[package]]
name = "tauri-plugin-shell"
version = "2.0.0-rc.0"
diff --git a/apps/desktop-solid/package.json b/apps/desktop-solid/package.json
index 72279e66a..2a3dcb809 100644
--- a/apps/desktop-solid/package.json
+++ b/apps/desktop-solid/package.json
@@ -33,6 +33,7 @@
"@tauri-apps/plugin-os": "2.0.0-rc.1",
"@tauri-apps/plugin-shell": ">=2.0.0-rc.0",
"@tauri-apps/plugin-store": "2.0.0-rc.0",
+ "@tauri-apps/plugin-process": "2.0.0-rc.0",
"@types/react-tooltip": "^4.2.4",
"cva": "npm:class-variance-authority@^0.7.0",
"effect": "^3.7.2",
diff --git a/apps/desktop-solid/src-tauri/Cargo.toml b/apps/desktop-solid/src-tauri/Cargo.toml
index 4759d09fa..81a0ffc79 100644
--- a/apps/desktop-solid/src-tauri/Cargo.toml
+++ b/apps/desktop-solid/src-tauri/Cargo.toml
@@ -63,6 +63,7 @@ ffmpeg-next = "7.0.4"
chrono = "0.4.38"
tauri-plugin-store = "2.0.0-rc.0"
tauri-plugin-os = "2.0.0-rc.0"
+tauri-plugin-process = "2.0.0-rc.0"
[target.'cfg(target_os = "macos")'.dependencies]
core-graphics = "0.24.0"
diff --git a/apps/desktop-solid/src-tauri/capabilities/default.json b/apps/desktop-solid/src-tauri/capabilities/default.json
index 2b78c5577..23de10311 100644
--- a/apps/desktop-solid/src-tauri/capabilities/default.json
+++ b/apps/desktop-solid/src-tauri/capabilities/default.json
@@ -20,6 +20,7 @@
"shell:default",
"fs:default",
"dialog:allow-save",
- "store:default"
+ "store:default",
+ "process:default"
]
}
diff --git a/apps/desktop-solid/src-tauri/src/lib.rs b/apps/desktop-solid/src-tauri/src/lib.rs
index 8262dbd12..6625acbe1 100644
--- a/apps/desktop-solid/src-tauri/src/lib.rs
+++ b/apps/desktop-solid/src-tauri/src/lib.rs
@@ -4,6 +4,7 @@ mod display;
mod editor;
mod editor_instance;
mod macos;
+mod permissions;
mod playback;
mod project_recordings;
mod recording;
@@ -35,7 +36,7 @@ use std::{
collections::HashMap, marker::PhantomData, path::PathBuf, process::Command, sync::Arc,
time::Duration,
};
-use tauri::{AppHandle, Manager, State, WebviewUrl, WebviewWindow, WindowEvent};
+use tauri::{AppHandle, Manager, State, WebviewUrl, WebviewWindow, WindowEvent, Wry};
use tauri_nspanel::{cocoa::appkit::NSMainMenuWindowLevel, ManagerExt};
use tauri_plugin_decorum::WebviewWindowExt;
use tauri_specta::Event;
@@ -566,7 +567,7 @@ struct SerializedEditorInstance {
recording_duration: f64,
saved_project_config: Option<ProjectConfiguration>,
recordings: ProjectRecordings,
- path: PathBuf
+ path: PathBuf,
}
#[tauri::command]
@@ -1047,6 +1048,36 @@ fn list_audio_devices() -> Vec<String> {
devices.keys().cloned().collect()
}
+#[tauri::command]
+#[specta::specta]
+fn open_main_window(app: AppHandle) {
+ if let Some(window) = app.get_webview_window("main") {
+ window.set_focus().ok();
+ return;
+ }
+
+ let Some(window) = WebviewWindow::builder(&app, "main", tauri::WebviewUrl::App("/".into()))
+ .title("Cap")
+ .inner_size(300.0, 325.0)
+ .resizable(false)
+ .maximized(false)
+ .shadow(true)
+ .accept_first_mouse(true)
+ .transparent(true)
+ .hidden_title(true)
+ .title_bar_style(tauri::TitleBarStyle::Overlay)
+ .theme(Some(tauri::Theme::Light))
+ .build()
+ .ok()
+ else {
+ return;
+ };
+
+ window.create_overlay_titlebar().unwrap();
+ #[cfg(target_os = "macos")]
+ window.set_traffic_lights_inset(14.0, 22.0).unwrap();
+}
+
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let specta_builder = tauri_specta::Builder::new()
@@ -1077,7 +1108,10 @@ pub fn run() {
set_playhead_position,
open_in_finder,
save_project_config,
- open_editor
+ open_editor,
+ open_main_window,
+ permissions::open_permission_settings,
+ permissions::do_permissions_check
])
.events(tauri_specta::collect_events![
RecordingOptionsChanged,
@@ -1102,6 +1136,7 @@ pub fn run() {
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_store::Builder::new().build())
.plugin(tauri_plugin_os::init())
+ .plugin(tauri_plugin_process::init())
.invoke_handler(specta_builder.invoke_handler())
.setup(move |app| {
specta_builder.mount_events(app);
@@ -1112,10 +1147,11 @@ pub fn run() {
panic!("Failed to install FFmpeg, which is required for Cap to function. Shutting down now")
};
- let main_window = app.get_webview_window("main").unwrap();
- main_window.create_overlay_titlebar().unwrap();
- #[cfg(target_os = "macos")]
- main_window.set_traffic_lights_inset(14.0, 22.0).unwrap();
+ if permissions::do_permissions_check().necessary_granted() {
+ open_main_window(app.handle().clone());
+ } else {
+ permissions::open_permissions_window(app);
+ }
app.manage(Arc::new(RwLock::new(App {
handle: app.handle().clone(),
diff --git a/apps/desktop-solid/src-tauri/src/permissions.rs b/apps/desktop-solid/src-tauri/src/permissions.rs
new file mode 100644
index 000000000..7133c5165
--- /dev/null
+++ b/apps/desktop-solid/src-tauri/src/permissions.rs
@@ -0,0 +1,96 @@
+use std::process::Command;
+
+use serde::{Deserialize, Serialize};
+use tauri::{Manager, WebviewUrl, WebviewWindow, Wry};
+use tauri_plugin_decorum::WebviewWindowExt;
+
+#[derive(Serialize, Deserialize, specta::Type)]
+#[serde(rename_all = "camelCase")]
+pub enum MacOSPermissionSettings {
+ ScreenRecording,
+ // Accessibility,
+}
+
+#[derive(Serialize, Deserialize, specta::Type)]
+#[serde(rename_all = "camelCase")]
+pub enum OSPermissionSettings {
+ MacOS(MacOSPermissionSettings),
+}
+
+#[tauri::command]
+#[specta::specta]
+pub fn open_permission_settings(settings: OSPermissionSettings) {
+ match settings {
+ OSPermissionSettings::MacOS(macos) => match macos {
+ MacOSPermissionSettings::ScreenRecording => {
+ Command::new("open")
+ .arg("x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture")
+ .spawn()
+ .expect("Failed to open Screen Recording settings");
+ } // MacOSPermissionSettings::Accessibility => {
+ // Command::new("open")
+ // .arg("x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")
+ // .spawn()
+ // .expect("Failed to open Accessibility settings");
+ // }
+ },
+ }
+}
+
+#[derive(Serialize, Deserialize, specta::Type)]
+#[serde(rename_all = "camelCase")]
+pub struct MacOSPermissionsCheck {
+ screen_recording: bool,
+}
+
+#[derive(Serialize, Deserialize, specta::Type)]
+#[serde(rename_all = "camelCase", tag = "os")]
+pub enum OSPermissionsCheck {
+ MacOS(MacOSPermissionsCheck),
+ Other
+}
+
+impl OSPermissionsCheck {
+ pub fn necessary_granted(&self) -> bool {
+ match self {
+ Self::MacOS(macos) => macos.screen_recording,
+ Self::Other => true
+ }
+ }
+}
+
+#[tauri::command]
+#[specta::specta]
+pub fn do_permissions_check() -> OSPermissionsCheck {
+ #[cfg(target_os = "macos")]
+ {
+ OSPermissionsCheck::MacOS(MacOSPermissionsCheck {
+ screen_recording: scap::has_permission(),
+ })
+ }
+
+ #[cfg(not(target_os = "macos"))]
+ OSpermissiosCheck::Other
+}
+
+#[tauri::command]
+#[specta::specta]
+pub fn open_permissions_window(app: &impl Manager<Wry>) {
+ if let Some(window) = app.get_webview_window("permissions") {
+ window.set_focus().ok();
+ return;
+ }
+
+ WebviewWindow::builder(app, "permissions", WebviewUrl::App("/permissions".into()))
+ .title("Cap Permissions")
+ .inner_size(300.0, 325.0)
+ .resizable(false)
+ .maximized(false)
+ .shadow(true)
+ .accept_first_mouse(true)
+ .transparent(true)
+ .hidden_title(true)
+ .decorations(false)
+ .build()
+ .ok();
+}
diff --git a/apps/desktop-solid/src-tauri/tauri.conf.json b/apps/desktop-solid/src-tauri/tauri.conf.json
index 026a69174..a96229756 100644
--- a/apps/desktop-solid/src-tauri/tauri.conf.json
+++ b/apps/desktop-solid/src-tauri/tauri.conf.json
@@ -11,21 +11,6 @@
},
"app": {
"macOSPrivateApi": true,
- "windows": [
- {
- "title": "Cap",
- "width": 300,
- "height": 325,
- "resizable": false,
- "maximized": false,
- "shadow": true,
- "acceptFirstMouse": true,
- "transparent": true,
- "hiddenTitle": true,
- "titleBarStyle": "Overlay",
- "theme": "Light"
- }
- ],
"security": {
"csp": null,
"assetProtocol": {
diff --git a/apps/desktop-solid/src/routes/index.tsx b/apps/desktop-solid/src/routes/index.tsx
index 47a429c8d..dc126df0d 100644
--- a/apps/desktop-solid/src/routes/index.tsx
+++ b/apps/desktop-solid/src/routes/index.tsx
@@ -46,9 +46,6 @@ export default function () {
type CameraOption = MediaDeviceInfo | { deviceId: string; label: string };
- // const navigate = useNavigate();
- // navigate("/recording-permissions");
-
const handleBodyClick = (e: MouseEvent) => {
if (windowSelectOpen()) {
const target = e.target as HTMLElement;
diff --git a/apps/desktop-solid/src/routes/permissions.tsx b/apps/desktop-solid/src/routes/permissions.tsx
new file mode 100644
index 000000000..a75850f96
--- /dev/null
+++ b/apps/desktop-solid/src/routes/permissions.tsx
@@ -0,0 +1,92 @@
+import { cx } from "cva";
+import { Button } from "@cap/ui-solid";
+import { exit } from "@tauri-apps/plugin-process";
+
+import { commands } from "../utils/tauri";
+import { createEffect, createResource, Suspense, Switch } from "solid-js";
+import { Match } from "solid-js";
+import { createTimer } from "@solid-primitives/timer";
+import { getCurrentWindow } from "@tauri-apps/api/window";
+
+export default function () {
+ const [check, checkActions] = createResource(() =>
+ commands.doPermissionsCheck()
+ );
+
+ createTimer(() => checkActions.refetch(), 100, setInterval);
+
+ const permissionsGranted = () => {
+ const c = check.latest;
+ if (c?.os === "macOS") return c?.screenRecording;
+ };
+
+ createEffect(() => {
+ if (permissionsGranted()) {
+ commands.openMainWindow();
+ const window = getCurrentWindow();
+ window.close();
+ }
+ });
+
+ return (
+ <div class="rounded-lg bg-gray-50 w-screen h-screen text-sm flex flex-col divide-y divide-gray-200">
+ <div
+ class={cx(
+ "pl-[1rem] flex flex-row items-center font-[500] h-[2.9rem] shrink-0"
+ )}
+ data-tauri-drag-region
+ >
+ <span data-tauri-drag-region>Recording Permissions</span>
+ </div>
+ <Suspense fallback={<div class="w-full flex-1 bg-gray-100" />}>
+ <Switch>
+ <Match
+ when={(() => {
+ const c = check.latest;
+ if (c?.os === "macOS") return c;
+ })()}
+ >
+ {(check) => (
+ <div class="flex flex-col items-center justify-center gap-4 flex-1">
+ <div class="flex flex-col items-center gap-2">
+ <span>Screen Recording Permission</span>
+ {check().screenRecording ? (
+ <span>Granted</span>
+ ) : (
+ <Button
+ onClick={() => {
+ commands.openPermissionSettings({
+ macOS: "screenRecording",
+ });
+ }}
+ >
+ Open Settings
+ </Button>
+ )}
+ </div>
+ {/*<div class="flex flex-col items-center gap-2">
+ <span>Accessibility Permission</span>
+ <Button
+ onClick={() => {
+ commands.openPermissionSettings({ macOS: "accessibility" });
+ }}
+ >
+ Open Settings
+ </Button>
+ </div>*/}
+ </div>
+ )}
+ </Match>
+ </Switch>
+ </Suspense>
+ <div class="flex flex-row-reverse p-2 gap-2">
+ <Button disabled={!permissionsGranted()}>
+ {permissionsGranted() ? "Continue" : "Waiting"}
+ </Button>
+ <Button variant="secondary" onClick={() => exit()}>
+ Quit
+ </Button>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/desktop-solid/src/utils/tauri.ts b/apps/desktop-solid/src/utils/tauri.ts
index 9659d1d12..98fe58261 100644
--- a/apps/desktop-solid/src/utils/tauri.ts
+++ b/apps/desktop-solid/src/utils/tauri.ts
@@ -150,6 +150,15 @@ async saveProjectConfig(videoId: string, config: ProjectConfiguration) : Promise
},
async openEditor(id: string) : Promise<void> {
await TAURI_INVOKE("open_editor", { id });
+},
+async openMainWindow() : Promise<void> {
+ await TAURI_INVOKE("open_main_window");
+},
+async openPermissionSettings(settings: OSPermissionSettings) : Promise<void> {
+ await TAURI_INVOKE("open_permission_settings", { settings });
+},
+async doPermissionsCheck() : Promise<OSPermissionsCheck> {
+ return await TAURI_INVOKE("do_permissions_check");
}
}
@@ -196,7 +205,11 @@ export type EditorStateChanged = { playhead_position: number }
export type HotkeysConfiguration = { show: boolean }
export type InProgressRecording = { recordingDir: string; displaySource: DisplaySource }
export type JsonValue<T> = [T]
+export type MacOSPermissionSettings = "screenRecording"
+export type MacOSPermissionsCheck = { screenRecording: boolean }
export type NewRecordingAdded = { path: string }
+export type OSPermissionSettings = { macOS: MacOSPermissionSettings }
+export type OSPermissionsCheck = ({ os: "macOS" } & MacOSPermissionsCheck) | { os: "other" }
export type ProjectConfiguration = { aspectRatio: AspectRatio | null; background: BackgroundConfiguration; camera: CameraConfiguration; audio: AudioConfiguration; cursor: CursorConfiguration; hotkeys: HotkeysConfiguration }
export type ProjectRecordings = { display: Video; camera: Video | null; audio: Audio | null }
export type RecordingOptions = { captureTarget: CaptureTarget; cameraLabel: string | null; audioInputName: string | null }
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 380fddde3..79059fe95 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -98,6 +98,9 @@ importers:
'@tauri-apps/plugin-os':
specifier: 2.0.0-rc.1
version: 2.0.0-rc.1
+ '@tauri-apps/plugin-process':
+ specifier: 2.0.0-rc.0
+ version: 2.0.0-rc.0
'@tauri-apps/plugin-shell':
specifier: '>=2.0.0-rc.0'
version: 2.0.0-rc.0
@@ -494,16 +497,16 @@ importers:
version: 3.9.7
next:
specifier: 14.2.3
next-auth:
specifier: ^4.24.5
next-mdx-remote:
specifier: ^4.4.1
nextjs-cors:
specifier: ^2.2.0
posthog-js:
specifier: ^1.129.0
version: 1.129.0
@@ -5126,6 +5129,9 @@ packages:
'@tauri-apps/[email protected]':
resolution: {integrity: sha512-PV8zlSTmYfiN2xzILUmlDSEycS7UYbH2yXk/ZqF+qQU6/s+OVQvmSth4EhllFjcpvPbtqELvpzfjw+2qEouchA==}
+ '@tauri-apps/[email protected]':
+ resolution: {integrity: sha512-Z12D/kmQzG1vCVf+jLXPhPDUA0pEjFrsg4p0uwO2sotVLM9287IuTM+aIz9cuAYOxFLKcsnDG7amSCL9IfA1gw==}
+
'@tauri-apps/[email protected]':
resolution: {integrity: sha512-bhUcQcrqZoK8H1DFXapr5r1Z75oh6Kd5Tltz97XpZFLREEqp+KhN2Fvyh8r/fKAyenYsTYUIsDsyGdjdueuF9g==}
@@ -17011,6 +17017,10 @@ snapshots:
dependencies:
'@tauri-apps/api': 2.0.0-rc.4
+ '@tauri-apps/[email protected]':
+ dependencies:
+ '@tauri-apps/api': 2.0.0-rc.4
+
'@tauri-apps/[email protected]':
dependencies:
'@tauri-apps/api': 2.0.0-rc.0
@@ -22251,23 +22261,6 @@ snapshots:
optionalDependencies:
nodemailer: 6.9.8
- dependencies:
- '@babel/runtime': 7.23.8
- '@panva/hkdf': 1.1.1
- cookie: 0.5.0
- jose: 4.15.4
- oauth: 0.9.15
- openid-client: 5.6.4
- preact: 10.19.3
- preact-render-to-string: 5.2.6([email protected])
- react: 18.2.0
- react-dom: 18.2.0([email protected])
- uuid: 8.3.2
- optionalDependencies:
- nodemailer: 6.9.8
-
dependencies:
'@mdx-js/mdx': 2.3.0
@@ -22291,7 +22284,7 @@ snapshots:
postcss: 8.4.31
react: 18.2.0
react-dom: 18.2.0([email protected])
- styled-jsx: 5.1.1(@babel/[email protected])([email protected])
+ styled-jsx: 5.1.1(@babel/[email protected])([email protected])
optionalDependencies:
'@next/swc-darwin-arm64': 14.1.0
'@next/swc-darwin-x64': 14.1.0
@@ -22331,35 +22324,10 @@ snapshots:
- '@babel/core'
- babel-plugin-macros
- dependencies:
- '@next/env': 14.2.3
- '@swc/helpers': 0.5.5
- busboy: 1.6.0
- caniuse-lite: 1.0.30001579
- graceful-fs: 4.2.11
- postcss: 8.4.31
- react: 18.2.0
- react-dom: 18.2.0([email protected])
- styled-jsx: 5.1.1(@babel/[email protected])([email protected])
- optionalDependencies:
- '@next/swc-darwin-arm64': 14.2.3
- '@next/swc-darwin-x64': 14.2.3
- '@next/swc-linux-arm64-gnu': 14.2.3
- '@next/swc-linux-arm64-musl': 14.2.3
- '@next/swc-linux-x64-gnu': 14.2.3
- '@next/swc-linux-x64-musl': 14.2.3
- '@next/swc-win32-arm64-msvc': 14.2.3
- '@next/swc-win32-ia32-msvc': 14.2.3
- '@next/swc-win32-x64-msvc': 14.2.3
- transitivePeerDependencies:
- - '@babel/core'
- - babel-plugin-macros
-
dependencies:
cors: 2.8.5
dependencies:
@@ -24034,13 +24002,6 @@ snapshots:
optionalDependencies:
'@babel/core': 7.23.7
- dependencies:
- client-only: 0.0.1
- react: 18.2.0
- optionalDependencies:
- '@babel/core': 7.25.2
-