Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Add error screen and project path retrieval to editor

Richie McIlroya83740c31783
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index e378c1a4c..634e8256d 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -1442,6 +1442,24 @@ async fn create_editor_instance(window: Window) -> Result<SerializedEditorInstan
})
}
+#[tauri::command]
+#[specta::specta]
+#[instrument(skip(window))]
+async fn get_editor_project_path(window: Window) -> Result<PathBuf, String> {
+ let CapWindowId::Editor { id } = CapWindowId::from_str(window.label()).unwrap() else {
+ return Err("Invalid window".to_string());
+ };
+
+ let window_ids = EditorWindowIds::get(window.app_handle());
+ let window_ids = window_ids.ids.lock().unwrap();
+
+ let Some((path, _)) = window_ids.iter().find(|(_, _id)| *_id == id) else {
+ return Err("Editor instance not found".to_string());
+ };
+
+ Ok(path.clone())
+}
+
#[tauri::command]
#[specta::specta]
#[instrument(skip(editor))]
@@ -2472,6 +2490,7 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
open_file_path,
get_video_metadata,
create_editor_instance,
+ get_editor_project_path,
get_mic_waveforms,
get_system_audio_waveforms,
start_playback,
diff --git a/apps/desktop/src/routes/editor/Editor.tsx b/apps/desktop/src/routes/editor/Editor.tsx
index 1e2a01903..a83f558fb 100644
--- a/apps/desktop/src/routes/editor/Editor.tsx
+++ b/apps/desktop/src/routes/editor/Editor.tsx
@@ -11,6 +11,7 @@ import { Menu } from "@tauri-apps/api/menu";
import {
createEffect,
createMemo,
+ createResource,
createSignal,
Match,
on,
@@ -41,6 +42,7 @@ import {
useEditorContext,
useEditorInstanceContext,
} from "./context";
+import { EditorErrorScreen } from "./EditorErrorScreen";
import { ExportPage } from "./ExportPage";
import { Header } from "./Header";
import { PlayerContent } from "./Player";
@@ -54,38 +56,61 @@ const RESIZE_HANDLE_HEIGHT = 8;
const MIN_PLAYER_HEIGHT = MIN_PLAYER_CONTENT_HEIGHT + RESIZE_HANDLE_HEIGHT;
export function Editor() {
+ const [projectPath] = createResource(() => commands.getEditorProjectPath());
+
return (
<EditorInstanceContextProvider>
- <Show
- when={(() => {
- const ctx = useEditorInstanceContext();
- const editorInstance = ctx.editorInstance();
-
- if (!editorInstance || !ctx.metaQuery.data) return;
-
- return {
- editorInstance,
- meta() {
- const d = ctx.metaQuery.data;
- if (!d)
- throw new Error(
- "metaQuery.data is undefined - how did this happen?",
- );
- return d;
- },
- refetchMeta: async () => {
- await ctx.metaQuery.refetch();
- },
- };
- })()}
- >
+ <EditorContent projectPath={projectPath()} />
+ </EditorInstanceContextProvider>
+ );
+}
+
+function EditorContent(props: { projectPath: string | undefined }) {
+ const ctx = useEditorInstanceContext();
+
+ const errorInfo = () => {
+ const error = ctx.editorInstance.error;
+ if (!error || !props.projectPath) return null;
+ const errorMessage = error instanceof Error ? error.message : String(error);
+ return { error: errorMessage, projectPath: props.projectPath };
+ };
+
+ const readyData = () => {
+ const editorInstance = ctx.editorInstance();
+ if (!editorInstance || !ctx.metaQuery.data) return null;
+
+ return {
+ editorInstance,
+ meta() {
+ const d = ctx.metaQuery.data;
+ if (!d)
+ throw new Error("metaQuery.data is undefined - how did this happen?");
+ return d;
+ },
+ refetchMeta: async () => {
+ await ctx.metaQuery.refetch();
+ },
+ };
+ };
+
+ return (
+ <Switch>
+ <Match when={errorInfo()}>
+ {(info) => (
+ <EditorErrorScreen
+ error={info().error}
+ projectPath={info().projectPath}
+ />
+ )}
+ </Match>
+ <Match when={readyData()}>
{(values) => (
<EditorContextProvider {...values()}>
<Inner />
</EditorContextProvider>
)}
- </Show>
- </EditorInstanceContextProvider>
+ </Match>
+ </Switch>
);
}
diff --git a/apps/desktop/src/routes/editor/EditorErrorScreen.tsx b/apps/desktop/src/routes/editor/EditorErrorScreen.tsx
new file mode 100644
index 000000000..04505a8b2
--- /dev/null
+++ b/apps/desktop/src/routes/editor/EditorErrorScreen.tsx
@@ -0,0 +1,161 @@
+import { Button } from "@cap/ui-solid";
+import { createMutation } from "@tanstack/solid-query";
+import { revealItemInDir } from "@tauri-apps/plugin-opener";
+import { type as ostype } from "@tauri-apps/plugin-os";
+import { Show } from "solid-js";
+import CaptionControlsWindows11 from "~/components/titlebar/controls/CaptionControlsWindows11";
+import { commands } from "~/utils/tauri";
+import IconAlertTriangle from "~icons/lucide/alert-triangle";
+import IconFolder from "~icons/lucide/folder";
+import IconLoaderCircle from "~icons/lucide/loader-circle";
+import IconRefreshCw from "~icons/lucide/refresh-cw";
+
+const NEEDS_RECOVERY_PATTERN = /may need to be recovered/i;
+
+function isRecoveryNeededError(error: string): boolean {
+ return NEEDS_RECOVERY_PATTERN.test(error);
+}
+
+export function EditorErrorScreen(props: {
+ error: string;
+ projectPath: string;
+}) {
+ const needsRecovery = () => isRecoveryNeededError(props.error);
+ const isMac = () => ostype() === "macos";
+
+ const recoverMutation = createMutation(() => ({
+ mutationFn: async () => {
+ const result = await commands.recoverRecording(props.projectPath);
+ await commands.showWindow({ Editor: { project_path: result } });
+ return result;
+ },
+ onSuccess: () => {
+ window.location.reload();
+ },
+ }));
+
+ const handleOpenFolder = () => {
+ revealItemInDir(props.projectPath);
+ };
+
+ return (
+ <div class="flex flex-col flex-1 min-h-0">
+ <div
+ data-tauri-drag-region
+ class="flex relative flex-row items-center w-full h-14 px-4"
+ >
+ {isMac() && <div class="h-full w-[4rem]" />}
+ <div data-tauri-drag-region class="flex-1 h-full" />
+ {ostype() === "windows" && <CaptionControlsWindows11 />}
+ </div>
+
+ <div class="flex-1 flex items-center justify-center p-8">
+ <div class="max-w-md w-full space-y-6">
+ <div class="flex flex-col items-center text-center space-y-3">
+ <div class="size-16 rounded-full bg-red-2 flex items-center justify-center">
+ <IconAlertTriangle class="size-8 text-red-9" />
+ </div>
+ <h2 class="text-xl font-semibold text-gray-12">
+ {needsRecovery()
+ ? "Recording Needs Recovery"
+ : "Unable to Open Recording"}
+ </h2>
+ <p class="text-sm text-gray-11">{props.error}</p>
+ </div>
+
+ <Show when={needsRecovery()}>
+ <div class="bg-gray-2 border border-gray-4 rounded-xl p-4 space-y-4">
+ <div class="space-y-2">
+ <h3 class="font-medium text-gray-12 text-sm">
+ Automatic Recovery
+ </h3>
+ <p class="text-xs text-gray-11">
+ Cap can attempt to recover your recording automatically. This
+ will reconstruct the recording from available segment data.
+ </p>
+ </div>
+
+ <Button
+ onClick={() => recoverMutation.mutate()}
+ disabled={recoverMutation.isPending}
+ variant="primary"
+ class="w-full"
+ >
+ <Show
+ when={recoverMutation.isPending}
+ fallback={
+ <>
+ <IconRefreshCw class="size-4 mr-2" />
+ Recover Recording
+ </>
+ }
+ >
+ <IconLoaderCircle class="size-4 mr-2 animate-spin" />
+ Recovering...
+ </Show>
+ </Button>
+
+ <Show when={recoverMutation.error}>
+ <div class="bg-red-2 border border-red-6 rounded-lg p-3">
+ <p class="text-red-11 text-xs">
+ Recovery failed:{" "}
+ {recoverMutation.error instanceof Error
+ ? recoverMutation.error.message
+ : String(recoverMutation.error)}
+ </p>
+ </div>
+ </Show>
+ </div>
+ </Show>
+
+ <div class="bg-gray-2 border border-gray-4 rounded-xl p-4 space-y-4">
+ <div class="space-y-2">
+ <h3 class="font-medium text-gray-12 text-sm">
+ Manual Investigation
+ </h3>
+ <p class="text-xs text-gray-11">
+ You can open the recording folder to inspect the raw files
+ directly.
+ </p>
+
+ <div class="bg-gray-3 rounded-lg p-3 space-y-2">
+ <p class="text-xs font-mono text-gray-11 break-all">
+ {props.projectPath}
+ </p>
+ <Show
+ when={isMac()}
+ fallback={
+ <p class="text-xs text-gray-10 italic">
+ Tip: Double-click inside the folder to browse the
+ contents.
+ </p>
+ }
+ >
+ <p class="text-xs text-gray-10 italic">
+ Tip: Right-click and select "Show Enclosing Folder" to see
+ the .cap bundle contents.
+ </p>
+ </Show>
+ </div>
+ </div>
+
+ <Button onClick={handleOpenFolder} variant="outline" class="w-full">
+ <IconFolder class="size-4 mr-2" />
+ Open Folder
+ </Button>
+ </div>
+
+ <div class="flex justify-center">
+ <button
+ type="button"
+ onClick={() => window.close()}
+ class="text-sm text-gray-10 hover:text-gray-11 transition-colors"
+ >
+ Close Window
+ </button>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index ed4697493..b14f88498 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -116,6 +116,9 @@ async getVideoMetadata(path: string) : Promise<VideoRecordingMetadata> {
async createEditorInstance() : Promise<SerializedEditorInstance> {
return await TAURI_INVOKE("create_editor_instance");
},
+async getEditorProjectPath() : Promise<string> {
+ return await TAURI_INVOKE("get_editor_project_path");
+},
async getMicWaveforms() : Promise<number[][]> {
return await TAURI_INVOKE("get_mic_waveforms");
},