Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop): register automation commands types and event listeners

Richie McIlroy37f77ff3eb2e
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index 33d0dc2e0..e83ed12b7 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -4,6 +4,7 @@ mod api;
mod audio;
mod audio_meter;
mod auth;
+mod automation;
mod camera;
mod camera_legacy;
#[cfg(target_os = "macos")]
@@ -2130,9 +2131,8 @@ pub struct NewStudioRecordingAdded {
path: PathBuf,
}
-#[derive(specta::Type, tauri_specta::Event, Debug, Clone, Serialize)]
+#[derive(Deserialize, specta::Type, tauri_specta::Event, Debug, Clone, Serialize)]
pub struct RecordingDeleted {
- #[allow(unused)]
path: PathBuf,
}
@@ -4338,6 +4338,11 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
recovery::find_incomplete_recordings,
recovery::recover_recording,
recovery::discard_incomplete_recording,
+ automation::get_automations,
+ automation::set_automations,
+ automation::test_automation,
+ automation::automation_should_open_screenshot_editor,
+ automation::list_automation_capabilities,
])
.events(tauri_specta::collect_events![
RecordingOptionsChanged,
@@ -4374,7 +4379,20 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
.typ::<general_settings::GeneralSettingsStore>()
.typ::<recording_settings::RecordingSettingsStore>()
.typ::<cap_flags::Flags>()
- .typ::<crate::window_exclusion::WindowExclusion>();
+ .typ::<crate::window_exclusion::WindowExclusion>()
+ .typ::<cap_automation::AutomationsStore>()
+ .typ::<cap_automation::AutomationRule>()
+ .typ::<cap_automation::Trigger>()
+ .typ::<cap_automation::Condition>()
+ .typ::<cap_automation::Action>()
+ .typ::<cap_automation::ExportProfile>()
+ .typ::<cap_automation::MatchMode>()
+ .typ::<cap_automation::CaptureTargetKind>()
+ .typ::<cap_automation::AutomationRecordingMode>()
+ .typ::<cap_automation::ClipboardSource>()
+ .typ::<cap_automation::ExportFormat>()
+ .typ::<cap_automation::AutomationExportCompression>()
+ .typ::<cap_automation::ExportDestination>();
#[cfg(debug_assertions)]
if let Err(err) = specta_builder.export(
@@ -4777,6 +4795,23 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
}
});
+ RecordingStarted::listen_any_spawn(&app, async |_event, app| {
+ crate::automation::run_recording_started_automations(app);
+ });
+
+ RecordingDeleted::listen_any_spawn(&app, async |event, app| {
+ crate::automation::run_recording_deleted_automations(app, event.path);
+ });
+
+ import::VideoImportProgress::listen_any_spawn(&app, async |event, app| {
+ if matches!(event.stage, import::ImportStage::Complete) {
+ crate::automation::run_video_imported_automations(
+ app,
+ std::path::PathBuf::from(event.project_path),
+ );
+ }
+ });
+
let app_handle = app.clone();
app.deep_link().on_open_url(move |event| {
deeplink_actions::handle(&app_handle, event.urls());
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index 0add9196a..a1eb5452d 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -411,6 +411,21 @@ async recoverRecording(projectPath: string) : Promise<string> {
},
async discardIncompleteRecording(projectPath: string) : Promise<null> {
return await TAURI_INVOKE("discard_incomplete_recording", { projectPath });
+},
+async getAutomations() : Promise<AutomationsStore> {
+ return await TAURI_INVOKE("get_automations");
+},
+async setAutomations(store: AutomationsStore) : Promise<null> {
+ return await TAURI_INVOKE("set_automations", { store });
+},
+async testAutomation(ruleId: string) : Promise<AutomationTestReport> {
+ return await TAURI_INVOKE("test_automation", { ruleId });
+},
+async automationShouldOpenScreenshotEditor(target: ScreenCaptureTarget) : Promise<boolean> {
+ return await TAURI_INVOKE("automation_should_open_screenshot_editor", { target });
+},
+async listAutomationCapabilities() : Promise<string[]> {
+ return await TAURI_INVOKE("list_automation_capabilities");
}
}
@@ -477,6 +492,7 @@ videoImportProgress: "video-import-progress"
/** user-defined types **/
+export type Action = { type: "copyToClipboard"; source?: ClipboardSource } | { type: "saveToLocation"; dir: string; filenameTemplate?: string | null } | { type: "export"; profile: ExportProfile; destination?: ExportDestination } | { type: "upload"; organizationId?: string | null; copyLink?: boolean; openInBrowser?: boolean } | { type: "revealInFileManager" } | { type: "openFile" } | { type: "runCommand"; program: string; args?: string[]; cwd?: string | null; env?: { [key in string]: string }; useShell?: boolean } | { type: "webhook"; url: string; method?: string; headers?: { [key in string]: string }; bodyTemplate?: string | null } | { type: "recognizeTextToClipboard" } | { type: "notify"; titleTemplate?: string; bodyTemplate?: string } | { type: "openEditor" } | { type: "skipEditor" } | { type: "applyPreset"; name: string } | { type: "deleteLocalFiles" }
export type Annotation = { id: string; type: AnnotationType; x: number; y: number; width: number; height: number; strokeColor: string; strokeWidth: number; fillColor: string; opacity: number; rotation: number; text: string | null; maskType?: MaskType | null; maskLevel?: number | null }
export type AnnotationType = "arrow" | "circle" | "rectangle" | "text" | "mask"
export type AppTheme = "system" | "light" | "dark"
@@ -510,6 +526,12 @@ export type AudioInputLevelChange = number
export type AudioMeta = { path: string; start_time?: number | null; device_id?: string | null; gap_summary?: AudioGapSummary | null }
export type AuthSecret = { api_key: string } | { token: string; expires: number }
export type AuthStore = { secret: AuthSecret; user_id: string | null; plan: Plan | null; organizations?: Organization[]; organizations_updated_at?: number | null }
+export type AutomationActionCheck = { actionType: string; capability: string; supported: boolean }
+export type AutomationExportCompression = "maximum" | "social" | "web" | "potato"
+export type AutomationRecordingMode = "studio" | "instant"
+export type AutomationRule = { id: string; name: string; enabled?: boolean; trigger: Trigger; matchMode?: MatchMode; conditions?: Condition[]; actions?: Action[] }
+export type AutomationTestReport = { ruleId: string; ruleName: string; actionChecks: AutomationActionCheck[] }
+export type AutomationsStore = { version?: number; rules?: AutomationRule[] }
export type BackgroundBlurConfig = { mode: BackgroundBlurMode }
export type BackgroundBlurMode = "off" | "light" | "heavy"
export type BackgroundConfiguration = { source: BackgroundSource; blur: number; padding: number; rounding: number; roundingType: CornerStyle; inset: number; crop: Crop | null; shadow: number; advancedShadow: ShadowConfiguration | null; border: BorderConfiguration | null }
@@ -534,6 +556,7 @@ export type CaptionWord = { text: string; start: number; end: number }
export type CaptionsData = { segments: CaptionSegment[]; settings: CaptionSettings }
export type CaptureDisplay = { id: DisplayId; name: string; refresh_rate: number }
export type CaptureDisplayWithThumbnail = { id: DisplayId; name: string; refresh_rate: number; thumbnail: string | null }
+export type CaptureTargetKind = "display" | "window" | "area"
export type CaptureWindow = { id: WindowId; owner_name: string; name: string; bounds: LogicalBounds; refresh_rate: number; bundle_identifier: string | null }
export type CaptureWindowWithThumbnail = { id: WindowId; owner_name: string; name: string; bounds: LogicalBounds; refresh_rate: number; thumbnail: string | null; app_icon: string | null; bundle_identifier: string | null }
export type CliInstallStatus = { installDir: string; shimPath: string; targetPath: string; installed: boolean; onPath: boolean; conflict: string | null; pathEntry: string; shellCommand: string;
@@ -545,7 +568,9 @@ pathConfigured: boolean }
export type ClickSpringConfig = { tension: number; mass: number; friction: number }
export type ClipConfiguration = { index: number; offsets: ClipOffsets }
export type ClipOffsets = { camera?: number; mic?: number; system_audio?: number }
+export type ClipboardSource = "raw" | "rendered"
export type CommercialLicense = { licenseKey: string; expiryDate: number | null; refresh: number; activatedOn: number }
+export type Condition = { type: "captureTargetIs"; target: CaptureTargetKind } | { type: "recordingModeIs"; mode: AutomationRecordingMode } | { type: "durationAtLeast"; secs: number } | { type: "durationAtMost"; secs: number } | { type: "windowTitleContains"; pattern: string } | { type: "organizationIs"; id: string }
export type CornerStyle = "squircle" | "rounded"
export type Crop = { position: XY<number>; size: XY<number> }
export type CurrentRecording = { target: CurrentRecordingTarget; mode: RecordingMode; status: RecordingStatus }
@@ -564,9 +589,12 @@ export type DownloadProgress = { progress: number; message: string }
export type EditorPreviewQuality = "quarter" | "half" | "full"
export type EditorStateChanged = { playhead_position: number }
export type ExportCompression = "Maximum" | "Social" | "Web" | "Potato"
+export type ExportDestination = "projectFolder" | { customPath: { dir: string } }
export type ExportEstimates = { duration_seconds: number; estimated_time_seconds: number; estimated_size_mb: number }
+export type ExportFormat = "mp4" | "gif" | "mov"
export type ExportPreviewResult = { jpeg_base64: string; estimated_size_mb: number; actual_width: number; actual_height: number; frame_render_time_ms: number; total_frames: number }
export type ExportPreviewSettings = { fps: number; resolution_base: XY<number>; compression_bpp: number; cursor_only?: boolean }
+export type ExportProfile = { format: ExportFormat; fps?: number; resolutionBase?: XY<number>; compression?: AutomationExportCompression | null; presetName?: string | null }
export type ExportSettings = ({ format: "Mp4" } & Mp4ExportSettings) | ({ format: "Gif" } & GifExportSettings) | ({ format: "Mov" } & MovExportSettings)
export type FileType = "recording" | "screenshot"
export type Flags = { captions: boolean }
@@ -608,6 +636,7 @@ export type MaskScalarKeyframe = { time: number; value: number }
export type MaskSegment = { start: number; end: number; track?: number; enabled?: boolean; maskType: MaskKind; center: XY<number>; size: XY<number>; feather?: number; opacity?: number; pixelation?: number; darkness?: number; fadeDuration?: number; keyframes?: MaskKeyframes }
export type MaskType = "blur" | "pixelate"
export type MaskVectorKeyframe = { time: number; x: number; y: number }
+export type MatchMode = "all" | "any"
export type MicrophoneDeviceSettings = { sampleRate: number | null; channels: number | null }
export type MicrophoneFormatInfo = { sampleRate: number; channels: number }
export type MicrophoneInfo = { name: string; sampleRate: number; channels: number; formats: MicrophoneFormatInfo[] }
@@ -682,6 +711,7 @@ export type TextSegment = { start: number; end: number; track?: number; enabled?
export type TimelineConfiguration = { segments: TimelineSegment[]; zoomSegments: ZoomSegment[]; sceneSegments?: SceneSegment[]; maskSegments?: MaskSegment[]; textSegments?: TextSegment[]; captionSegments?: CaptionTrackSegment[]; keyboardSegments?: KeyboardTrackSegment[] }
export type TimelineSegment = { recordingSegment?: number; timescale: number; start: number; end: number }
export type TranscriptionEngine = "Whisper" | "Parakeet"
+export type Trigger = "screenshotTaken" | "studioRecordingFinished" | "instantRecordingFinished" | "recordingStarted" | "uploadCompleted" | "videoImported" | "recordingDeleted"
export type UploadMeta = { state: "MultipartUpload"; video_id: string; file_path: string; pre_created_video: VideoUploadInfo; recording_dir: string } | { state: "SinglePartUpload"; video_id: string; recording_dir: string; file_path: string; screenshot_path: string } | { state: "SegmentUpload"; video_id: string; pre_created_video: VideoUploadInfo; recording_dir: string } | { state: "Failed"; error: string } | { state: "Complete" }
export type UploadMode = { Initial: { pre_created_video: VideoUploadInfo | null } } | "Reupload"
export type UploadProgress = { progress: number }