Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop): add custom recordings storage path setting

ManthanNimodiyacf1b479ce529
diff --git a/apps/desktop/src-tauri/src/general_settings.rs b/apps/desktop/src-tauri/src/general_settings.rs
index 3bc845923..df0c67f59 100644
--- a/apps/desktop/src-tauri/src/general_settings.rs
+++ b/apps/desktop/src-tauri/src/general_settings.rs
@@ -6,7 +6,7 @@ use specta::Type;
use std::collections::BTreeMap;
#[cfg(target_os = "macos")]
use tauri::Listener;
-use tauri::{AppHandle, Wry};
+use tauri::{AppHandle, Manager, Wry};
use tauri_plugin_store::StoreExt;
use tracing::{error, instrument};
use uuid::Uuid;
@@ -218,6 +218,8 @@ pub struct GeneralSettingsStore {
pub enable_telemetry: bool,
#[serde(default)]
pub out_of_process_muxer: bool,
+ #[serde(default)]
+ pub recordings_path: Option<String>,
}
fn default_enable_native_camera_preview() -> bool {
@@ -314,6 +316,7 @@ impl Default for GeneralSettingsStore {
has_completed_onboarding: false,
enable_telemetry: true,
out_of_process_muxer: cap_recording::DEFAULT_OUT_OF_PROCESS_MUXER,
+ recordings_path: None,
}
}
}
@@ -328,6 +331,23 @@ pub enum AppTheme {
}
impl GeneralSettingsStore {
+ pub fn recordings_dir(app: &AppHandle<Wry>) -> std::path::PathBuf {
+ let custom = Self::get(app)
+ .ok()
+ .flatten()
+ .and_then(|s| s.recordings_path)
+ .and_then(|p| {
+ let path = std::path::PathBuf::from(&p);
+ if path.is_absolute() { Some(path) } else { None }
+ });
+
+ let path = custom.unwrap_or_else(|| {
+ app.path().app_data_dir().unwrap().join("recordings")
+ });
+ std::fs::create_dir_all(&path).unwrap_or_default();
+ path
+ }
+
// The effective value: the native preview is macOS-only; it is not
// reliable on Windows, so the stored setting is ignored there and the
// websocket preview is always used.
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index 80c6e4081..b508c8905 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -4254,6 +4254,43 @@ async fn set_server_url(app: MutableState<'_, App>, server_url: String) -> Resul
Ok(())
}
+#[tauri::command]
+#[specta::specta]
+#[instrument(skip(app))]
+async fn pick_recordings_folder(app: AppHandle) -> Result<Option<String>, String> {
+ use tauri_plugin_dialog::DialogExt;
+
+ let (tx, rx) = tokio::sync::oneshot::channel();
+
+ app.dialog()
+ .file()
+ .set_title("Choose Recordings Folder")
+ .pick_folder(move |path| {
+ let _ = tx.send(
+ path.as_ref()
+ .and_then(|p| p.as_path())
+ .map(|p| p.to_string_lossy().to_string()),
+ );
+ });
+
+ let result = rx.await.map_err(|e| e.to_string())?;
+ if let Some(ref path) = result {
+ general_settings::GeneralSettingsStore::update(&app, |s| {
+ s.recordings_path = Some(path.clone());
+ })?;
+ }
+ Ok(result)
+}
+
+#[tauri::command]
+#[specta::specta]
+#[instrument(skip(app))]
+async fn reset_recordings_folder(app: AppHandle) -> Result<(), String> {
+ general_settings::GeneralSettingsStore::update(&app, |s| {
+ s.recordings_path = None;
+ })
+}
+
#[tauri::command]
#[specta::specta]
#[instrument(skip(app))]
@@ -4590,6 +4627,8 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
delete_recording_directory,
set_pretty_name,
set_server_url,
+ pick_recordings_folder,
+ reset_recordings_folder,
set_camera_preview_state,
set_camera_window_position,
ignore_camera_window_position,
@@ -6171,9 +6210,7 @@ pub(crate) async fn wait_for_recording_ready(app: &AppHandle, path: &Path) -> Re
}
fn recordings_path(app: &AppHandle) -> PathBuf {
- let path = app.path().app_data_dir().unwrap().join("recordings");
- std::fs::create_dir_all(&path).unwrap_or_default();
- path
+ general_settings::GeneralSettingsStore::recordings_dir(app)
}
// fn recording_path(app: &AppHandle, recording_id: &str) -> PathBuf {
diff --git a/apps/desktop/src-tauri/src/logging.rs b/apps/desktop/src-tauri/src/logging.rs
index c75d35ce5..3fe05afad 100644
--- a/apps/desktop/src-tauri/src/logging.rs
+++ b/apps/desktop/src-tauri/src/logging.rs
@@ -1,4 +1,4 @@
-use crate::{ArcLock, feeds::microphone::MicrophoneFeed, permissions, web_api::ManagerExt};
+use crate::{ArcLock, feeds::microphone::MicrophoneFeed, general_settings::GeneralSettingsStore, permissions, web_api::ManagerExt};
use cap_recording::diagnostics::{
CameraDiagnostics, CameraFormatInfo, DisplayDiagnostics, HardwareInfo, MicrophoneDiagnostics,
StorageInfo,
@@ -208,7 +208,7 @@ pub async fn upload_log_file(app: &AppHandle) -> Result<(), String> {
.path()
.app_data_dir()
.map_err(|e| format!("Failed to get app data dir: {e}"))?;
- let recordings_dir = app_data_dir.join("recordings");
+ let recordings_dir = GeneralSettingsStore::recordings_dir(&app);
let is_recording = {
let app_lock = app.state::<ArcLock<crate::App>>();
diff --git a/apps/desktop/src-tauri/src/recovery.rs b/apps/desktop/src-tauri/src/recovery.rs
index b038e1694..2bb22d90a 100644
--- a/apps/desktop/src-tauri/src/recovery.rs
+++ b/apps/desktop/src-tauri/src/recovery.rs
@@ -4,10 +4,10 @@ use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
use specta::Type;
use std::path::PathBuf;
-use tauri::{AppHandle, Manager};
+use tauri::AppHandle;
use tracing::info;
-use crate::create_screenshot;
+use crate::{create_screenshot, general_settings::GeneralSettingsStore};
const RECOVERY_CUTOFF_DATE: (i32, u32, u32) = (2025, 12, 31);
@@ -44,11 +44,7 @@ pub struct IncompleteRecordingInfo {
pub async fn find_incomplete_recordings(
app: AppHandle,
) -> Result<Vec<IncompleteRecordingInfo>, String> {
- let recordings_dir = app
- .path()
- .app_data_dir()
- .map_err(|e| e.to_string())?
- .join("recordings");
+ let recordings_dir = GeneralSettingsStore::recordings_dir(&app);
if !recordings_dir.exists() {
return Ok(Vec::new());
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
index 653407279..34fa10f3b 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
@@ -639,6 +639,20 @@ function Inner(props: { initialStore: GeneralSettingsStore | null }) {
</SectionRows>
</Section>
+ <StorageSection
+ recordingsPath={settings.recordingsPath ?? null}
+ onPick={async () => {
+ const path = await commands.pickRecordingsFolder();
+ if (path !== null) {
+ setSettings("recordingsPath", path);
+ }
+ }}
+ onReset={async () => {
+ await commands.resetRecordingsFolder();
+ setSettings("recordingsPath", null);
+ }}
+ />
+
<DefaultProjectNameCard
onChange={(value) =>
handleChange("defaultProjectNameTemplate", value)
@@ -687,6 +701,43 @@ function Inner(props: { initialStore: GeneralSettingsStore | null }) {
);
}
+function StorageSection(props: {
+ recordingsPath: string | null;
+ onPick: () => Promise<void>;
+ onReset: () => Promise<void>;
+}) {
+ const defaultLabel = "Default (Application Support)";
+ const displayPath = () => props.recordingsPath ?? defaultLabel;
+ const isCustom = () => props.recordingsPath !== null;
+
+ return (
+ <Section
+ title="Storage"
+ description="Where Cap saves your recordings."
+ >
+ <SectionCard padded>
+ <div class="flex flex-col gap-3">
+ <div class="flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-3 border border-gray-4 min-w-0">
+ <span class="flex-1 text-xs text-gray-12 truncate font-mono">
+ {displayPath()}
+ </span>
+ </div>
+ <div class="flex justify-end gap-2">
+ <Show when={isCustom()}>
+ <Button size="sm" variant="gray" onClick={props.onReset}>
+ Reset to Default
+ </Button>
+ </Show>
+ <Button size="sm" variant="dark" onClick={props.onPick}>
+ Choose Folder
+ </Button>
+ </div>
+ </div>
+ </SectionCard>
+ </Section>
+ );
+}
+
function TelemetryCard(props: {
value: boolean;
onChange: (value: boolean) => void;
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index 52bf52e82..27caab900 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -355,6 +355,12 @@ async setPrettyName(prettyName: string) : Promise<null> {
async setServerUrl(serverUrl: string) : Promise<null> {
return await TAURI_INVOKE("set_server_url", { serverUrl });
},
+async pickRecordingsFolder() : Promise<string | null> {
+ return await TAURI_INVOKE("pick_recordings_folder");
+},
+async resetRecordingsFolder() : Promise<null> {
+ return await TAURI_INVOKE("reset_recordings_folder");
+},
async setCameraPreviewState(state: CameraPreviewState) : Promise<null> {
return await TAURI_INVOKE("set_camera_preview_state", { state });
},
@@ -663,7 +669,7 @@ export type ExportSettings = ({ format: "Mp4" } & Mp4ExportSettings) | ({ format
export type FileType = "recording" | "screenshot"
export type Flags = { captions: boolean }
export type FramesRendered = { renderedCount: number; totalFrames: number; type: "FramesRendered" }
-export type GeneralSettingsStore = { instanceId?: string; uploadIndividualFiles?: boolean; hideDockIcon?: 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; captureKeyboardEvents?: boolean; postDeletionBehaviour?: PostDeletionBehaviour; excludedWindows?: WindowExclusion[]; deleteInstantRecordingsAfterUpload?: boolean; instantModeMaxResolution?: number; defaultProjectNameTemplate?: string | null; crashRecoveryRecording?: boolean; maxFps?: number; transcriptionHints?: string[]; editorPreviewQuality?: EditorPreviewQuality; studioRecordingQuality?: StudioRecordingQuality; mainWindowPosition?: WindowPosition | null; cameraWindowPosition?: WindowPosition | null; cameraWindowPositionsByMonitorName?: { [key in string]: WindowPosition }; hasCompletedOnboarding?: boolean; enableTelemetry?: boolean; outOfProcessMuxer?: boolean }
+export type GeneralSettingsStore = { instanceId?: string; uploadIndividualFiles?: boolean; hideDockIcon?: 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; captureKeyboardEvents?: boolean; postDeletionBehaviour?: PostDeletionBehaviour; excludedWindows?: WindowExclusion[]; deleteInstantRecordingsAfterUpload?: boolean; instantModeMaxResolution?: number; defaultProjectNameTemplate?: string | null; crashRecoveryRecording?: boolean; maxFps?: number; transcriptionHints?: string[]; editorPreviewQuality?: EditorPreviewQuality; studioRecordingQuality?: StudioRecordingQuality; mainWindowPosition?: WindowPosition | null; cameraWindowPosition?: WindowPosition | null; cameraWindowPositionsByMonitorName?: { [key in string]: WindowPosition }; hasCompletedOnboarding?: boolean; enableTelemetry?: boolean; outOfProcessMuxer?: boolean; recordingsPath?: string | null }
export type GifExportSettings = { fps: number; resolution_base: XY<number>; quality: GifQuality | null }
export type GifQuality = {
/**