Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: Editor header dialog fixes

Richie McIlroybed7ac4bebfc
diff --git a/apps/desktop/src/routes/editor/Header.tsx b/apps/desktop/src/routes/editor/Header.tsx
index d1a2b5f40..83f69d059 100644
--- a/apps/desktop/src/routes/editor/Header.tsx
+++ b/apps/desktop/src/routes/editor/Header.tsx
@@ -70,115 +70,127 @@ export function Header() {
: "Exporting Recording"
}
confirm={<></>}
+ class="bg-gray-600"
>
- <Switch>
- <Match when={progressState.type === "copying"}>
- {(when) => {
- const state = progressState as Extract<
- ProgressState,
- { type: "copying" }
- >;
- return (
- <div class="w-[80%] text-center mx-auto">
- <h3 class="text-sm font-medium mb-3 text-gray-50">
- {state.stage === "rendering"
- ? "Rendering video"
- : "Copying to clipboard"}
- </h3>
-
- <div class="w-full bg-gray-200 rounded-full h-2.5 mb-2">
- <div
- class="bg-blue-300 h-2.5 rounded-full transition-all duration-200"
- style={{
- width: `${
- state.stage === "rendering"
- ? Math.min(
- ((state.renderProgress || 0) /
- (state.totalFrames || 1)) *
- 100,
- 100
- )
- : Math.min(state.progress || 0, 100)
- }%`,
- }}
- />
+ <div class="min-h-[120px] flex items-center justify-center relative">
+ <Switch>
+ <Match when={progressState.type === "copying"}>
+ {(when) => {
+ const state = progressState as Extract<
+ ProgressState,
+ { type: "copying" }
+ >;
+ return (
+ <div class="w-[80%] text-center mx-auto relative z-10">
+ <h3 class="text-sm font-medium mb-3 text-gray-50">
+ {state.stage === "rendering"
+ ? "Rendering video"
+ : "Copying to clipboard"}
+ </h3>
+
+ <div class="w-full bg-gray-200 rounded-full h-2.5 mb-2">
+ <div
+ class="bg-blue-300 h-2.5 rounded-full transition-all duration-200"
+ style={{
+ width: `${
+ state.stage === "rendering"
+ ? Math.min(
+ ((state.renderProgress || 0) /
+ (state.totalFrames || 1)) *
+ 100,
+ 100
+ )
+ : Math.min(state.progress || 0, 100)
+ }%`,
+ }}
+ />
+ </div>
+
+ <p class="text-xs mt-3 relative z-10">{state.message}</p>
</div>
-
- <p class="text-xs text-gray-50 mt-2">{state.message}</p>
- </div>
- );
- }}
- </Match>
- <Match when={progressState.type === "saving"}>
- {(when) => {
- const state = progressState as Extract<
- ProgressState,
- { type: "saving" }
- >;
- return (
- <div class="w-[80%] text-center mx-auto">
- <h3 class="text-sm font-medium mb-3 text-gray-50">
- {state.stage === "rendering"
- ? "Rendering video"
- : "Saving file"}
- </h3>
-
- <div class="w-full bg-gray-200 rounded-full h-2.5 mb-2">
- <div
- class="bg-blue-300 h-2.5 rounded-full transition-all duration-200"
- style={{
- width: `${
- state.stage === "rendering"
- ? Math.min(
- ((state.renderProgress || 0) /
- (state.totalFrames || 1)) *
- 100,
- 100
- )
- : Math.min(state.progress || 0, 100)
- }%`,
- }}
- />
+ );
+ }}
+ </Match>
+ <Match when={progressState.type === "saving"}>
+ {(when) => {
+ const state = progressState as Extract<
+ ProgressState,
+ { type: "saving" }
+ >;
+ return (
+ <div class="w-[80%] text-center mx-auto relative z-10">
+ <h3 class="text-sm font-medium mb-3 text-gray-50">
+ {state.stage === "rendering"
+ ? "Rendering video"
+ : "Saving file"}
+ </h3>
+
+ <div class="w-full bg-gray-200 rounded-full h-2.5 mb-2">
+ <div
+ class="bg-blue-300 h-2.5 rounded-full transition-all duration-200"
+ style={{
+ width: `${
+ state.stage === "rendering"
+ ? Math.min(
+ ((state.renderProgress || 0) /
+ (state.totalFrames || 1)) *
+ 100,
+ 100
+ )
+ : Math.min(state.progress || 0, 100)
+ }%`,
+ }}
+ />
+ </div>
+
+ <p class="text-xs mt-3 relative z-10">{state.message}</p>
</div>
-
- <p class="text-xs text-gray-50 mt-2">{state.message}</p>
- </div>
- );
- }}
- </Match>
- <Match when={progressState.type === "uploading"}>
- {(when) => {
- const state = progressState as Extract<
- ProgressState,
- { type: "uploading" }
- >;
- return (
- <div class="w-[80%] text-center mx-auto">
- <h3 class="text-sm font-medium mb-3 text-gray-50">
- {state.stage === "rendering"
- ? "Rendering video"
- : "Creating shareable link"}
- </h3>
-
- <div class="w-full bg-gray-200 rounded-full h-2.5 mb-2">
- <div
- class="bg-blue-300 h-2.5 rounded-full transition-all duration-200"
- style={{
- width: `${
- state.stage === "rendering"
- ? Math.min(state.renderProgress || 0, 100)
- : Math.min(state.uploadProgress || 0, 100)
- }%`,
- }}
- />
+ );
+ }}
+ </Match>
+ <Match when={progressState.type === "uploading"}>
+ {(when) => {
+ const state = progressState as Extract<
+ ProgressState,
+ { type: "uploading" }
+ >;
+ return (
+ <div class="w-[80%] text-center mx-auto relative z-10">
+ <h3 class="text-sm font-medium mb-3 text-gray-50">
+ {state.stage === "rendering"
+ ? "Rendering video"
+ : "Creating shareable link"}
+ </h3>
+
+ <div class="w-full bg-gray-200 rounded-full h-2.5 mb-2">
+ <div
+ class="bg-blue-300 h-2.5 rounded-full transition-all duration-200"
+ style={{
+ width: `${
+ state.stage === "rendering"
+ ? Math.min(state.renderProgress || 0, 100)
+ : Math.min(
+ (state.uploadProgress || 0) * 100,
+ 100
+ )
+ }%`,
+ }}
+ />
+ </div>
+
+ <p class="text-xs text-white mt-3 relative z-10">
+ {state.stage === "rendering"
+ ? `Rendering - ${Math.round(
+ state.renderProgress || 0
+ )}%`
+ : state.message}
+ </p>
</div>
-
- <p class="text-xs text-gray-50 mt-2">{state.message}</p>
- </div>
- );
- }}
- </Match>
- </Switch>
+ );
+ }}
+ </Match>
+ </Switch>
+ </div>
</DialogContent>
</Dialog.Root>
</>
@@ -263,97 +275,160 @@ function ShareButton() {
const uploadVideo = createMutation(() => ({
mutationFn: async () => {
- if (!recordingMeta()) return;
-
- if (recordingMeta()?.sharing) {
- // Use reupload for existing shares
- return await commands.reuploadRenderedVideo(
- videoId,
- project
- ? project
- : presets.getDefaultConfig() ?? DEFAULT_PROJECT_CONFIG
- );
+ console.log("Starting upload process...");
+ if (!recordingMeta()) {
+ console.error("No recording metadata available");
+ throw new Error("Recording metadata not available");
}
- setProgressState({
- type: "uploading",
- renderProgress: 0,
- uploadProgress: 0,
- message: "Preparing to render...",
- mediaPath: videoId,
- stage: "rendering",
- totalFrames: 0,
- });
+ let unlisten: (() => void) | undefined;
- // Listen for upload progress events
- const unlisten = await events.uploadProgress.listen(
- (event: {
- payload: { stage: string; progress: number; message: string };
- }) => {
+ try {
+ // Set initial progress state
+ setProgressState({
+ type: "uploading",
+ renderProgress: 0,
+ uploadProgress: 0,
+ message: "Rendering - 0%",
+ mediaPath: videoId,
+ stage: "rendering",
+ });
+
+ // Setup progress listener before starting upload
+ unlisten = await events.uploadProgress.listen((event) => {
+ console.log("Upload progress event:", event.payload);
if (progressState.type === "uploading") {
+ const progress = Math.round(event.payload.progress * 100);
if (event.payload.stage === "rendering") {
setProgressState({
type: "uploading",
- renderProgress: Math.round(event.payload.progress * 100),
+ renderProgress: progress,
uploadProgress: 0,
- message: event.payload.message,
+ message: `Rendering - ${progress}%`,
mediaPath: videoId,
stage: "rendering",
- totalFrames: progressState.totalFrames,
});
} else {
setProgressState({
type: "uploading",
renderProgress: 100,
- uploadProgress: Math.round(event.payload.progress * 100),
- message: event.payload.message,
+ uploadProgress: progress,
+ message: `Uploading - ${progress}%`,
mediaPath: videoId,
stage: "uploading",
- totalFrames: progressState.totalFrames,
});
}
}
+ });
+
+ console.log("Starting actual upload...");
+ const projectConfig =
+ project ?? presets.getDefaultConfig() ?? DEFAULT_PROJECT_CONFIG;
+
+ // First try to get or render the video
+ try {
+ setProgressState({
+ type: "uploading",
+ renderProgress: 0,
+ uploadProgress: 0,
+ message: "Rendering - 0%",
+ mediaPath: videoId,
+ stage: "rendering",
+ });
+
+ const progress = new Channel<RenderProgress>();
+ progress.onmessage = (p) => {
+ console.log("Progress channel message:", p);
+ if (
+ p.type === "FrameRendered" &&
+ progressState.type === "uploading"
+ ) {
+ const renderProgress = Math.round(
+ (p.current_frame / (progressState.totalFrames || 1)) * 100
+ );
+ setProgressState({
+ ...progressState,
+ message: `Rendering - ${renderProgress}%`,
+ renderProgress,
+ });
+ }
+ if (
+ p.type === "EstimatedTotalFrames" &&
+ progressState.type === "uploading"
+ ) {
+ console.log("Got total frames:", p.total_frames);
+ setProgressState({
+ ...progressState,
+ totalFrames: p.total_frames,
+ });
+ }
+ };
+
+ await commands.renderVideoWithProgress(
+ videoId,
+ projectConfig,
+ progress
+ );
+ } catch (error) {
+ console.error("Error rendering video:", error);
+ throw new Error("Failed to render video");
}
- );
- try {
- const result = await commands.uploadRenderedVideo(
- videoId,
- project
- ? project
- : presets.getDefaultConfig() ?? DEFAULT_PROJECT_CONFIG,
- null
- );
+ // Now proceed with upload
+ const result = recordingMeta()?.sharing
+ ? await commands.reuploadRenderedVideo(videoId, projectConfig)
+ : await commands.uploadRenderedVideo(videoId, projectConfig, null);
- unlisten();
+ console.log("Upload result:", result);
if (result === "NotAuthenticated") {
- throw new Error("Not authenticated");
+ throw new Error("You need to sign in to share recordings");
}
if (result === "PlanCheckFailed") {
- throw new Error("Plan check failed");
+ throw new Error("Failed to verify your subscription status");
}
if (result === "UpgradeRequired") {
- throw new Error("Upgrade required");
+ throw new Error("This feature requires an upgraded plan");
}
+ // Show success state briefly before resetting
+ setProgressState({
+ type: "uploading",
+ renderProgress: 100,
+ uploadProgress: 100,
+ message: "Upload complete!",
+ mediaPath: videoId,
+ stage: "uploading",
+ });
+
+ setTimeout(() => {
+ setProgressState({ type: "idle" });
+ }, 1500);
+
return result;
} catch (error) {
- unlisten();
+ console.error("Upload error:", error);
setProgressState({ type: "idle" });
- throw error;
+ throw error instanceof Error
+ ? error
+ : new Error("Failed to upload recording");
+ } finally {
+ if (unlisten) {
+ console.log("Cleaning up upload progress listener");
+ unlisten();
+ }
}
},
onSuccess: () => {
+ console.log("Upload successful, refreshing metadata");
metaActions.refetch();
- // Don't immediately set to idle - let the progress show for a moment
- setTimeout(() => {
- setProgressState({ type: "idle" });
- }, 1500);
},
onError: (error) => {
- console.error("Upload error:", error);
+ console.error("Upload mutation error:", error);
setProgressState({ type: "idle" });
+ commands.globalMessageDialog(
+ error instanceof Error ? error.message : "Failed to upload recording"
+ );
},
}));