Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ jobs:
needs: changes
if: ${{ !cancelled() && needs.changes.outputs.test_web != 'false' }}
runs-on: ubuntu-24.04
timeout-minutes: 15
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type { MobileThemeVariables } from "../../../lib/mobileTheme";
import {
createMobileThemePairPatch,
createMobileThemeSelectionPatch,
normalizeMobileThemeMode,
resolveMobileThemeMode,
resolveMobileThemeIds,
type MobileThemeAppearance,
type MobileThemeId,
Expand Down Expand Up @@ -120,15 +120,15 @@ function resolveThemeVariablesByAppearance(

/** The appearance whose theme is on screen, read from the native scheme. */
export function resolveThemeAppearance(stored: Preferences | null): MobileThemeAppearance {
const themeMode = normalizeMobileThemeMode(stored?.themeMode);
const themeMode = resolveMobileThemeMode(stored ?? {});
if (themeMode !== "system") return themeMode;
return Appearance.getColorScheme() === "dark" ? "dark" : "light";
}

function runtimeStateFor(stored: Preferences | null): MobileThemeRuntimeState {
return {
baseFontSize: resolveAppearancePreferences(stored).baseFontSize,
themeMode: normalizeMobileThemeMode(stored?.themeMode),
themeMode: resolveMobileThemeMode(stored ?? {}),
themeAppearance: resolveThemeAppearance(stored),
};
}
Expand Down Expand Up @@ -201,7 +201,7 @@ export function AppearancePreferencesProvider(props: { readonly children: ReactN
manufacturer,
process.env.EXPO_PUBLIC_T3_FLOATING_TABS === "1",
);
const themeMode = normalizeMobileThemeMode(storedPreferences?.themeMode);
const themeMode = resolveMobileThemeMode(storedPreferences ?? {});
const themeAppearance = themeMode === "system" ? systemColorScheme : themeMode;
const resolvedThemeIds = resolveMobileThemeIds(storedPreferences ?? {});
const themeIds = useMemo<MobileThemeIds>(
Expand Down
14 changes: 13 additions & 1 deletion apps/mobile/src/lib/mobileTheme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
flattenThemeColor,
getMobileThemeVariables,
resolveMobileThemeIds,
resolveMobileThemeMode,
themeColorWithAlpha,
themeColorToNativeColor,
} from "./mobileTheme";
Expand Down Expand Up @@ -225,6 +226,17 @@ describe("mobile themes", () => {
});

it("migrates one theme choice to both appearances and preserves independent choices", () => {
expect(resolveMobileThemeIds({})).toEqual({ light: "ocean", dark: "ocean" });
expect(resolveMobileThemeMode({})).toBe("dark");
expect(resolveMobileThemeMode({ themeId: "grove" })).toBe("system");
for (const themeMode of ["light", "dark", "system"] as const) {
expect(resolveMobileThemeMode({ themeMode })).toBe(themeMode);
expect(resolveMobileThemeMode({ themeId: "t3-code", themeMode })).toBe(themeMode);
}
expect(resolveMobileThemeIds({ themeId: "t3-code" })).toEqual({
light: "t3-code",
dark: "t3-code",
});
expect(resolveMobileThemeIds({ themeId: "grove" })).toEqual({
light: "grove",
dark: "grove",
Expand All @@ -233,7 +245,7 @@ describe("mobile themes", () => {
resolveMobileThemeIds({ themeId: "grove", lightThemeId: "iris", darkThemeId: "ocean" }),
).toEqual({ light: "iris", dark: "ocean" });
expect(resolveMobileThemeIds({ themeId: "grove", lightThemeId: "missing" })).toEqual({
light: DEFAULT_MOBILE_THEME_ID,
light: "ocean",
dark: "grove",
});
});
Expand Down
18 changes: 15 additions & 3 deletions apps/mobile/src/lib/mobileTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,23 @@ export type MobileThemeVariables = Readonly<Record<MobileThemeVariable, string>>
function normalizeMobileThemeId(value: unknown): MobileThemeId {
return typeof value === "string" && (MOBILE_THEME_IDS as readonly string[]).includes(value)
? (value as MobileThemeId)
: DEFAULT_MOBILE_THEME_ID;
: "ocean";
}

export function normalizeMobileThemeMode(value: unknown): MobileThemeMode {
return value === "light" || value === "dark" || value === "system" ? value : "system";
export function resolveMobileThemeMode(preferences: {
readonly themeMode?: unknown;
readonly themeId?: unknown;
readonly lightThemeId?: unknown;
readonly darkThemeId?: unknown;
}): MobileThemeMode {
const value = preferences.themeMode;
if (value === "light" || value === "dark" || value === "system") return value;
const hasThemeChoice = [
preferences.themeId,
preferences.lightThemeId,
preferences.darkThemeId,
].some((id) => typeof id === "string" && (MOBILE_THEME_IDS as readonly string[]).includes(id));
return hasThemeChoice ? "system" : "dark";
}

export function resolveMobileThemeIds(preferences: {
Expand Down
62 changes: 29 additions & 33 deletions apps/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
};

try {
const storedTheme = window.localStorage.getItem("t3code:theme");
let storedTheme = window.localStorage.getItem("t3code:theme");
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
const LEGACY_THEME_IDS = {
"t3-chat-dark": "t3-chat",
Expand All @@ -228,9 +228,16 @@
"t3-ember": "ember",
"t3-iris": "iris",
};
if (
storedTheme !== null &&
!RESERVED_THEME_IDS.includes(storedTheme) &&
!findCustomTheme(storedTheme)
) {
storedTheme = null;
}
const isLegacyT3ChatDark = storedTheme === "t3-chat-dark";
const themeId =
storedTheme === null ? "" : (LEGACY_THEME_IDS[storedTheme] ?? storedTheme);
storedTheme === null ? "ocean" : (LEGACY_THEME_IDS[storedTheme] ?? storedTheme);
const legacyMode = isLegacyT3ChatDark ? "dark" : null;
const builtInModes = BUILT_IN_THEME_MODES[themeId] ?? null;
const customTheme = builtInModes ? null : findCustomTheme(themeId);
Expand All @@ -241,14 +248,13 @@
(mode) => mode === customTheme.appearance || customTheme.variants?.[mode],
)
: null);
const isKnownTheme =
storedTheme === "light" ||
storedTheme === "dark" ||
storedTheme === "system" ||
themeModes !== null;
const theme = isKnownTheme && storedTheme ? storedTheme : "system";
const isThemed = isKnownTheme && themeModes !== null;
const baseAppearance = customTheme ? customTheme.appearance : "light";
const theme = storedTheme ?? "ocean";
const isThemed = themeModes !== null;
const baseAppearance = customTheme
? customTheme.appearance
: storedTheme === null
? "dark"
: "light";
const systemMode = prefersDark ? "dark" : "light";
const storedAppearanceMode = window.localStorage.getItem(
THEME_APPEARANCE_MODE_STORAGE_KEY,
Expand Down Expand Up @@ -352,14 +358,7 @@
} else {
delete document.documentElement.dataset.themeId;
}
// A resolved half is a selection even when the base theme is gone
// (deleting the base leaves the mix pointing at a real theme).
const hasSelection = halfThemeId !== null || (isKnownTheme && storedTheme !== null);
if (hasSelection) {
document.documentElement.dataset.themeSelected = "true";
} else {
delete document.documentElement.dataset.themeSelected;
}
document.documentElement.dataset.themeSelected = "true";
document.documentElement.classList.toggle("dark", isDark);
const chromeColor = customColors
? isThemeColor(customColors.chrome)
Expand All @@ -371,24 +370,21 @@
? DARK_BACKGROUND
: LIGHT_BACKGROUND;
document.documentElement.style.backgroundColor = chromeColor;
if (hasSelection) {
const splashColors = customSplash ?? builtInSplash ?? fallbackSplash;
for (const [name, value] of Object.entries(splashColors)) {
document.documentElement.style.setProperty(`--boot-${name}`, value);
}
const splashColors = customSplash ?? builtInSplash ?? fallbackSplash;
for (const [name, value] of Object.entries(splashColors)) {
document.documentElement.style.setProperty(`--boot-${name}`, value);
}
setThemeColor(chromeColor);
} catch {
let prefersDark = true;
try {
prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
} catch {}
delete document.documentElement.dataset.themeId;
delete document.documentElement.dataset.themeSelected;
document.documentElement.classList.toggle("dark", prefersDark);
const fallbackColor = prefersDark ? DARK_BACKGROUND : LIGHT_BACKGROUND;
document.documentElement.style.backgroundColor = fallbackColor;
setThemeColor(fallbackColor);
const splash = BUILT_IN_THEME_PALETTES.ocean.dark;
document.documentElement.dataset.themeId = "ocean";
document.documentElement.dataset.themeSelected = "true";
document.documentElement.classList.add("dark");
document.documentElement.style.backgroundColor = splash.chrome;
for (const [name, value] of Object.entries(splash)) {
document.documentElement.style.setProperty(`--boot-${name}`, value);
}
setThemeColor(splash.chrome);
}
})();
</script>
Expand Down
13 changes: 2 additions & 11 deletions apps/web/src/components/AppSidebarLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore";
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
import { cn, isMacPlatform } from "../lib/utils";
import { primaryServerKeybindingsAtom } from "../state/server";
import { useEnvironmentIdentificationMode } from "../hooks/useSettings";
import {
PanelAnimationSuppressionProvider,
usePanelAnimationSettings,
Expand All @@ -43,7 +42,6 @@ import ThreadSidebar from "./Sidebar";
import { SidebarBrandWidthProbe } from "./sidebar/SidebarChrome";
import { isAppModalPage } from "./sidebar/mainAppLocation";
import type { SidebarRouteReveal } from "./sidebar/routeReveal";
import { useSidebarStageBackdropVariant } from "./SidebarStageBackdrop";
import {
clampThreadSidebarWidth,
resolveInitialThreadSidebarWidth,
Expand All @@ -59,7 +57,6 @@ import {
SidebarTrigger,
useMobileSidebarSheetMounted,
useSidebar,
useSidebarVisibility,
} from "./ui/sidebar";
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
import { appAtomRegistry } from "../rpc/atomRegistry";
Expand Down Expand Up @@ -319,9 +316,6 @@ function SidebarControl({ showSidebar }: { readonly showSidebar: boolean }) {
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
const { toggleSidebar } = useSidebar();
const mobileSidebarSheetMounted = useMobileSidebarSheetMounted();
const isSidebarVisible = useSidebarVisibility();
const environmentIdentificationMode = useEnvironmentIdentificationMode();
const stageBackdropVariant = useSidebarStageBackdropVariant(environmentIdentificationMode);
const shortcutLabel = shortcutLabelForCommand(keybindings, "sidebar.toggle", {
context: { usagePageOpen },
});
Expand Down Expand Up @@ -393,11 +387,8 @@ function SidebarControl({ showSidebar }: { readonly showSidebar: boolean }) {
<TooltipTrigger
render={
<SidebarTrigger
variant={isSidebarVisible && stageBackdropVariant ? "media-navigation" : "ghost"}
className={cn(
"pointer-events-auto",
isSidebarVisible && stageBackdropVariant && "relative top-auto translate-y-0",
)}
variant="ghost"
className="pointer-events-auto"
aria-label="Toggle main sidebar"
/>
}
Expand Down
27 changes: 5 additions & 22 deletions apps/web/src/components/SidebarStageBackdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { primaryServerConfigAtom } from "../state/server";
export type SidebarStageBackdropVariant = "nightly" | "dev";
export type EnvironmentIdentificationPillLabel = "Dev" | "Nightly";

const STAGE_BACKDROP_VIEW_BOX = "0 0 8192 96";

export function resolveSidebarStageBackdropVariant(
stageLabel: string,
mode: EnvironmentIdentificationMode = "artwork",
Expand Down Expand Up @@ -49,23 +47,8 @@ export function useSidebarStageBackdropVariant(
return resolveSidebarStageBackdropVariant(useEnvironmentStageLabel(), mode);
}

export function SidebarStageBackdrop({ variant }: { variant: SidebarStageBackdropVariant }) {
return (
<div
aria-hidden
className="sidebar-stage-backdrop pointer-events-none absolute inset-x-0 top-0 z-0 h-20 select-none overflow-hidden"
>
<StageBackdropArt variant={variant} />
</div>
);
}

function StageBackdropArt({ variant }: { variant: SidebarStageBackdropVariant }) {
return variant === "nightly" ? <NightlySkyArt /> : <DevBlueprintArt />;
}

export function StageBackdropButtonArt({ variant }: { variant: SidebarStageBackdropVariant }) {
return variant === "nightly" ? <NightlySkyArt compact /> : <DevBlueprintArt compact />;
return variant === "nightly" ? <NightlySkyArt /> : <DevBlueprintArt />;
}

const NIGHTLY_STARS: ReadonlyArray<{
Expand Down Expand Up @@ -99,7 +82,7 @@ const NIGHTLY_SPARKLES: ReadonlyArray<{ x: number; y: number }> = [
{ x: 246, y: 26 },
];

function NightlySkyArt({ compact = false }: { compact?: boolean }) {
function NightlySkyArt() {
const idPrefix = useId().replaceAll(":", "");
const skyId = `${idPrefix}-stage-night-sky`;
const glowId = `${idPrefix}-stage-night-glow`;
Expand All @@ -114,7 +97,7 @@ function NightlySkyArt({ compact = false }: { compact?: boolean }) {
className="h-full w-full"
fill="none"
preserveAspectRatio="xMinYMin slice"
viewBox={compact ? "96 0 8192 96" : STAGE_BACKDROP_VIEW_BOX}
viewBox="96 0 8192 96"
xmlns="http://www.w3.org/2000/svg"
>
<defs>
Expand Down Expand Up @@ -211,7 +194,7 @@ function NightlySkyArt({ compact = false }: { compact?: boolean }) {
);
}

function DevBlueprintArt({ compact = false }: { compact?: boolean }) {
function DevBlueprintArt() {
const idPrefix = useId().replaceAll(":", "");
const paperId = `${idPrefix}-stage-bp-paper`;
const glowId = `${idPrefix}-stage-bp-glow`;
Expand All @@ -229,7 +212,7 @@ function DevBlueprintArt({ compact = false }: { compact?: boolean }) {
className="h-full w-full"
fill="none"
preserveAspectRatio="xMinYMin slice"
viewBox={compact ? "64 0 8192 96" : STAGE_BACKDROP_VIEW_BOX}
viewBox="64 0 8192 96"
xmlns="http://www.w3.org/2000/svg"
>
<defs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function AppearanceSettingsPanel() {
: "Only built-in themes show artwork."
: environmentStageVariant
? "Choose how Dev and Nightly environments are identified."
: "Show Dev or Nightly artwork in the sidebar header.";
: "Show Dev or Nightly artwork on the send button.";
const glassOpacityRatio =
(settings.glassOpacity - MIN_GLASS_OPACITY) / (MAX_GLASS_OPACITY - MIN_GLASS_OPACITY);
const glassOpacitySliderStyle = {
Expand Down
Loading
Loading