The VS Code of video editing, built for agents.
TypeScript
Refactor Export Progress Component and Enhance Cancel Functionality
konstantin-paulus11995532b659
diff --git a/apps/web/src/components/sidebar-right/inspector/export-progress.tsx b/apps/web/src/components/sidebar-right/inspector/export-progress.tsxindex c1ab7f4f..461c1a8e 100644--- a/apps/web/src/components/sidebar-right/inspector/export-progress.tsx+++ b/apps/web/src/components/sidebar-right/inspector/export-progress.tsx@@ -2,118 +2,102 @@* License, v. 2.0. If a copy of the MPL was not distributed with this* file, You can obtain one at http://mozilla.org/MPL/2.0/. */+import { createEffect, createMemo, createSignal, on } from "solid-js";import { Show, Portal } from "solid-js/web";+import {+ AlertDialog,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogPortal,+ AlertDialogTitle,+} from "@/components/ui/alert-dialog";import { Button } from "@/components/ui/button";-import { Icon } from "@/components/ui/icon";-import { formatDuration } from "@/utils/formatters";-import type { EncoderConfig } from "@diffusionstudio/encoder";--/** The settings this overlay reads: the encoder's, less how it is driven. */-export type ExportConfig = Omit<- EncoderConfig,- "target" | "scene" | "onProgress" | "realizeScene" | "comment"->;type ExportProgressProps = {open: boolean;+ audioOnly: boolean;progress: number;remaining?: { minutes: number; seconds: number };- config?: ExportConfig;- width: number;- height: number;- duration: number;onCancel: () => void;};export function ExportProgress(props: ExportProgressProps) {- const cfg = () => props.config;+ const [confirming, setConfirming] = createSignal(false);+ const open = createMemo(() => props.open);+ createEffect(on(open, () => setConfirming(false)));++ const confirmCancel = () => {+ setConfirming(false);+ props.onCancel();+ };- const format = () => (cfg()?.format ?? "mp4").toUpperCase();- const fps = () => cfg()?.video?.fps ?? 30;- const videoCodec = () => cfg()?.video?.codec ?? "avc";- const audioCodec = () => cfg()?.audio?.codec ?? "aac";- const sampleRate = () =>- Math.round((cfg()?.audio?.sampleRate ?? 48000) / 1000);- const bitrate = () => {- const bps = cfg()?.video?.bitrate ?? 10e6;- return `${(bps / 1e6).toFixed(1)} Mbps`;+ const remaining = () => {+ const r = props.remaining;+ if (!r) return;+ return r.minutes > 0+ ? `~${r.minutes}m ${r.seconds}s remaining`+ : `~${r.seconds}s remaining`;};return (<Show when={props.open}><Portal>- <div class="fixed inset-0 z-50 bg-overlay-strong" />- <div class="fixed inset-0 z-50 flex items-center justify-center">+ <div class="fixed inset-0 z-50 flex items-center justify-center bg-background"><div class="flex w-full max-w-md flex-col items-center px-6">- <h4 class="text-lg">Exporting Composition</h4>+ <h4 class="text-[14px] mb-2">+ {props.audioOnly ? "Exporting audio..." : "Exporting video..."}+ </h4>- <div class="mt-4 flex w-full flex-col gap-2">+ <div+ role="progressbar"+ aria-valuemin={0}+ aria-valuemax={100}+ aria-valuenow={props.progress}+ class="mt-8 h-1.5 w-full overflow-hidden rounded-full bg-foreground/10"+ ><div- class="grid w-full auto-cols-auto grid-flow-col grid-rows-4 gap-y-2 rounded-lg border border-foreground/10 bg-foreground/5 px-3 py-3 text-xs- [&>div]:w-2 [&>p]:text-foreground [&>span]:text-muted-foreground"- >- <span>Duration</span>- <span>Resolution</span>- <span>Bitrate</span>- <span>Frame rate</span>-- <p>{formatDuration(props.duration)}</p>- <p>- {props.width} x {props.height}- </p>- <p>{bitrate()}</p>- <p>{fps()} FPS</p>-- <div />- <div />- <div />- <div />-- <span>Video Codec</span>- <span>Container</span>- <span>Audio Codec</span>- <span>Sample Rate</span>-- <p>{videoCodec()}</p>- <p>{format()}</p>- <p>{audioCodec()}</p>- <p>{sampleRate()} KHz</p>- </div>-- <div>- <div class="mt-2 mb-2 flex w-full justify-between text-sm">- <p class="text-muted-foreground">Progress</p>- <p>- {props.progress}%- <Show when={props.remaining}>- {(r) => (- <span>- {" "}- · {r().minutes}min {r().seconds}s- </span>- )}- </Show>- </p>- </div>- <div class="relative h-2 w-full overflow-hidden rounded-full bg-foreground/20">- <div- class="h-full bg-foreground rounded-full transition-all"- style={{ width: `${props.progress}%` }}- />- </div>- </div>+ class="h-full rounded-full bg-primary transition-all"+ style={{ width: `${props.progress}%` }}+ />+ </div>+ <div class="mt-3 flex w-full justify-between text-xs tabular-nums">+ <span class="text-muted-foreground">{remaining()}</span>+ <span>{props.progress}%</span></div><Button- class="mt-6 border-foreground/15 bg-foreground/10 shadow-none gap-0.5 pl-1 pr-3"- onClick={props.onCancel}+ variant="secondary"+ class="mt-8 px-3"+ onClick={() => setConfirming(true)}>- <Icon name="spinner-loader" class="size-6 animate-spin" />- Cancel+ Cancel Export</Button></div></div></Portal>++ <AlertDialog open={confirming()} onOpenChange={setConfirming}>+ <AlertDialogPortal>+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>Stop exporting?</AlertDialogTitle>+ <AlertDialogDescription>+ The export is still in progress. You'll need to start over if you stop now.+ </AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogFooter>+ <Button variant="secondary" onClick={() => setConfirming(false)}>+ Continue+ </Button>+ <Button variant="destructive" onClick={confirmCancel}>+ Stop export+ </Button>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialogPortal>+ </AlertDialog></Show>);}diff --git a/apps/web/src/context/export.tsx b/apps/web/src/context/export.tsxindex cd9f98b5..e7988564 100644--- a/apps/web/src/context/export.tsx+++ b/apps/web/src/context/export.tsx@@ -11,8 +11,8 @@ import { Computed, getActiveEntity } from "@diffusionstudio/runtime";import { assert, downloadObject, isInputTarget } from "@/utils";import { useEngineContext } from "@/engine";import { useProject } from "@/context/project";-import { ExportProgress, type ExportConfig } from "@/components/sidebar-right/inspector/export-progress";-import { renderScene, renderOverlay, cancelRender } from "@/context/render";+import { ExportProgress } from "@/components/sidebar-right/inspector/export-progress";+import { renderScene, renderOverlay, cancelRender, type ExportConfig } from "@/context/render";import {MIME_TYPES,getDefaultExportTemplate,@@ -155,12 +155,9 @@ export function ExportProvider(props: { children: JSX.Element }) {{props.children}<ExportProgressopen={!!renderOverlay()}+ audioOnly={renderOverlay()?.audioOnly ?? false}progress={renderOverlay()?.progress ?? 0}remaining={renderOverlay()?.remaining}- config={renderOverlay()?.config as ExportConfig | undefined}- width={renderOverlay()?.width ?? 0}- height={renderOverlay()?.height ?? 0}- duration={renderOverlay()?.duration ?? 0}onCancel={cancelRender}/></ExportContext.Provider>diff --git a/apps/web/src/context/render.ts b/apps/web/src/context/render.tsindex 1d205217..f6c89711 100644--- a/apps/web/src/context/render.ts+++ b/apps/web/src/context/render.ts@@ -3,7 +3,7 @@* file, You can obtain one at http://mozilla.org/MPL/2.0/. */import { createSignal } from "solid-js";-import { createEncoder, computeOutputSize } from "@diffusionstudio/encoder";+import { createEncoder } from "@diffusionstudio/encoder";import { Computed, FrameRate, Workarea } from "@diffusionstudio/runtime";import { createCapture } from "@/engine/capture";@@ -14,22 +14,24 @@ import type { Entity } from "koota";import type { EncoderConfig, ExportResult } from "@diffusionstudio/encoder";import type { Capture } from "@/engine/capture";import type { Engine } from "@/engine";-import type { ExportConfig } from "@/components/sidebar-right/inspector/export-progress";/*** Unified scene render path, used by the UI export (`ExportProvider.exportScene`)- * and the agent's export tool (`dapi/handlers/export`): the "Exporting- * Composition" overlay, the engine stop/start lifecycle, the capture world the+ * and the agent's export tool (`dapi/handlers/export`): the export+ * progress overlay, the engine stop/start lifecycle, the capture world the* encode runs against, progress reporting, cancel wiring, and the export* analytics events all live in {@link renderScene}.*/+/** The encoder settings a render takes: the encoder's, less how it is driven. */+export type ExportConfig = Omit<+ EncoderConfig,+ "target" | "scene" | "onProgress" | "realizeScene" | "comment"+>;+export type RenderOverlayState = {- config?: Partial<ExportConfig>;- /** The encode's actual pixel size, from the scene's own aspect ratio. */- width: number;- height: number;- duration: number;+ /** No video track is encoded: video is off, or the container is audio-only. */+ audioOnly: boolean;progress: number;remaining?: { minutes: number; seconds: number };};@@ -73,16 +75,10 @@ export async function renderScene(: computed?.duration ?? 0;const duration = frames / (world.get(FrameRate)?.value || 30);- // The same size the encoder works out for itself, so the overlay reports- // the dimensions actually encoded — the scene's aspect ratio, not 16:9.- const { width, height } = computeOutputSize(- computed?.width || 1920,- computed?.height || 1080,- config?.video?.resolution ?? 1080,- );+ const audioOnly = config?.video?.enabled === false || config?.format === "ogg";cancelActive = undefined;- setOverlay({ config, width, height, duration, progress: 0, remaining: undefined });+ setOverlay({ audioOnly, progress: 0, remaining: undefined });let logged = -1;const logProgress = (percent: number) => {@@ -119,7 +115,7 @@ export async function renderScene(capture = await createCapture(world, scene, {dir,frameRate: config?.video?.fps,- mode: config?.video?.enabled === false || config?.format === "ogg" ? "offline-audio" : "offline-video",+ mode: audioOnly ? "offline-audio" : "offline-video",});const encoder = await createEncoder(capture.world, {