diff --git a/apps/desktop/src/settings/DesktopClientSettings.test.ts b/apps/desktop/src/settings/DesktopClientSettings.test.ts index d66ca346aabb3..1bc9fd681e54d 100644 --- a/apps/desktop/src/settings/DesktopClientSettings.test.ts +++ b/apps/desktop/src/settings/DesktopClientSettings.test.ts @@ -22,6 +22,7 @@ const clientSettings: ClientSettings = { notificationMode: "notifications-and-sound", inAppNotificationsEnabled: true, appearanceContrast: 100, + pdfAppearance: "dark", browserDefaultViewport: { _tag: "preset", width: 1024, height: 600, presetId: "nest-hub" }, browserDefaultZoomFactor: 1.25, browserDefaultAppearance: "dark", diff --git a/apps/mobile/src/components/PdfAppearance.tsx b/apps/mobile/src/components/PdfAppearance.tsx new file mode 100644 index 0000000000000..a1eb5ed6661f5 --- /dev/null +++ b/apps/mobile/src/components/PdfAppearance.tsx @@ -0,0 +1,59 @@ +import { useGT } from "gt-react-native"; +import { useAtomValue } from "@effect/atom-react"; +import { AsyncResult } from "effect/reactivity"; +import { useState, type ReactNode } from "react"; +import { Platform, StyleSheet, View } from "react-native"; + +import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider"; +import { mobilePreferencesAtom } from "../state/preferences"; +import { ControlPill } from "./ui/ControlPill"; + +export function PdfAppearance(props: { readonly children: ReactNode }) { + const gt = useGT(); + const preferences = useAtomValue(mobilePreferencesAtom); + const appearance = AsyncResult.isSuccess(preferences) + ? (preferences.value.pdfAppearance ?? "match-app") + : "match-app"; + const { themeAppearance } = useAppearancePreferences(); + const [override, setOverride] = useState(null); + const dark = + override ?? + (appearance === "dark" || (appearance === "match-app" && themeAppearance === "dark")); + + return ( + + + setOverride(!dark)} + /> + + + {props.children} + {Platform.OS === "ios" && dark ? ( + // iOS supports blending but not the invert filter. + + ) : null} + + + ); +} diff --git a/apps/mobile/src/components/PdfPreview.android.tsx b/apps/mobile/src/components/PdfPreview.android.tsx index 89328245a43c6..f05d9d43f1b17 100644 --- a/apps/mobile/src/components/PdfPreview.android.tsx +++ b/apps/mobile/src/components/PdfPreview.android.tsx @@ -13,6 +13,7 @@ import { pdfInitialPage, pdfLinkUrl, preparePdfPreview } from "../lib/pdfPreview import { m } from "../i18n/messages"; import { tryOpenExternalUrl } from "../lib/openExternalUrl"; import { ControlPill } from "./ui/ControlPill"; +import { PdfAppearance } from "./PdfAppearance"; const preparedPdfAtom = Atom.family((uri: string) => Atom.make( @@ -49,6 +50,14 @@ const preparedPdfAtom = Atom.family((uri: string) => ); export function PdfPreview(props: { readonly uri: string }) { + return ( + + + + ); +} + +function PdfContent(props: { readonly uri: string }) { const gt = useGT(); const atom = preparedPdfAtom(props.uri); const prepared = useAtomValue(atom); diff --git a/apps/mobile/src/components/PdfPreview.tsx b/apps/mobile/src/components/PdfPreview.tsx index 05c516c81b258..031af667c2a56 100644 --- a/apps/mobile/src/components/PdfPreview.tsx +++ b/apps/mobile/src/components/PdfPreview.tsx @@ -4,6 +4,7 @@ import { View } from "react-native"; import { WebView } from "react-native-webview"; import { FilePreviewLoading, FilePreviewNotice } from "../features/files/FilePreviewFeedback"; +import { PdfAppearance } from "./PdfAppearance"; import { webViewDecelerationRate } from "../lib/webViewDecelerationRate"; export function PdfPreview(props: { readonly uri: string }) { @@ -14,28 +15,30 @@ export function PdfPreview(props: { readonly uri: string }) { {error ? ( {error} ) : null} - - setError(event.nativeEvent.description || gt("The PDF could not be loaded.")) - } - onHttpError={(event) => - setError( - gt("The server returned HTTP {statusCode}.", { - statusCode: event.nativeEvent.statusCode, - }), - ) - } - renderLoading={() => ( - - )} - style={{ flex: 1, backgroundColor: "transparent" }} - /> + + + setError(event.nativeEvent.description || gt("The PDF could not be loaded.")) + } + onHttpError={(event) => + setError( + gt("The server returned HTTP {statusCode}.", { + statusCode: event.nativeEvent.statusCode, + }), + ) + } + renderLoading={() => ( + + )} + style={{ flex: 1, backgroundColor: "transparent" }} + /> + ); } diff --git a/apps/mobile/src/features/settings/SettingsAppearanceRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsAppearanceRouteScreen.tsx index 3046a19e71074..ef7e3fb704fb6 100644 --- a/apps/mobile/src/features/settings/SettingsAppearanceRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsAppearanceRouteScreen.tsx @@ -9,6 +9,7 @@ import { CodeAppearanceSection } from "./appearance/sections/CodeAppearanceSecti import { TerminalAppearanceSection } from "./appearance/sections/TerminalAppearanceSection"; import { TextAppearanceSection } from "./appearance/sections/TextAppearanceSection"; import { ThemeAppearanceSection } from "./appearance/sections/ThemeAppearanceSection"; +import { PdfAppearanceSection } from "./appearance/sections/PdfAppearanceSection"; import { ToolCallsAppearanceSection } from "./appearance/sections/ToolCallsAppearanceSection"; export function SettingsAppearanceRouteScreen() { @@ -31,6 +32,7 @@ export function SettingsAppearanceRouteScreen() { + diff --git a/apps/mobile/src/features/settings/appearance/sections/PdfAppearanceSection.tsx b/apps/mobile/src/features/settings/appearance/sections/PdfAppearanceSection.tsx new file mode 100644 index 0000000000000..7746b88b96697 --- /dev/null +++ b/apps/mobile/src/features/settings/appearance/sections/PdfAppearanceSection.tsx @@ -0,0 +1,43 @@ +import { msg, useGT, useMessages } from "gt-react-native"; +import { useAtomValue } from "@effect/atom-react"; +import type { PdfAppearance } from "@t3tools/contracts/settings"; +import { AsyncResult } from "effect/reactivity"; +import { View } from "react-native"; + +import { ListChoiceRow } from "../../../../components/ui/ListChoiceRow"; +import { mobilePreferencesAtom, saveMobilePreferences } from "../../../../state/preferences"; +import { useAtomCommand } from "../../../../state/use-atom-command"; +import { SettingsSection } from "../../components/SettingsSection"; + +const OPTIONS: ReadonlyArray = [ + ["match-app", msg("Match theme")], + ["original", msg("Original colors")], + ["dark", msg("Inverted colors")], +]; + +export function PdfAppearanceSection() { + const gt = useGT(); + const m = useMessages(); + const preferences = useAtomValue(mobilePreferencesAtom); + const savePreferences = useAtomCommand(saveMobilePreferences); + const ready = AsyncResult.isSuccess(preferences); + const appearance = ready ? (preferences.value.pdfAppearance ?? "match-app") : "match-app"; + return ( + + + {OPTIONS.map(([value, label], index) => ( + { + void savePreferences({ pdfAppearance: value }); + }} + separated={index > 0} + /> + ))} + + + ); +} diff --git a/apps/mobile/src/i18n/translations/de.json b/apps/mobile/src/i18n/translations/de.json index f538b87920412..ee4a1f633859b 100644 --- a/apps/mobile/src/i18n/translations/de.json +++ b/apps/mobile/src/i18n/translations/de.json @@ -5464,5 +5464,11 @@ "ad208e3e32c85029": "Alle ausblenden", "3328503592789bed": "Zen", "856812e7e1fc445e": "Tool-Aufrufe im Chat", - "8d545d54c0a9e950": "Die Befehle, Bearbeitungen und Suchen ausblenden, die Agenten ausführen. „Erfolgreiche ausblenden“ behält Fehler. „Zen“ zeigt nur endgültige Antworten. Genehmigungen, Fragen und Fehler werden immer angezeigt." + "8d545d54c0a9e950": "Die Befehle, Bearbeitungen und Suchen ausblenden, die Agenten ausführen. „Erfolgreiche ausblenden“ behält Fehler. „Zen“ zeigt nur endgültige Antworten. Genehmigungen, Fragen und Fehler werden immer angezeigt.", + "6dc1e8c15f62989d": "Originalfarben wiederherstellen", + "0d576a2c32b02d5d": "Farben invertieren", + "66104e819c8d2122": "Design übernehmen", + "a368bf0b43feb260": "Originalfarben", + "4d2fa01e838b9549": "Invertierte Farben", + "1c19f2863386a317": "PDF-Farben" } diff --git a/apps/mobile/src/i18n/translations/en.json b/apps/mobile/src/i18n/translations/en.json index 745201ad99094..f1059b7d4fae2 100644 --- a/apps/mobile/src/i18n/translations/en.json +++ b/apps/mobile/src/i18n/translations/en.json @@ -5466,5 +5466,11 @@ "ad208e3e32c85029": "Hide all", "3328503592789bed": "Zen", "856812e7e1fc445e": "Tool calls in chat", - "8d545d54c0a9e950": "Hide the commands, edits, and searches agents run. Hide successful keeps failures. Zen shows only final answers. Approvals, questions, and errors always show." + "8d545d54c0a9e950": "Hide the commands, edits, and searches agents run. Hide successful keeps failures. Zen shows only final answers. Approvals, questions, and errors always show.", + "6dc1e8c15f62989d": "Restore original colors", + "0d576a2c32b02d5d": "Invert colors", + "66104e819c8d2122": "Match theme", + "a368bf0b43feb260": "Original colors", + "4d2fa01e838b9549": "Inverted colors", + "1c19f2863386a317": "PDF colors" } diff --git a/apps/mobile/src/i18n/translations/es.json b/apps/mobile/src/i18n/translations/es.json index fb134339cd3c4..abe3a98ff2f89 100644 --- a/apps/mobile/src/i18n/translations/es.json +++ b/apps/mobile/src/i18n/translations/es.json @@ -5458,5 +5458,11 @@ "ad208e3e32c85029": "Ocultar todo", "3328503592789bed": "Zen", "856812e7e1fc445e": "Llamadas a herramientas en el chat", - "8d545d54c0a9e950": "Oculta los comandos, ediciones y búsquedas que ejecutan los agentes. Ocultar las correctas mantiene los fallos. Zen solo muestra las respuestas finales. Las aprobaciones, preguntas y errores siempre se muestran." + "8d545d54c0a9e950": "Oculta los comandos, ediciones y búsquedas que ejecutan los agentes. Ocultar las correctas mantiene los fallos. Zen solo muestra las respuestas finales. Las aprobaciones, preguntas y errores siempre se muestran.", + "6dc1e8c15f62989d": "Restaurar colores originales", + "0d576a2c32b02d5d": "Invertir colores", + "66104e819c8d2122": "Seguir el tema", + "a368bf0b43feb260": "Colores originales", + "4d2fa01e838b9549": "Colores invertidos", + "1c19f2863386a317": "Colores del PDF" } diff --git a/apps/mobile/src/i18n/translations/fr.json b/apps/mobile/src/i18n/translations/fr.json index d6aef220df3a2..670452aafefa7 100644 --- a/apps/mobile/src/i18n/translations/fr.json +++ b/apps/mobile/src/i18n/translations/fr.json @@ -5458,5 +5458,11 @@ "ad208e3e32c85029": "Tout masquer", "3328503592789bed": "Zen", "856812e7e1fc445e": "Appels d’outils dans la discussion", - "8d545d54c0a9e950": "Masque les commandes, modifications et recherches lancées par les agents. Masquer les réussis garde les échecs. Zen n’affiche que les réponses finales. Les approbations, questions et erreurs s’affichent toujours." + "8d545d54c0a9e950": "Masque les commandes, modifications et recherches lancées par les agents. Masquer les réussis garde les échecs. Zen n’affiche que les réponses finales. Les approbations, questions et erreurs s’affichent toujours.", + "6dc1e8c15f62989d": "Rétablir les couleurs d’origine", + "0d576a2c32b02d5d": "Inverser les couleurs", + "66104e819c8d2122": "Suivre le thème", + "a368bf0b43feb260": "Couleurs d’origine", + "4d2fa01e838b9549": "Couleurs inversées", + "1c19f2863386a317": "Couleurs du PDF" } diff --git a/apps/mobile/src/i18n/translations/ja.json b/apps/mobile/src/i18n/translations/ja.json index 8cd9fba5c8332..246e32825162e 100644 --- a/apps/mobile/src/i18n/translations/ja.json +++ b/apps/mobile/src/i18n/translations/ja.json @@ -5439,5 +5439,11 @@ "ad208e3e32c85029": "すべて非表示", "3328503592789bed": "Zen", "856812e7e1fc445e": "チャット内のツール呼び出し", - "8d545d54c0a9e950": "エージェントが実行するコマンド、編集、検索を非表示にします。「成功したものを非表示」では失敗は表示されます。Zen では最終的な回答だけを表示します。承認、質問、エラーは常に表示されます。" + "8d545d54c0a9e950": "エージェントが実行するコマンド、編集、検索を非表示にします。「成功したものを非表示」では失敗は表示されます。Zen では最終的な回答だけを表示します。承認、質問、エラーは常に表示されます。", + "6dc1e8c15f62989d": "元の色に戻す", + "0d576a2c32b02d5d": "色を反転", + "66104e819c8d2122": "テーマに合わせる", + "a368bf0b43feb260": "元の色", + "4d2fa01e838b9549": "反転した色", + "1c19f2863386a317": "PDFの色" } diff --git a/apps/mobile/src/i18n/translations/ko.json b/apps/mobile/src/i18n/translations/ko.json index 731eaeecaec22..cbc72d39c716e 100644 --- a/apps/mobile/src/i18n/translations/ko.json +++ b/apps/mobile/src/i18n/translations/ko.json @@ -5443,5 +5443,11 @@ "ad208e3e32c85029": "모두 숨기기", "3328503592789bed": "Zen", "856812e7e1fc445e": "채팅의 도구 호출", - "8d545d54c0a9e950": "에이전트가 실행하는 명령, 편집, 검색을 숨깁니다. 성공한 항목 숨기기는 실패를 남겨 둡니다. Zen은 최종 답변만 표시합니다. 승인, 질문, 오류는 항상 표시됩니다." + "8d545d54c0a9e950": "에이전트가 실행하는 명령, 편집, 검색을 숨깁니다. 성공한 항목 숨기기는 실패를 남겨 둡니다. Zen은 최종 답변만 표시합니다. 승인, 질문, 오류는 항상 표시됩니다.", + "6dc1e8c15f62989d": "원래 색상으로 복원", + "0d576a2c32b02d5d": "색상 반전", + "66104e819c8d2122": "테마에 맞추기", + "a368bf0b43feb260": "원래 색상", + "4d2fa01e838b9549": "반전된 색상", + "1c19f2863386a317": "PDF 색상" } diff --git a/apps/mobile/src/i18n/translations/pt-BR.json b/apps/mobile/src/i18n/translations/pt-BR.json index 2c4ee1bc64fc4..9d09705700f8b 100644 --- a/apps/mobile/src/i18n/translations/pt-BR.json +++ b/apps/mobile/src/i18n/translations/pt-BR.json @@ -5458,5 +5458,11 @@ "ad208e3e32c85029": "Ocultar todas", "3328503592789bed": "Zen", "856812e7e1fc445e": "Chamadas de ferramentas no chat", - "8d545d54c0a9e950": "Oculta os comandos, edições e pesquisas que os agentes executam. \"Ocultar bem-sucedidas\" mantém as falhas. Zen mostra só as respostas finais. Aprovações, perguntas e erros sempre aparecem." + "8d545d54c0a9e950": "Oculta os comandos, edições e pesquisas que os agentes executam. \"Ocultar bem-sucedidas\" mantém as falhas. Zen mostra só as respostas finais. Aprovações, perguntas e erros sempre aparecem.", + "6dc1e8c15f62989d": "Restaurar cores originais", + "0d576a2c32b02d5d": "Inverter cores", + "66104e819c8d2122": "Seguir o tema", + "a368bf0b43feb260": "Cores originais", + "4d2fa01e838b9549": "Cores invertidas", + "1c19f2863386a317": "Cores do PDF" } diff --git a/apps/mobile/src/i18n/translations/ru.json b/apps/mobile/src/i18n/translations/ru.json index c4f78e560083b..98bdaa74a188e 100644 --- a/apps/mobile/src/i18n/translations/ru.json +++ b/apps/mobile/src/i18n/translations/ru.json @@ -5538,5 +5538,11 @@ "ad208e3e32c85029": "Скрывать все", "3328503592789bed": "Дзен", "856812e7e1fc445e": "Вызовы инструментов в чате", - "8d545d54c0a9e950": "Скрывать команды, правки и поиски, которые выполняют агенты. «Скрывать успешные» оставляет ошибки. «Дзен» показывает только итоговые ответы. Запросы подтверждения, вопросы и ошибки показываются всегда." + "8d545d54c0a9e950": "Скрывать команды, правки и поиски, которые выполняют агенты. «Скрывать успешные» оставляет ошибки. «Дзен» показывает только итоговые ответы. Запросы подтверждения, вопросы и ошибки показываются всегда.", + "6dc1e8c15f62989d": "Восстановить исходные цвета", + "0d576a2c32b02d5d": "Инвертировать цвета", + "66104e819c8d2122": "Как в теме", + "a368bf0b43feb260": "Исходные цвета", + "4d2fa01e838b9549": "Инвертированные цвета", + "1c19f2863386a317": "Цвета PDF" } diff --git a/apps/mobile/src/i18n/translations/sv.json b/apps/mobile/src/i18n/translations/sv.json index fa3a3dd6d039f..78d8347e402dd 100644 --- a/apps/mobile/src/i18n/translations/sv.json +++ b/apps/mobile/src/i18n/translations/sv.json @@ -5464,5 +5464,11 @@ "ad208e3e32c85029": "Dölj alla", "3328503592789bed": "Zen", "856812e7e1fc445e": "Verktygsanrop i chatten", - "8d545d54c0a9e950": "Dölj kommandon, redigeringar och sökningar som agenter kör. Dölj lyckade behåller misslyckanden. Zen visar bara slutliga svar. Godkännanden, frågor och fel visas alltid." + "8d545d54c0a9e950": "Dölj kommandon, redigeringar och sökningar som agenter kör. Dölj lyckade behåller misslyckanden. Zen visar bara slutliga svar. Godkännanden, frågor och fel visas alltid.", + "6dc1e8c15f62989d": "Återställ originalfärger", + "0d576a2c32b02d5d": "Invertera färger", + "66104e819c8d2122": "Följ temat", + "a368bf0b43feb260": "Originalfärger", + "4d2fa01e838b9549": "Inverterade färger", + "1c19f2863386a317": "PDF-färger" } diff --git a/apps/mobile/src/i18n/translations/zh.json b/apps/mobile/src/i18n/translations/zh.json index f36e76805c298..c0b56dbdc3341 100644 --- a/apps/mobile/src/i18n/translations/zh.json +++ b/apps/mobile/src/i18n/translations/zh.json @@ -5449,5 +5449,11 @@ "ad208e3e32c85029": "全部隐藏", "3328503592789bed": "专注模式", "856812e7e1fc445e": "聊天中的工具调用", - "8d545d54c0a9e950": "隐藏智能体执行的命令、编辑和搜索。“隐藏成功的调用”仍保留失败项;“专注模式”仅显示最终回答。审批、提问和错误始终显示。" + "8d545d54c0a9e950": "隐藏智能体执行的命令、编辑和搜索。“隐藏成功的调用”仍保留失败项;“专注模式”仅显示最终回答。审批、提问和错误始终显示。", + "6dc1e8c15f62989d": "恢复原始颜色", + "0d576a2c32b02d5d": "反转颜色", + "66104e819c8d2122": "跟随主题", + "a368bf0b43feb260": "原始颜色", + "4d2fa01e838b9549": "反转颜色", + "1c19f2863386a317": "PDF 颜色" } diff --git a/apps/mobile/src/persistence/mobile-preferences.ts b/apps/mobile/src/persistence/mobile-preferences.ts index 71d095b0b4fb5..14745a1601d85 100644 --- a/apps/mobile/src/persistence/mobile-preferences.ts +++ b/apps/mobile/src/persistence/mobile-preferences.ts @@ -20,6 +20,7 @@ import { } from "@t3tools/contracts"; import { ToolCallVisibility } from "@t3tools/contracts/settings"; import type { AndroidNavigationStyle } from "../lib/androidNavigationStyle"; +import type { PdfAppearance } from "@t3tools/contracts/settings"; import type { ComposerEnterBehavior } from "../lib/composerEnterBehavior"; import type { FollowUpBehavior } from "../lib/followUpBehavior"; import { isMicrophoneKind, type MicrophoneEntry } from "../lib/microphonePriority"; @@ -147,6 +148,7 @@ export interface Preferences { readonly lightThemeId?: MobileThemeId; readonly darkThemeId?: MobileThemeId; readonly themeMode?: MobileThemeMode; + readonly pdfAppearance?: PdfAppearance; readonly androidNavigationStyle?: AndroidNavigationStyle; readonly baseFontSize?: number; readonly terminalFontSize?: number | null; @@ -240,6 +242,7 @@ function sanitizePreferences(parsed: Preferences): Preferences { lightThemeId?: MobileThemeId; darkThemeId?: MobileThemeId; themeMode?: MobileThemeMode; + pdfAppearance?: PdfAppearance; androidNavigationStyle?: AndroidNavigationStyle; baseFontSize?: number; terminalFontSize?: number | null; @@ -342,6 +345,12 @@ function sanitizePreferences(parsed: Preferences): Preferences { preferences.codeFontSize = parsed.codeFontSize; } if (typeof parsed.codeWordBreak === "boolean") preferences.codeWordBreak = parsed.codeWordBreak; + if ( + parsed.pdfAppearance === "match-app" || + parsed.pdfAppearance === "original" || + parsed.pdfAppearance === "dark" + ) + preferences.pdfAppearance = parsed.pdfAppearance; if (typeof parsed.mathRenderingEnabled === "boolean") preferences.mathRenderingEnabled = parsed.mathRenderingEnabled; if (typeof parsed.crashReportsEnabled === "boolean") { diff --git a/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx b/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx index add8d7368e2ab..6b94ae4a5669f 100644 --- a/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx +++ b/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx @@ -1651,6 +1651,14 @@ it("keeps a workspace PDF open across URL renewals and reloads it when the file await using screen = await render(preview("first")); const opened = screen.container.querySelector("iframe"); expect(opened?.src.startsWith(original)).toBe(true); + const colors = screen.getByRole("button", { name: "Inverted colors" }); + const initiallyDark = colors.element().getAttribute("aria-pressed") === "true"; + await colors.click(); + await expect.element(colors).toHaveAttribute("aria-pressed", String(!initiallyDark)); + expect(screen.container.querySelector("iframe")).toBe(opened); + expect(getComputedStyle(opened!).filter).toBe( + initiallyDark ? "none" : "invert(1) hue-rotate(180deg)", + ); // An agent command renews the signed URL but leaves the file alone. assetUrlState.mockReturnValue({ @@ -1662,6 +1670,7 @@ it("keeps a workspace PDF open across URL renewals and reloads it when the file await screen.rerender(preview("second")); expect(assetUrlState).toHaveBeenLastCalledWith(expect.anything(), expect.anything(), "second"); expect(screen.container.querySelector("iframe")).toBe(opened); + await expect.element(colors).toHaveAttribute("aria-pressed", String(!initiallyDark)); assetUrlState.mockReturnValue({ _tag: "Success", @@ -1673,6 +1682,7 @@ it("keeps a workspace PDF open across URL renewals and reloads it when the file const reloaded = screen.container.querySelector("iframe"); expect(reloaded).not.toBe(opened); expect(reloaded?.src.startsWith(edited)).toBe(true); + await expect.element(colors).toHaveAttribute("aria-pressed", String(!initiallyDark)); // Servers without revisions hold the preview back until a fresh grant arrives. assetUrlState.mockReturnValue({ @@ -1686,6 +1696,7 @@ it("keeps a workspace PDF open across URL renewals and reloads it when the file assetUrlState.mockReturnValue({ _tag: "Success", url: original, expiresAt: 0 }); await screen.rerender(preview("fourth")); expect(screen.container.querySelector("iframe")?.src.startsWith(original)).toBe(true); + await expect.element(colors).toHaveAttribute("aria-pressed", String(!initiallyDark)); } finally { URL.revokeObjectURL(original); URL.revokeObjectURL(edited); diff --git a/apps/web/src/components/files/BrowserDocumentFrame.tsx b/apps/web/src/components/files/BrowserDocumentFrame.tsx index 3270556fb0ff4..27ad8ae28b887 100644 --- a/apps/web/src/components/files/BrowserDocumentFrame.tsx +++ b/apps/web/src/components/files/BrowserDocumentFrame.tsx @@ -1,3 +1,4 @@ +import { useGT } from "gt-react"; import { useAtomValue } from "@effect/atom-react"; import { type KeybindingCommand, @@ -38,8 +39,12 @@ import { useState, } from "react"; import { isElectron } from "~/env"; -import { FileSurfaceLoading } from "./fileSurfaceChrome"; +import { MoonIcon, SunIcon } from "lucide-react"; +import { FileSurfaceAction, FileSurfaceLoading } from "./fileSurfaceChrome"; import type { PdfViewState } from "./PdfViewer"; +import { useClientSettings } from "~/hooks/useSettings"; +import { useRenderedAppearance } from "~/hooks/useTheme"; +import "./pdfAppearance.css"; import { useOpenLink } from "~/browser/useOpenLink"; import { ExpandedImageDialog } from "~/components/chat/ExpandedImageDialog"; @@ -87,19 +92,43 @@ function PdfDocument(props: { documentKey: string; threadRef: ScopedThreadRef | undefined; actions?: ReactNode; + pending?: boolean; }) { + const gt = useGT(); const [view, setView] = useState({ page: 0, offset: 0, zoom: null, left: 0 }); + const appearance = useClientSettings((settings) => settings.pdfAppearance); + const themeAppearance = useRenderedAppearance(); + const [override, setOverride] = useState(null); + const dark = + override ?? + (appearance === "dark" || (appearance === "match-app" && themeAppearance === "dark")); + if (props.pending) return ; return ( - +
+ setOverride(!dark)} + > + {dark ? : } + + } + /> +
); } @@ -112,6 +141,7 @@ function PdfDocumentRevision(props: { onViewChange: (view: PdfViewState) => void; threadRef: ScopedThreadRef | undefined; actions?: ReactNode; + appearanceAction: ReactNode; }) { const [src] = useState(props.src); const openLink = useOpenLink(props.threadRef); @@ -123,12 +153,18 @@ function PdfDocumentRevision(props: { !/iPad|iPhone|iPod/.test(navigator.userAgent) && !(navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1); return native ? ( - // oxlint-disable-next-line react/iframe-missing-sandbox -- Chromium's PDF plugin requires an unsandboxed frame; src is an exact-file asset grant. -