|
| 1 | +import { Button } from "@cap/ui-solid"; |
| 2 | +import { createMutation } from "@tanstack/solid-query"; |
| 3 | +import { revealItemInDir } from "@tauri-apps/plugin-opener"; |
| 4 | +import { type as ostype } from "@tauri-apps/plugin-os"; |
| 5 | +import { Show } from "solid-js"; |
| 6 | +import CaptionControlsWindows11 from "~/components/titlebar/controls/CaptionControlsWindows11"; |
| 7 | +import { commands } from "~/utils/tauri"; |
| 8 | +import IconAlertTriangle from "~icons/lucide/alert-triangle"; |
| 9 | +import IconFolder from "~icons/lucide/folder"; |
| 10 | +import IconLoaderCircle from "~icons/lucide/loader-circle"; |
| 11 | +import IconRefreshCw from "~icons/lucide/refresh-cw"; |
| 12 | + |
| 13 | +const NEEDS_RECOVERY_PATTERN = /may need to be recovered/i; |
| 14 | + |
| 15 | +function isRecoveryNeededError(error: string): boolean { |
| 16 | + return NEEDS_RECOVERY_PATTERN.test(error); |
| 17 | +} |
| 18 | + |
| 19 | +export function EditorErrorScreen(props: { |
| 20 | + error: string; |
| 21 | + projectPath: string; |
| 22 | +}) { |
| 23 | + const needsRecovery = () => isRecoveryNeededError(props.error); |
| 24 | + const isMac = () => ostype() === "macos"; |
| 25 | + |
| 26 | + const recoverMutation = createMutation(() => ({ |
| 27 | + mutationFn: async () => { |
| 28 | + const result = await commands.recoverRecording(props.projectPath); |
| 29 | + await commands.showWindow({ Editor: { project_path: result } }); |
| 30 | + return result; |
| 31 | + }, |
| 32 | + onSuccess: () => { |
| 33 | + window.location.reload(); |
| 34 | + }, |
| 35 | + })); |
| 36 | + |
| 37 | + const handleOpenFolder = () => { |
| 38 | + revealItemInDir(props.projectPath); |
| 39 | + }; |
| 40 | + |
| 41 | + return ( |
| 42 | + <div class="flex flex-col flex-1 min-h-0"> |
| 43 | + <div |
| 44 | + data-tauri-drag-region |
| 45 | + class="flex relative flex-row items-center w-full h-14 px-4" |
| 46 | + > |
| 47 | + {isMac() && <div class="h-full w-[4rem]" />} |
| 48 | + <div data-tauri-drag-region class="flex-1 h-full" /> |
| 49 | + {ostype() === "windows" && <CaptionControlsWindows11 />} |
| 50 | + </div> |
| 51 | + |
| 52 | + <div class="flex-1 flex items-center justify-center p-8"> |
| 53 | + <div class="max-w-md w-full space-y-6"> |
| 54 | + <div class="flex flex-col items-center text-center space-y-3"> |
| 55 | + <div class="size-16 rounded-full bg-red-2 flex items-center justify-center"> |
| 56 | + <IconAlertTriangle class="size-8 text-red-9" /> |
| 57 | + </div> |
| 58 | + <h2 class="text-xl font-semibold text-gray-12"> |
| 59 | + {needsRecovery() |
| 60 | + ? "Recording Needs Recovery" |
| 61 | + : "Unable to Open Recording"} |
| 62 | + </h2> |
| 63 | + <p class="text-sm text-gray-11">{props.error}</p> |
| 64 | + </div> |
| 65 | + |
| 66 | + <Show when={needsRecovery()}> |
| 67 | + <div class="bg-gray-2 border border-gray-4 rounded-xl p-4 space-y-4"> |
| 68 | + <div class="space-y-2"> |
| 69 | + <h3 class="font-medium text-gray-12 text-sm"> |
| 70 | + Automatic Recovery |
| 71 | + </h3> |
| 72 | + <p class="text-xs text-gray-11"> |
| 73 | + Cap can attempt to recover your recording automatically. This |
| 74 | + will reconstruct the recording from available segment data. |
| 75 | + </p> |
| 76 | + </div> |
| 77 | + |
| 78 | + <Button |
| 79 | + onClick={() => recoverMutation.mutate()} |
| 80 | + disabled={recoverMutation.isPending} |
| 81 | + variant="primary" |
| 82 | + class="w-full" |
| 83 | + > |
| 84 | + <Show |
| 85 | + when={recoverMutation.isPending} |
| 86 | + fallback={ |
| 87 | + <> |
| 88 | + <IconRefreshCw class="size-4 mr-2" /> |
| 89 | + Recover Recording |
| 90 | + </> |
| 91 | + } |
| 92 | + > |
| 93 | + <IconLoaderCircle class="size-4 mr-2 animate-spin" /> |
| 94 | + Recovering... |
| 95 | + </Show> |
| 96 | + </Button> |
| 97 | + |
| 98 | + <Show when={recoverMutation.error}> |
| 99 | + <div class="bg-red-2 border border-red-6 rounded-lg p-3"> |
| 100 | + <p class="text-red-11 text-xs"> |
| 101 | + Recovery failed:{" "} |
| 102 | + {recoverMutation.error instanceof Error |
| 103 | + ? recoverMutation.error.message |
| 104 | + : String(recoverMutation.error)} |
| 105 | + </p> |
| 106 | + </div> |
| 107 | + </Show> |
| 108 | + </div> |
| 109 | + </Show> |
| 110 | + |
| 111 | + <div class="bg-gray-2 border border-gray-4 rounded-xl p-4 space-y-4"> |
| 112 | + <div class="space-y-2"> |
| 113 | + <h3 class="font-medium text-gray-12 text-sm"> |
| 114 | + Manual Investigation |
| 115 | + </h3> |
| 116 | + <p class="text-xs text-gray-11"> |
| 117 | + You can open the recording folder to inspect the raw files |
| 118 | + directly. |
| 119 | + </p> |
| 120 | + |
| 121 | + <div class="bg-gray-3 rounded-lg p-3 space-y-2"> |
| 122 | + <p class="text-xs font-mono text-gray-11 break-all"> |
| 123 | + {props.projectPath} |
| 124 | + </p> |
| 125 | + <Show |
| 126 | + when={isMac()} |
| 127 | + fallback={ |
| 128 | + <p class="text-xs text-gray-10 italic"> |
| 129 | + Tip: Double-click inside the folder to browse the |
| 130 | + contents. |
| 131 | + </p> |
| 132 | + } |
| 133 | + > |
| 134 | + <p class="text-xs text-gray-10 italic"> |
| 135 | + Tip: Right-click and select "Show Enclosing Folder" to see |
| 136 | + the .cap bundle contents. |
| 137 | + </p> |
| 138 | + </Show> |
| 139 | + </div> |
| 140 | + </div> |
| 141 | + |
| 142 | + <Button onClick={handleOpenFolder} variant="outline" class="w-full"> |
| 143 | + <IconFolder class="size-4 mr-2" /> |
| 144 | + Open Folder |
| 145 | + </Button> |
| 146 | + </div> |
| 147 | + |
| 148 | + <div class="flex justify-center"> |
| 149 | + <button |
| 150 | + type="button" |
| 151 | + onClick={() => window.close()} |
| 152 | + class="text-sm text-gray-10 hover:text-gray-11 transition-colors" |
| 153 | + > |
| 154 | + Close Window |
| 155 | + </button> |
| 156 | + </div> |
| 157 | + </div> |
| 158 | + </div> |
| 159 | + </div> |
| 160 | + ); |
| 161 | +} |
0 commit comments