The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 07:15 UTC
fix(web): PDFs in the desktop file panel can be saved again (#38749)
Julius Marminge committed
Nov 18, 2026 at 13:32 UTC
e48d6f31817ad12975af2ffd341ae2b1b961d247
3 files changed
+66
-1
apps/web/src/components/files/BrowserDocumentFrame.tsx
+13
-1
@@ -28,6 +28,7 @@ import {
28
} from "@t3tools/shared/keybindings";
29
import {
30
lazy,
31
+ type ReactNode,
32
Suspense,
33
useEffect,
34
useEffectEvent,
@@ -79,7 +80,12 @@ export const isPdfPreviewFile = (path: string): boolean =>
80
const PdfViewer = lazy(() => import("./PdfViewer"));
81
82
// The document stays mounted while each revision gets a fresh PDF.js document.
82
-function PdfDocument(props: { src: string; title: string; documentKey: string }) {
83
+function PdfDocument(props: {
84
+ src: string;
85
+ title: string;
86
+ documentKey: string;
87
+ actions?: ReactNode;
88
+}) {
89
const [view, setView] = useState<PdfViewState>({ page: 0, offset: 0, zoom: null, left: 0 });
90
return (
91
<PdfDocumentRevision
@@ -89,6 +95,7 @@ function PdfDocument(props: { src: string; title: string; documentKey: string })
95
positionKey={props.documentKey}
96
initialView={view}
97
onViewChange={setView}
98
+ actions={props.actions}
99
/>
100
);
101
}
@@ -100,6 +107,7 @@ function PdfDocumentRevision(props: {
107
positionKey: string;
108
initialView: PdfViewState;
109
onViewChange: (view: PdfViewState) => void;
110
+ actions?: ReactNode;
111
}) {
112
const [src] = useState(props.src);
113
// The Electron shell does not enable PDF plugins. WebKit embeds on iOS
@@ -124,6 +132,7 @@ function PdfDocumentRevision(props: {
132
positionKey={props.positionKey}
133
initialView={props.initialView}
134
onViewChange={props.onViewChange}
135
+ actions={props.actions}
136
/>
137
</Suspense>
138
);
@@ -143,6 +152,8 @@ export function BrowserDocumentFrame(props: {
152
readonly documentKey?: string | undefined;
153
/** Resource identity without its revision, so PDF reloads can retain the reading position. */
154
readonly documentId?: string | undefined;
155
+ /** Toolbar actions for the in-app PDF viewer; Chromium's own viewer brings its own. */
156
+ readonly pdfActions?: ReactNode;
157
}) {
158
const key = props.documentKey ?? props.src;
159
return props.pdf ? (
@@ -151,6 +162,7 @@ export function BrowserDocumentFrame(props: {
162
documentKey={key}
163
src={props.src}
164
title={props.title}
165
+ actions={props.pdfActions}
166
/>
167
) : props.htmlRender ? (
168
<HtmlRenderDocument
apps/web/src/components/files/FilePreviewPanel.tsx
+50
@@ -5,6 +5,7 @@ import { m, type MessageResolver } from "~/i18n/messages";
5
import { namedClipboardTarget, useCopyToClipboard } from "~/hooks/useCopyToClipboard";
6
import { Spinner } from "~/components/ui/spinner";
7
import {
8
+ type AssetResource,
9
AuthPreviewOperateScope,
10
type EditorId,
11
type EnvironmentId,
@@ -296,10 +297,59 @@ export function WorkspaceBrowserPreview(props: {
297
documentId={`${props.environmentId}:${resource._tag}:${props.threadRef.threadId}:${props.absolutePath}`}
298
title={props.title}
299
pdf={pdf}
300
+ pdfActions={
301
+ <WorkspacePdfSaveAction
302
+ environmentId={props.environmentId}
303
+ resource={resource}
304
+ name={props.title}
305
+ />
306
+ }
307
/>
308
);
309
}
310
311
+function WorkspacePdfSaveAction(props: {
312
+ readonly environmentId: EnvironmentId;
313
+ readonly resource: AssetResource;
314
+ readonly name: string;
315
+}) {
316
+ const gt = useGT();
317
+ const [saving, setSaving] = useState(false);
318
+ const refreshAssetUrl = useAssetUrlRefresh(props.environmentId, props.resource);
319
+ return (
320
+ <FileSurfaceAction
321
+ label={saving ? gt("Preparing file…") : gt("Save file")}
322
+ disabled={saving}
323
+ onPress={() => {
324
+ setSaving(true);
325
+ void (async () => {
326
+ const url = await refreshAssetUrl();
327
+ if (!url) throw new Error(gt("Reconnect to the environment and try again."));
328
+ const response = await fetch(url);
329
+ if (!response.ok) throw new Error(gt("The file could not be loaded. Try again."));
330
+ // Blob downloads keep desktop's custom app scheme from navigating to an external browser.
331
+ const downloadUrl = URL.createObjectURL(await response.blob());
332
+ setTimeout(() => URL.revokeObjectURL(downloadUrl), 30_000);
333
+ const anchor = document.createElement("a");
334
+ anchor.href = downloadUrl;
335
+ anchor.download = props.name.split(/[\\/]/).at(-1) || props.name;
336
+ anchor.click();
337
+ })()
338
+ .catch((cause: unknown) =>
339
+ toastManager.add({
340
+ type: "error",
341
+ title: gt("Could not save file"),
342
+ description: thrownErrorMessage(cause, m) ?? gt("Please try again."),
343
+ }),
344
+ )
345
+ .finally(() => setSaving(false));
346
+ }}
347
+ >
348
+ <DownloadIcon className="size-3.5" />
349
+ </FileSurfaceAction>
350
+ );
351
+}
352
+
353
function WorkspaceVideoPreview(props: {
354
readonly environmentId: EnvironmentId;
355
readonly threadRef: ScopedThreadRef;
apps/web/src/components/files/PdfViewer.tsx
+3
@@ -6,6 +6,7 @@ import {
6
useRef,
7
useState,
8
type CSSProperties,
9
+ type ReactNode,
10
} from "react";
11
import { TextLayer, type PDFDocumentProxy } from "pdfjs-dist";
12
import { msg, useGT } from "gt-react";
@@ -144,6 +145,7 @@ export default function PdfViewer(props: {
145
positionKey?: string;
146
initialView?: PdfViewState;
147
onViewChange?: (view: PdfViewState) => void;
148
+ actions?: ReactNode;
149
}) {
150
const gt = useGT();
151
const [savedPosition] = useState(() =>
@@ -448,6 +450,7 @@ export default function PdfViewer(props: {
450
</FileSurfaceAction>
451
</>
452
) : null}
453
+ {props.actions}
454
</div>
455
<div
456
ref={scroll}